#zip-archive #stream #download #unpacking #deflate #multipart

stream-unpack

A small library for stream unpacking archives

5 releases (2 stable)

1.0.1 Jan 22, 2024
1.0.0 Jan 21, 2024
0.1.2 Jan 15, 2024
0.1.1 Jan 15, 2024
0.1.0 Jan 12, 2024

#256 in Compression

33 downloads per month

GPL-3.0 license

46KB
930 lines

stream-unpacker

A small library for stream unpacking archives (e.g. downloading and unpacking simultaneously). Currently supports single, multipart and fake multipart (single archive cut into multiple files) ZIPs, uncompressed and compressed with DEFLATE. This library requires you to obtain a central directory of the ZIP you want to unpack first, and provides utilities for doing so conveniently.

Example

See full examples in this repo.

let archive = fs::read("archive.zip").unwrap();

let central_directory = read_cd::from_provider(
    vec![archive.len()],
    false, // Determines whether to interpret it as a fake multipart (cut) archive
    |pos, length| Ok(archive[(pos.offset)..(pos.offset + length)].to_owned())
).unwrap();

let mut unpacker = ZipUnpacker::new(central_directory.sort(), vec![archive.len()]);
unpacker.set_callback(|data| {
    println!("Got data: {data:?}");
    // Do something useful with data. See full examples

    Ok(())
});

// You can provide an arbitrary amount of bytes at a time
// Make sure to advance the buffer exactly the amount of bytes returned
// All split archives (multipart and fake multipart) should be treated
// as a continuous stream of bytes from the first one to the last one
let (advanced, reached_end) = unpacker.update(archive).unwrap();

println!("Done!");

License: GPL v3

Dependencies

~0.5–1MB
~23K SLoC