Skip to content

Instantly share code, notes, and snippets.

@mysteriouspants
Created March 14, 2020 05:23
Show Gist options
  • Save mysteriouspants/ba83b992134ff34bc09fdc397b08bb2e to your computer and use it in GitHub Desktop.
Save mysteriouspants/ba83b992134ff34bc09fdc397b08bb2e to your computer and use it in GitHub Desktop.
pub trait Source : Read + Seek + Send { }
impl<TSource: Source> NoMemEntryStore<TSource> {
/// Reads an archive from an input source. Optionally scans each entry
/// header, which would detect errors in the archive earlier.
pub fn from_source(
source: &mut TSource, verify: bool
) -> Result<NoMemEntryStore<TSource>, ArchiveParseError> {
let archive = Archive::load_from(source)?;
if verify {
// loop through all the entries and validate they they can be parsed
source.seek(SeekFrom::Start(archive.archive_start as u64))?;
for _i in 1 ..= archive.archive_size {
Entry::load_from(
&mut source, &opts_for_archive(
&archive.archive_version, &archive.archive_type
)
)?;
}
}
return Ok(NoMemEntryStore::<TSource> { archive, source, });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment