4 releases

0.2.1 Nov 24, 2022
0.2.0 Jul 25, 2021
0.1.1 Feb 25, 2021
0.1.0 Feb 22, 2021

#311 in Compression

Download history 3754/week @ 2024-12-17 3072/week @ 2024-12-24 4288/week @ 2024-12-31 4312/week @ 2025-01-07 3570/week @ 2025-01-14 3521/week @ 2025-01-21 3409/week @ 2025-01-28 3233/week @ 2025-02-04 3366/week @ 2025-02-11 4096/week @ 2025-02-18 3480/week @ 2025-02-25 3452/week @ 2025-03-04 3847/week @ 2025-03-11 4058/week @ 2025-03-18 4282/week @ 2025-03-25 5421/week @ 2025-04-01

18,208 downloads per month
Used in 22 crates (3 directly)

MIT license

41KB
594 lines

Rust crates for ZIP structures (zip_structs)

CI (master) CI (Release) zip_structs at crates.io zip_structs at docs.rs

This crates handles structures in ZIP files.

  • End of central directory (EOCD) structure
  • Central directory structure
  • Local file header structure
    • Data descriptor structure

Installation

Add the following line to [dependencies] in your Cargo.toml.

zip_structs = "^0.2"

Breaking changes to the API are planned for the future. Therefore, it is strongly recommended to use this versioning format.

Basic usage of parsing from the EOCD sturcture of a ZIP archive

use std::io::BufReader;
use std::fs::File;
use oem_cp::decode_string_complete_table;
use oem_cp::code_table::DECODING_TABLE_CP437;

use zip_structs::zip_central_directory::ZipCDEntry;
use zip_structs::zip_eocd::ZipEOCD;
use zip_structs::zip_local_file_header::ZipLocalFileHeader;

let mut zip_file = BufReader(File::open("path/to/archive.zip")?);

let eocd = ZipEOCD::from_reader(&mut zip_file)?;
let cd_list = ZipCDEntry::all_from_eocd(&mut zip_file, &eocd)?;

// Show file names in the ZIP archive
for cd in &cd_list {
    println!(
        "{}",
        if cd.is_encoded_in_utf8() {
            String::from_utf8_lossy(&cd.file_name_raw);
        } else {
            decode_string_complete_table(&cd.file_name_raw, DECODING_TABLE_CP437)
        }
    );
    let local_file_header = ZipLocalFileHeader::from_central_directory(&mut zip_file, &cd)?;
    do_something(&local_file_header);
}

Competing libraries

There are some libraries providing more abstract and higher-level APIs.

  • zip
  • rc-zip

These libraries do not handle general purpose bit flags in central directories and local file headers. rc-zip cannot handle file names encoded in other than UTF-8.

  • vfs-zip

This library provides virtual file system, not structures in ZIP archives.

Support of ZIP64

This library has not supported ZIP64 yet.

License

MIT

See LICENSE

Dependencies

~0.4–0.8MB
~19K SLoC