3 unstable releases

0.2.1 Jun 30, 2023
0.2.0 Apr 15, 2023
0.1.0 Feb 3, 2023

#294 in Compression

Download history 1/week @ 2024-02-16 12/week @ 2024-02-23 7/week @ 2024-03-01 1/week @ 2024-03-15 174/week @ 2024-03-22 29/week @ 2024-03-29 2/week @ 2024-04-05

205 downloads per month

Apache-2.0

33KB
528 lines

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

Dependencies

~250KB