More granular feature handling
This commit is contained in:
parent
9a6039f5ee
commit
7e40c71852
5 changed files with 7 additions and 16 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -2398,7 +2398,6 @@ name = "librqbit-core"
|
|||
version = "4.0.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cfg",
|
||||
"bytes",
|
||||
"data-encoding",
|
||||
"directories",
|
||||
|
|
|
|||
|
|
@ -19,5 +19,5 @@ serde = { version = "1", features = ["derive"] }
|
|||
buffers = { path = "../buffers", package = "librqbit-buffers", version = "4" }
|
||||
clone_to_owned = { path = "../clone_to_owned", package = "librqbit-clone-to-owned", version = "3" }
|
||||
anyhow = "1"
|
||||
sha1w = { path = "../sha1w", default-features = false, package = "librqbit-sha1-wrapper", version = "4" }
|
||||
sha1w = { path = "../sha1w", default-features = false, optional = true, package = "librqbit-sha1-wrapper", version = "4" }
|
||||
bytes = "1.7.1"
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@ directories = "5"
|
|||
tokio-util = "0.7.10"
|
||||
data-encoding = "2.6.0"
|
||||
bytes = "1.7.1"
|
||||
assert_cfg = "0.1.0"
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
serde_json = "1"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use anyhow::Context;
|
||||
|
||||
use crate::{constants::CHUNK_SIZE, torrent_metainfo::TorrentMetaV1Info};
|
||||
use crate::constants::CHUNK_SIZE;
|
||||
|
||||
pub fn last_element_size<T>(total_length: T, piece_length: T) -> T
|
||||
where
|
||||
|
|
@ -73,8 +73,9 @@ impl ValidPieceIndex {
|
|||
}
|
||||
|
||||
impl Lengths {
|
||||
#[cfg(any(feature = "sha1-crypto-hash", feature = "sha1-ring"))]
|
||||
pub fn from_torrent<ByteBuf: AsRef<[u8]>>(
|
||||
torrent: &TorrentMetaV1Info<ByteBuf>,
|
||||
torrent: &crate::torrent_metainfo::TorrentMetaV1Info<ByteBuf>,
|
||||
) -> anyhow::Result<Lengths> {
|
||||
let total_length = torrent.iter_file_lengths()?.sum();
|
||||
Lengths::new(total_length, torrent.piece_length)
|
||||
|
|
@ -157,11 +158,7 @@ impl Lengths {
|
|||
}
|
||||
|
||||
// A helper to iterate over pieces in a file.
|
||||
pub(crate) fn iter_pieces_within_offset(
|
||||
&self,
|
||||
offset_bytes: u64,
|
||||
len: u64,
|
||||
) -> std::ops::Range<u32> {
|
||||
pub fn iter_pieces_within_offset(&self, offset_bytes: u64, len: u64) -> std::ops::Range<u32> {
|
||||
// Validation and correction
|
||||
let offset_bytes = offset_bytes.min(self.total_length);
|
||||
let end_bytes = (offset_bytes + len).min(self.total_length);
|
||||
|
|
|
|||
|
|
@ -1,16 +1,13 @@
|
|||
pub mod constants;
|
||||
pub mod directories;
|
||||
pub mod hash_id;
|
||||
|
||||
pub mod lengths;
|
||||
pub mod magnet;
|
||||
pub mod peer_id;
|
||||
pub mod spawn_utils;
|
||||
pub mod speed_estimator;
|
||||
#[cfg(any(feature = "sha1-crypto-hash", feature = "sha1-ring"))]
|
||||
pub mod torrent_metainfo;
|
||||
|
||||
pub use hash_id::Id20;
|
||||
|
||||
assert_cfg::exactly_one! {
|
||||
feature = "sha1-crypto-hash",
|
||||
feature = "sha1-ring",
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue