compiling the zip2 crate to wasm with the goal of compiling to luau through wasynth
Find a file
Gregory Szorc 46c2ae88d4 Implement support for writing symlinks
The primary goal of this commit is to enable this library to emit
zip archives with symlinks while minimizing the surface area of the
change to hopefully enable the PR to merge with minimal controversy.

Today, it isn't possible to write symlinks with this library because
there's no way to preserve the upper S_IFMT bits in the file mode
bits because:

* There's no way to set FileOptions.permissions with the S_IFLNK bits
  set (FileOptions.unix_permissions() throws away bits beyond 0o777).
* Existing APIs for starting a "typed" (e.g. file or directory) entry
  automatically set the S_IFMT bits and could conflict with bits
  set on FileOptions.permissions.
* The low-level, generic start_entry() function isn't public.

When implementing this, I initially added a `FileOptions.unix_mode()`
function to allow setting all 16 bits in the eventual external
attributes u32. However, I quickly realized this wouldn't be enough
because APIs like start_file() do things like `|= 0o100000`. So if
we went this route, we'd need to make consumers of
FileOptions.permissions aware of when they should or shouldn't touch
the high bits beyond 0o777.

I briefly thought about making FileOptions.permissions an enum with
a variant to allow the st_mode bits to sail through unmodified. But
this change seemed overly invasive, low level, and not very
user-friendly.

So the approach I decided on was to define a new add_symlink() API.
It follows the pattern of add_directory() and provides an easy-to-use
and opionated API around the addition of a special file type.

I purposefully chose to not implement reading or extraction support
for symlinks because a) I don't need the feature at the moment
b) implementing symlink extraction in a way that works reliably on all
platforms and doesn't have security issues is hard. I figured it was
best to limit the scope of this change so this PR stands a good chance
of being merged.

Partially implements #77.
2022-04-12 10:58:24 -07:00
.github feat: add Clippy to CI 2022-01-23 19:02:57 +03:00
benches Use some ::with_capacity when reading zip file. 2022-04-11 16:17:20 +02:00
examples fix nightly clippy warnings in examples 2022-01-30 15:32:40 +01:00
src Implement support for writing symlinks 2022-04-12 10:58:24 -07:00
tests Merge branch 'feature/supported-methods' into feature/end-to-end-all-methods 2022-01-30 21:26:45 +00:00
.gitignore add libflate feature 2018-11-04 10:12:21 -08:00
Cargo.toml Use some ::with_capacity when reading zip file. 2022-04-11 16:17:20 +02:00
CODE_OF_CONDUCT.md doc: veeeery small fix to CoC 2022-01-23 17:35:39 +03:00
LICENSE Added Travis support, README and LICENSE 2014-09-11 10:50:41 +02:00
README.md feat: prepare 0.6.2 release 2022-04-02 17:34:07 +03:00

zip-rs

Build Status Crates.io version Discord

Documentation

PSA: This version of the ZIP crate will not gain any new features, and will only be updated if major security issues are found.

Info

A zip library for rust which supports reading and writing of simple ZIP files.

Supported compression formats:

  • stored (i.e. none)
  • deflate
  • bzip2
  • zstd

Currently unsupported zip extensions:

  • Encryption
  • Multi-disk

Usage

With all default features:

[dependencies]
zip = "0.6.2"

Without the default features:

[dependencies]
zip = { version = "0.6.2", default-features = false }

The features available are:

  • aes-crypto: Enables decryption of files which were encrypted with AES. Supports AE-1 and AE-2 methods.
  • deflate: Enables the deflate compression algorithm, which is the default for zip files.
  • bzip2: Enables the BZip2 compression algorithm.
  • time: Enables features using the time crate.
  • zstd: Enables the Zstandard compression algorithm.

All of these are enabled by default.

MSRV

Our current Minimum Supported Rust Version is 1.54.0. When adding features, we will follow these guidelines:

  • We will always support the latest four minor Rust versions. This gives you a 6 month window to upgrade your compiler.
  • Any change to the MSRV will be accompanied with a minor version bump
    • While the crate is pre-1.0, this will be a change to the PATCH version.

Examples

See the examples directory for:

  • How to write a file to a zip.
  • How to write a directory of files to a zip (using walkdir).
  • How to extract a zip file.
  • How to extract a single file from a zip.
  • How to read a zip from the standard input.