iter_file_details_ext update impl
This commit is contained in:
parent
abce0c6629
commit
98f011673e
3 changed files with 26 additions and 9 deletions
|
|
@ -1144,10 +1144,10 @@ impl Session {
|
|||
.iter_file_details_ext(&lengths)?
|
||||
.map(|fd| {
|
||||
Ok::<_, anyhow::Error>(FileInfo {
|
||||
relative_filename: fd.filename.to_pathbuf()?,
|
||||
offset_in_torrent: fd.offset,
|
||||
relative_filename: fd.details.filename.to_pathbuf()?,
|
||||
offset_in_torrent: fd.details.offset,
|
||||
piece_range: fd.pieces,
|
||||
len: fd.len,
|
||||
len: fd.details.len,
|
||||
})
|
||||
})
|
||||
.collect::<anyhow::Result<Vec<FileInfo>>>()?;
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ impl TorrentStorage for FilesystemStorage {
|
|||
for file_details in meta.info.iter_file_details_ext(&meta.lengths)? {
|
||||
let mut full_path = self.output_folder.clone();
|
||||
let relative_path = file_details
|
||||
.details
|
||||
.filename
|
||||
.to_pathbuf()
|
||||
.context("error converting file to path")?;
|
||||
|
|
|
|||
|
|
@ -182,12 +182,23 @@ where
|
|||
|
||||
pub struct FileDetails<'a, BufType> {
|
||||
pub filename: FileIteratorName<'a, BufType>,
|
||||
// absolute offset in torrent if it was a flat blob of bytes
|
||||
pub offset: u64,
|
||||
pub len: u64,
|
||||
|
||||
// bep-47
|
||||
pub attr: Option<BufType>,
|
||||
pub sha1: Option<BufType>,
|
||||
pub symlink_path: Option<Vec<BufType>>,
|
||||
}
|
||||
|
||||
pub struct FileDetailsExt<'a, BufType> {
|
||||
pub details: FileDetails<'a, BufType>,
|
||||
// the pieces that contain this file
|
||||
pub pieces: std::ops::Range<u32>,
|
||||
}
|
||||
|
||||
impl<'a, BufType> FileDetails<'a, BufType> {
|
||||
impl<'a, BufType> FileDetailsExt<'a, BufType> {
|
||||
pub fn pieces_usize(&self) -> std::ops::Range<usize> {
|
||||
self.pieces.start as usize..self.pieces.end as usize
|
||||
}
|
||||
|
|
@ -243,17 +254,22 @@ impl<BufType: AsRef<[u8]>> TorrentMetaV1Info<BufType> {
|
|||
pub fn iter_file_details_ext<'a>(
|
||||
&'a self,
|
||||
lengths: &'a Lengths,
|
||||
) -> anyhow::Result<impl Iterator<Item = FileDetails<'a, BufType>> + 'a> {
|
||||
) -> anyhow::Result<impl Iterator<Item = FileDetailsExt<'a, BufType>> + 'a> {
|
||||
Ok(self
|
||||
.iter_filenames_and_lengths()?
|
||||
.scan(0u64, |acc_offset, (filename, len)| {
|
||||
let offset = *acc_offset;
|
||||
*acc_offset += len;
|
||||
Some(FileDetails {
|
||||
filename,
|
||||
Some(FileDetailsExt {
|
||||
details: FileDetails {
|
||||
filename,
|
||||
offset,
|
||||
len,
|
||||
attr: None,
|
||||
sha1: None,
|
||||
symlink_path: None,
|
||||
},
|
||||
pieces: lengths.iter_pieces_within_offset(offset, len),
|
||||
offset,
|
||||
len,
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue