stream-unzip

Crates.iostream-unzip
lib.rsstream-unzip
version0.2.1
sourcesrc
created_at2023-02-03 01:56:55.037401
updated_at2023-06-30 18:07:25.019461
descriptionUnzip a file incrementally
homepage
repositoryhttps://github.com/jsoverson/stream-unzip
max_upload_size
id775325
size86,594
Jarrod Overson (jsoverson)

documentation

README

stream-unzip

This library is a minimal unzip implementation designed for streaming data.

Important note

Zip files contain the central directory at the end of the file. This library decodes Zip entries as they are read and does not reference the central directory.

This works for many zip files but there may be edge cases.

Usage

let path = "path/to/file.zip";
let mut file = tokio::fs::File::open(path).await.unwrap();
let mut buff: [u8; 1024] = [0; 1024];

let mut zip_reader = ZipReader::default();
while let Ok(num) = file.read(&mut buff).await {
    if num == 0 {
        break;
    }
    zip_reader.update(buff[..num].to_vec().into());

    // Entries can be drained from the reader as they
    // are completed.
    let entries = zip_reader.drain_entries();
    for entry in entries {
        println!("entry: {}", entry.name());
        // write to disk or whatever you need.
    }

}
// Or read the whole file and deal with the entries
// at the end.
zip_reader.finish();
let entries = zip_reader.drain_entries();

Running the example

cargo run --example <zip file> <output directory>

Contributing

There are known zip files that this library can not yet decode. They are found in the testdata/todo directory. They will be addressed by the author when the need arises but you are free to contribute fixes for them at any time. If there are other issues with decompressing zip files, please include a minimal zip file that reproduces the issue.

License

This project is licensed under

Commit count: 14

cargo fmt