Skip to content

constructs synthetic Central Directories when missing from otherwise-valid ZIP data

Notifications You must be signed in to change notification settings

bungaku-moe/synthzip

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

synthzip Latest Version

What is it?

A rust library for constructing a synthetic Central Directory when you have ZIP data that has a Local File Header (LFH), but no Central Directory File Header (CDFH), or End of Central Directory (EOCD) data.

This is a somewhat niche library. You probably won't need it (directly), unless you happen to be doing something unusual. But if you are, it may be exactly what you need to do that one weird thing.

How do I obtain this majestic tool?

Run the following Cargo command in your project directory (assuming you have cargo-edit installed):

cargo add synthzip

Or add the following line to your Cargo.toml (in the [dependencies] array):

synthzip = "^ 0.1"

How do I use it?

fn main() {
  // This can be any source that implements Read + Seek, and reads a valid ZIP
  // Local File Header, compressed data, and (optional) trailing Data Descriptor.
  let mut input = std::io::Cursor::new(Vec::new());

  // read the data into an entry.
  let entry = synthzip::Entry::read(&mut input).expect("failed to read zip entry from input");

  // create a new (empty) CentralDirectory
  let mut index = synthzip::CentralDirectory::new();

  // add the Entry to the CentralDirectory. This will create a corresponding ZIP
  // Central Directory File Header and update the End of Central Directory appropriately.
  index.add(&entry)

  // this can be any destination that implements Write + Seek.
  let mut output = std::fs::File::create("/path/for/output.zip").expect("failed to create output file");

  // write the entry to the output destination.
  entry.write(&mut output).expect("failed to write zip entry to output");

  // write the Central Directory after the entry data.
  index.write(&mut output).expect("failed to write central directory to output");

  /// flush the output, if you're so inclined.
  output.flush().unwrap();
}

License

synthzip is available under the MIT License. See LICENSE.txt for the full text.

While the license is short, it's still written in fancy lawyer-speak. If you prefer more down-to-earth language, consider the following:

  • tl;drLegal has a simple visual summary available here.
  • FOSSA has a more in-depth overview available here.

About

constructs synthetic Central Directories when missing from otherwise-valid ZIP data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%