Crates.io | stream-unpack |
lib.rs | stream-unpack |
version | 1.0.1 |
source | src |
created_at | 2024-01-12 20:52:31.618999 |
updated_at | 2024-01-22 13:30:26.414595 |
description | A small library for stream unpacking archives |
homepage | |
repository | https://github.com/mkrsym1/stream-unpack |
max_upload_size | |
id | 1098007 |
size | 87,265 |
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.
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