packkit/zip

Writing ZIP with a compression method, and reading ZIP archives encrypted with ZipCrypto or WinZip AES. packkit.write stores ZIP entries without compression, and packkit.read reads any unencrypted ZIP archive.

The reader and writer support Zip64, so an archive can hold more than 65,535 entries and entries over 4 GiB. File names are written as UTF-8.

Types

How the body of each file entry is compressed. Directories are always stored.

pub type Method {
  Store
  Deflate
  Bzip2
  Lzma
  Zstd
  Xz
}

Constructors

  • Store

    No compression (method 0).

  • Deflate

    DEFLATE (method 8), readable by every ZIP tool.

  • Bzip2

    bzip2 (method 12).

  • Lzma

    LZMA (method 14).

  • Zstd

    Zstandard (method 93).

  • Xz

    xz (method 95).

Values

pub fn decode_with_password(
  bytes bytes: BitArray,
  password password: String,
  limits limits: limit.Limits,
) -> Result(archive.Archive, archive.ArchiveError)

Reads a ZIP archive whose entries may be encrypted with ZipCrypto or WinZip AES (AE-1 and AE-2). Entries that are not encrypted are read as usual.

A wrong password returns InvalidData. Use packkit.read for archives without a password.

pub fn encode(
  archive_value: archive.Archive,
  method method: Method,
) -> Result(BitArray, archive.ArchiveError)

Writes archive as ZIP, compressing every file entry with method.

Returns EntryRejected for symbolic and hard links, which this writer does not store, and for the unsafe paths packkit.write rejects.

Examples

let report = archive.new_entry(path: "report.csv", kind: File(<<"a,b\n":utf8>>))
encode(Archive(format: Zip, entries: [report], comment: None), method: Deflate)
✨ Search Document