4 releases

0.0.4 Aug 22, 2024
0.0.3 Jul 7, 2024
0.0.2 Jun 30, 2024
0.0.1 Jun 27, 2024

#136 in Compression

Download history 303/week @ 2024-06-27 126/week @ 2024-07-04 11/week @ 2024-07-11 1/week @ 2024-07-18 15/week @ 2024-07-25 10/week @ 2024-08-01 5/week @ 2024-08-08 14/week @ 2024-08-15 198/week @ 2024-08-22 63/week @ 2024-08-29

281 downloads per month
Used in airshipper

Apache-2.0 OR MIT

105KB
2K SLoC

Crates.io docs.rs pipeline status coverage report license dependencies

zip-core

Helper library to provide zip parsing according to PKWARE-APPNOT Version: 6.3.10 This library is intendent to be implementation independent, no_std basic functionality, structs/enum for zip crates. By default std is used, however it can be disabled via default-features = false.

zip

[local file header 1]
[encryption header 1]
[file data 1]
[data descriptor 1]
.
.
.
[local file header n]
[encryption header n]
[file data n]
[data descriptor n]
[archive decryption header]
[archive extra data record]
[central directory header 1]
.
.
.
[central directory header n]
[zip64 end of central directory record]
[zip64 end of central directory locator]
[end of central directory record]

Usage

You can use this crate to generate your own zip parser. Either because you are owner of the very good zip crate, or you want to build your own async version of it. Or you want to build your own zip parser, e.g. to extract as much data of a corupted file without any errors.

The nature of this crate is io-less, we don't offer any functionality to load in a file, a stream or anything. except for bytes::Buf if the parse feature is enabled.

You can use this crate and provide your own io logic around it, e.g. like:

let file = include_bytes!("example.zip");
let mut i = 0;
while let Some(local_occurence) = find_next_signature(
    &file[i..],
    core_zip::raw::CentralDirectoryHeaderFixed::CENTRAL_FILE_HEADER_SIGNATURE.to_le_bytes(),
) {
    let occurence = i + local_occurence;
    let mut buf = &file[occurence..];
    if let Ok(f) = CentralDirectoryHeaderFixed::from_buf(&mut buf) {
        println!("{:?}", std::str::from_utf8(&f.file_name));
    }
    i = occurence + 3;
}

You might see the std::str::from_utf8, thats right, this crate doesn't even interpret the data in the records (except from some size values).

It provides some utilities, e.g. is_valid_signature to check if the signature you parsed is correct, but it wont stop you from doing weird stuff with your zip.

You could also use this crate to craft your own zipbombs, posibilities are endless.

In case you wondered: the need for this crate came from the veloren project, we want to upload our game without redownloading a whole zip, so we want to only download those parts where the crc missmatches.

See the documentation and the examples for more information on how to use this crate.

Dependencies