Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API for reading raw file content #205

Closed
nicklaswj opened this issue Oct 27, 2020 · 3 comments · Fixed by #209
Closed

API for reading raw file content #205

nicklaswj opened this issue Oct 27, 2020 · 3 comments · Fixed by #209

Comments

@nicklaswj
Copy link

Hi all.
I'm using zip-rs to only read zip archives (i.e. not decompress the content), and thus have default-features = false.
However the two variants of the enum CompressionMethod, Deflated and Bzip2 only exist if respectively the two features "flate" and "bzip2" are turned on. Currently this is not a big problem if you want to know the compression method, since you can just match on the Unsupported(v) variant and check the value v, however I can see that you are deprecating this variant.

So what am I suppose to do if I want to know the compression method but not turn on the decompression/compression features? Second is there a good reason for the variants Deflated and Bzip2 to be behind a feature flag?

Otherwise thanks for a really useful and easy to use crate :)

Nicklas

@nicklaswj nicklaswj changed the title CompressionMethod deprecation of Unsupported (Question) CompressionMethod deprecation of Unsupported Oct 27, 2020
@Plecra
Copy link
Member

Plecra commented Nov 10, 2020

Ah, another consequence of my clumsy use of deprecated. The intention is that CompressionMethod will contain every valid variant, at which point Deflated and Bzip2 will be usable without the feature like you mentioned.

There are a few issues like this (#198) that shouldn't take much work to resolve, so I'm making 0.5.9 a priority.

@Plecra
Copy link
Member

Plecra commented Nov 15, 2020

I'm looping #209 (comment) back into this issue, since the changes seem closely linked.

Would you be able to explain what you are reading the raw content of the files for? It'd be good to know what the API needs to give access to.

impl<R: Read + io::Seek> ZipArchive<R> {
    // Attempt to read the content of the file without decompressing it
    pub fn by_index_raw<'a>(&'a mut self, file_number: usize) -> ZipResult<ZipFile<'a>>;
}

And if you don't mind, it'd be great to know if this API works well for you:

// This `File` type is from the next version of the crate
impl<R: io::Read> File<R> {
    fn raw_reader(&mut self) -> &mut R;
}
// Copy any bzip2-compressed files out of the archive
Archive::open(File::open("compressed.zip")?)?
    .iter()
    .filter(|file| file.compression_method() == CompressionMethod::BZip2)
    .map(|file| std::io::copy(file.raw_reader(), &mut File::create(file.name().to_pathbuf())?))
    .collect::<Result<_, _>>()?;

@Plecra Plecra changed the title (Question) CompressionMethod deprecation of Unsupported API for reading raw file content Nov 15, 2020
@Plecra Plecra reopened this Nov 15, 2020
@Plecra
Copy link
Member

Plecra commented May 11, 2021

This is implemented as the ZipArchive::by_index_raw API

@Plecra Plecra closed this as completed May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants