-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Select piece length when none is provided
When no piece length is provided to imdl torrent create, a piece length is selected based on the size of the input. The hueristic is lifted directly from libtorrent. Also adds a imdl torrent piece-length command, which prints a table of the piece lengths chosen at different content sizes, which is useful for understanding and debugging the piece length selection algorithm. type: added
- Loading branch information
Showing
15 changed files
with
325 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::common::*; | ||
|
||
pub(crate) struct Files { | ||
total_size: Bytes, | ||
} | ||
|
||
impl Files { | ||
pub(crate) fn from_root(root: &Path) -> Result<Files, Error> { | ||
let mut total_size = 0; | ||
|
||
for result in WalkDir::new(root).sort_by(|a, b| a.file_name().cmp(b.file_name())) { | ||
let entry = result?; | ||
|
||
let metadata = entry.metadata()?; | ||
|
||
if metadata.is_file() { | ||
total_size += metadata.len(); | ||
} | ||
} | ||
|
||
Ok(Files { | ||
total_size: Bytes::from(total_size), | ||
}) | ||
} | ||
|
||
pub(crate) fn total_size(&self) -> Bytes { | ||
self.total_size | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::common::*; | ||
|
||
pub(crate) struct Linter { | ||
allowed: BTreeSet<Lint>, | ||
} | ||
|
||
impl Linter { | ||
pub(crate) fn new() -> Linter { | ||
Linter { | ||
allowed: BTreeSet::new(), | ||
} | ||
} | ||
|
||
pub(crate) fn allow(&mut self, allowed: impl IntoIterator<Item = Lint>) { | ||
self.allowed.extend(allowed) | ||
} | ||
|
||
pub(crate) fn is_allowed(&self, lint: Lint) -> bool { | ||
self.allowed.contains(&lint) | ||
} | ||
|
||
pub(crate) fn is_denied(&self, lint: Lint) -> bool { | ||
!self.is_allowed(lint) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.