Skip to content

Releases

v0.6.1

Choose a tag to compare

@github-actions github-actions released this 02 Dec 05:38
Immutable release. Only release title and notes can be modified.
1565ee5

Fixed

  • Reverted the breaking change in 0.6.0: codec.EmptyInput is removed again, and packkit.decompress and gzip.decode return InvalidData for empty input with the same per-format message as 0.5.x, such as "gzip header truncated". The public API is the same as 0.5.1. The Zstandard Content_Checksum check from 0.6.0 stays. Do not use 0.6.0.

Install

gleam add packkit

See HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.

v0.6.0

Choose a tag to compare

@github-actions github-actions released this 02 Dec 01:11
Immutable release. Only release title and notes can be modified.
801f714

Fixed

  • The Zstandard decoder now checks the Content_Checksum (the low 32 bits of XXH64 of the frame's content) when the frame sets the checksum flag. A corrupted frame returned different bytes instead of InvalidData.
  • packkit.decompress and gzip.decode return the new codec.EmptyInput error for empty input with every codec except Identity, instead of InvalidData with a different truncation message per format such as "gzip header truncated". Code that matches every CodecError variant needs an arm for EmptyInput.

Install

gleam add packkit

See HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.

v0.5.1

Choose a tag to compare

@github-actions github-actions released this 23 Nov 07:22
a9b930b

Fixed

  • The 7z reader checks max_entry_name_bytes, and the tar, cpio and ar readers and the Identity codec check max_output_bytes, like the other readers and codecs.
  • The 7z reader returns EntryRejected for an unsafe entry path, like the other readers, instead of InvalidData.
  • Reading an ar archive whose symbol table member has a negative size looped forever. A negative size, mode or name length, or a BSD long name longer than its member, is now InvalidData.
  • A cpio name size past the end of the input, or a body without its padding at the end of the input, panicked. Both are now InvalidData.
  • A tar PAX path or linkpath with non-ASCII characters kept the trailing newline, because the record length counts bytes and was applied to characters.
  • The LZ4 decoder now checks the frame header checksum, the block checksums and the content checksum, and the Snappy decoder checks the CRC-32C of each chunk. A corrupted stream returned different bytes instead of InvalidData.
  • A Brotli stream whose window is smaller than its output could not be decoded when it referred to the static dictionary past the window.
  • The 7z reader panicked on a file name outside the Basic Multilingual Plane, such as an emoji, and on an unpaired UTF-16 surrogate. It now reads surrogate pairs and returns InvalidData for an unpaired surrogate, and the 7z writer writes such names instead of returning EntryRejected.
  • A Brotli stream whose context map pointed past its prefix codes panicked. It is now InvalidData.
  • A 7z header with a huge file count made the reader build a list per file before checking max_members, which could run out of memory. The count is now checked first.

Install

gleam add packkit

See HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.

v0.5.0

Choose a tag to compare

@github-actions github-actions released this 23 Nov 02:51
993fc05

Breaking

The public API shrinks from 26 modules to 7: packkit, packkit/codec, packkit/archive, packkit/limit, packkit/gzip, packkit/zip and packkit/seven_z.

  • Archive, Entry, ArchiveFormat, Codec and Limits are plain records and custom types instead of opaque values, so they are built with their constructors and read by field access. Their getters and setters are removed: archive.new, from_entries, add, add_file, add_directory, add_symlink, add_hardlink, with_comment, entries, entry_count, format, comment, kind and name; codec.with_level, clear_level, with_dictionary, clear_dictionary, dictionary, dictionary_bytes, kind, name, level, dictionary_of and has_dictionary; and the limit getters, with_max_* setters, new and new_checked.
  • packkit/entry merges into packkit/archive. EntryKind carries the body or the link target (File(body), Directory, Symlink(target), Hardlink(target)), and archive.new_entry(path:, kind:) fills in the usual mode, owner 0 and time 0. Paths and metadata are checked when the archive is written: packkit.write, zip.encode and seven_z.encode return EntryRejected for an unsafe path, a NUL byte in a link target, or a negative mode, owner id or time. Metadata, EntryPath, EntryError, MetadataError, the getters, the setters and the _checked constructors are removed.
  • packkit/error is removed. CodecError moves to packkit/codec and ArchiveError to packkit/archive, and the variants lose their prefix, so CodecInvalidData becomes codec.InvalidData and ArchiveEntryRejected becomes archive.EntryRejected. CodecNotImplemented and ArchiveNotImplemented become Unsupported, FormatMismatch and CommentUnsupported carry ArchiveFormat values, and CodecDictionaryRequired has no field. format_codec_error and format_archive_error become codec.error_to_string and archive.error_to_string. RecipeError, DetectError, ArchiveUnsupported, CodecOptionUnsupported and CodecDictionaryMismatch are removed.
  • packkit/recipe and packkit/detect move into packkit. Recipe(format:, codecs:) lists codecs from the inside out; the 18 shortcut constructors, archive_only, archive_with, wrap, the getters and description are removed. Detection returns Result(Detected, Nil), where Detected is Compressed(codec) or Archived(recipe), from packkit.detect_filename, detect_bytes and detect (was detect_path_or_bytes).
  • packkit/level is removed, together with compression levels and zlib preset dictionaries. The zlib decoder only checked the dictionary id and never used the dictionary as history.
  • packkit/stream and the gzip Decoder are removed. They kept every chunk in memory and decoded once at the end; join the chunks and call packkit.decompress instead.
  • packkit/checksum and the modules for tar, cpio, ar and every codec except gzip are internal now. Use packkit.compress, decompress, read and write. Their extra functions (deflate.encode_stored_only, encode_dynamic and decode_with_remainder, bzip2.encode_with_level, lz4.encode_with_content_size, lzw.encode_with_options, the Snappy raw block functions and zstd.frame_header_for_size) are no longer public.
  • The first argument of compress, decompress, read, unpack, pack and their _with_limits forms has no label, and write takes only the archive, because the archive knows its format. packkit.package_version is removed.
  • gzip.Header is a record with name, comment, modified_at and extra. gzip.encode(bytes, header:) checks the header and returns HeaderError, whose variants lose the Header prefix. gzip.decode(bytes, limits:) returns the header and the payload. default_header, the setters, the getters, encode_with_header, decode_payload, decode_payload_with_limits, decode_with_limits and codec are removed.
  • zip.Method and seven_z.Method are plain custom types such as zip.Deflate and seven_z.Lzma. zip.encode(archive, method:) replaces encode and encode_with_method, and seven_z.encode(archive, method:, encryption:) with Unencrypted, EncryptContents(password) or EncryptContentsAndHeaders(password) replaces the six encode_* functions. decode_with_password(bytes:, password:, limits:) replaces the two password decoders in each module. format, new, decode, decode_with_limits, zip.name and zip.inner_codec are removed.
  • Limits loses max_window_bits. A zlib stream whose window is over 32 KiB is now InvalidData, as RFC 1950 requires.

Before:

import packkit
import packkit/archive
import packkit/recipe
import packkit/tar

let archive_value =
  tar.new() |> tar.add_file(path: "hello.txt", body: <<"hi":utf8>>)
let assert Ok(bytes) =
  packkit.pack(archive_value: archive_value, using: recipe.tar_gzip())
let assert Ok(decoded) = packkit.unpack(bytes: bytes, using: recipe.tar_gzip())
archive.entry_count(decoded)

After:

import gleam/list
import gleam/option.{None}
import packkit
import packkit/archive.{Archive, File}
import packkit/codec

let hello = archive.new_entry(path: "hello.txt", kind: File(<<"hi":utf8>>))
let backup = Archive(format: archive.Tar, entries: [hello], comment: None)
let recipe = packkit.Recipe(format: archive.Tar, codecs: [codec.Gzip])
let assert Ok(bytes) = packkit.pack(backup, using: recipe)
let assert Ok(decoded) = packkit.unpack(bytes, using: recipe)
list.length(decoded.entries)

Fixed

  • Reading a tar or ar entry whose mode does not fit in 16 bits, such as a tar header with mode 7777777, panicked. The mode is now kept as it is.
  • Writing a 7z archive with a comment dropped the comment silently. It now returns CommentUnsupported, like tar, cpio and ar.
  • The cpio writer put the whole mode next to the file type bits, so a mode read from ZIP such as 0o100644 produced an archive packkit could not read. It now keeps only the permission bits.
  • ZIP returns FieldOverflow for a modification time or owner id that does not fit in 32 bits, and 7z for a time past the FILETIME range, instead of cutting the value down.

Install

gleam add packkit

See HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.

v0.4.0

Choose a tag to compare

@github-actions github-actions released this 19 Nov 12:02
eedc259

Changed

  • GitHub Releases now attach the Hex package tarball, checksums.txt, a keyless cosign signature bundle for it and build provenance (*.intoto.jsonl). See "Verifying releases" in the README.

Install

gleam add packkit

See HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.

v0.3.0

Choose a tag to compare

@github-actions github-actions released this 11 Sep 01:36
79580c4

Documentation

  • README: archive.entry_by_path returns the first of two entries with the same path, while tar -xf leaves the last one on disk; the "Inspecting an archive" section now says so and shows how to get the last one (search the reversed archive.entries). A test pins that recipe. (#4)

Install

gleam add packkit

See HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.

v0.2.0

Choose a tag to compare

@github-actions github-actions released this 10 Sep 14:41
1478266

Changed

  • The minimum Gleam version is now 1.14.0 (was 1.15.0). 1.14.0 builds and tests the package unchanged on both targets, and gleam_stdlib 1.0 already requires it. CI tests that floor alongside the latest Gleam 1.x.
  • 64-bit little-endian fields in ZIP (Zip64 sizes and offsets, 8-byte Info-ZIP uid/gid) and 7z (entry mtime) are now read as two 32-bit halves. Results on Erlang are unchanged; on JavaScript this removes the compiler's truncation warning for 64-bit integer segments.

Fixed

  • The doc comments of limit.with_max_members and limit.with_max_entry_depth now point to the clamp-to-1 contract of limit.with_max_input_bytes, like the other unchecked setters.

Install

gleam add packkit

See HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.

v0.1.0

Choose a tag to compare

@github-actions github-actions released this 26 May 14:23
980ed98

Initial public release. The bullets below are the entire change history
accumulated during the pre-1.0 scaffold-to-stable arc; everything listed
ships in v0.1.0. Highlights of the pre-release hardening pass:

  • Fix (gzip, RFC 1952 §2.3.1 compliance): the decoder now (a) rejects
    reserved FLG bits 0x20 / 0x40 / 0x80 with a typed
    CodecInvalidData("gzip reserved FLG bits set") instead of silently
    ignoring them; (b) actually verifies the FHCRC field against the
    CRC-16 of the preceding header bytes (low two bytes of CRC-32) and
    surfaces a typed gzip header CRC16 mismatch on disagreement
    (previously the two bytes were skipped without verification); and
    (c) decodes FNAME / FCOMMENT through a UTF-8-then-Latin-1 fallback so
    RFC-conformant ISO-8859-1 names from older gzip producers no longer
    surface as "gzip header string is not UTF-8".
  • Fix (archive): archive.entry_by_path searches in insertion order
    (the order the docstring promises and entries() |> list.find(...)
    produces) instead of the internal reversed list, so duplicate-path
    archives return the first match, not the last.
  • Fix (gzip): with_name / with_comment panic on embedded NUL
    to keep the round-trip law name(with_name(h, x)) == Some(x).
    Previously they silently stripped NULs, breaking the law; the checked
    counterparts (with_name_checked / with_comment_checked) are still
    the untrusted-input route.
  • Fix (lz4, JS target): refactored decode_block_loop,
    decode_blocks, decode_legacy_blocks, and copy_match_byte_by_byte
    into Step/Continue trampolines, mirroring the deflate / bzip2 fix.
    Decoding more than ~1500 LZ77 sequences on JS no longer overflows the
    call stack with RangeError: Maximum call stack size exceeded.
  • Fix (detect): from_path_or_bytes surfaces the caller-supplied
    path in the DetectUnknownFormat.input field when both detection
    paths fail, instead of the internal "byte-signature scan" sentinel.
  • Tests: added 180 differential-corpus tests across gzip / bzip2 /
    xz / zstd / lz4 / lzw (compress) against the system CLI, plus six
    metamon-driven recipe pack/unpack round-trip properties.
  • Docs: README rewritten around worked examples (every code block
    is checked by test/packkit/readme_examples_test.gleam so it cannot
    silently rot); doc/reference/spec.md removed (it was local-only,
    gitignored, and stale).
  • Workflows: the GitHub Release body now points at
    CHANGELOG.md rather than a non-existent repository spec.

The remaining bullets are the per-feature history of the 0.1.0 cycle.

  • Feature (brotli): the encoder now also emits a real LZ77
    compressed metablock as a third candidate (alongside the existing
    uncompressed and literals-only paths). A greedy 4-byte hash-chain
    match finder over the 32 KiB window produces insert-and-copy
    commands; each command picks a cell_idx ≥ 2 IC symbol so the
    distance is read from a dedicated distance Huffman code instead of
    reusing the ring buffer. Three complex-form Huffman descriptors
    (256 literal, 704 IC, 64 distance) describe the alphabet, all
    built via the same naive frequency-merge Huffman the literals path
    already used. Repetitive payloads compress dramatically further:
    1 KiB of zeros drops to ~60 bytes (was ~140 bytes), "abc" x 100
    to ~54 bytes (was ~85), and 1.35 KiB of repeated lorem-ipsum to
    ~100 bytes. All outputs round-trip through both packkit's own
    decoder and the reference brotli CLI.
  • Fix (brotli encoder, single-symbol Huffman codes):
    assign_brotli_canonical_codes now matches the decoder's
    canonicalise_from_pairs special case for single-active-symbol
    alphabets: the decoder treats them as zero-bit codes
    (decode_prefix_walk exits immediately when an entry has
    length == 0 && code == 0), so the encoder must too — otherwise
    the descriptor's trailing bits leak into the next section. The
    bug surfaced when the LZ77 distance alphabet held a single code
    (e.g., every command shared the same distance), shifting all
    subsequent bitstream sections.
  • Feature (brotli): the encoder now optionally emits a single
    ISLAST=1 compressed metablock whose literal alphabet uses a
    complex-form Huffman code (RFC 7932 §3.5), still without an LZ77
    match step. The complex-form descriptor is built via a CL-Huffman
    table length-limited to 5 bits, RLE-encoded with sym 16 / 17 chain-
    breaking Lit separators, trimmed at the last non-zero alphabet
    length, and — crucially — terminated as soon as the CL Huffman
    space is exhausted (matching the decoder's early-exit Kraft check
    in read_one_cl). The encoder picks the smaller of the
    uncompressed and the compressed candidate per payload, so
    incompressible payloads never regress. Repetitive byte alphabets
    (e.g. abc x 100, mostly-zero tar headers) round-trip through both
    packkit's own decoder and the reference brotli CLI.
  • Fix (brotli decoder, JS target): emit_literals_loop and
    decode_prefix_walk previously called themselves through
    use <- result.try(...) closures and through mutually-recursive
    helpers, so the Gleam JS compiler could not emit a while loop.
    Each compressed-metablock literal added a stack frame and a payload
    of more than ~10 000 prefix-code bit reads — easily reached by a
    3 KiB tar archive — blew the JS engine's call-stack limit. Both
    loops are now structured around an explicit LiteralStep /
    inlined-case dispatcher so the recursive call stays in tail
    position, restoring single-frame iteration on JS.
  • Feature (zstd): the sequences encoder now also emits
    FSE_Compressed_Mode for LL/OF/ML tables whenever the per-chunk
    symbol distribution is biased enough that a chunk-specific FSE
    distribution beats the predefined one. Once a chunk has ≥ 32
    sequences the encoder tallies the LL/ML/OF codes, normalises
    each alphabet to a power-of-2 table size (accuracy_log chosen
    per RFC 8478 §3.1.1.3.2.2.1.1 — capped at 9 / 8 / 9
    respectively), builds the encoder state tables via the
    decoder-side fse.build_state_table (so encoder and decoder
    see identical layouts), and emits a distribution header
    followed by the FSE bitstream. When the resulting section
    beats the Predefined_Mode candidate, the encoder switches to
    the 0xA8 mode byte (all three alphabets at value 2 =
    FSE_Compressed_Mode); otherwise it falls back to the
    predefined-tables path with the original 0x00 mode byte.
    Highly-biased inputs (e.g. an ABCDX motif x 100) now
    compress to ~3 % of raw size; uniform inputs incur no overhead
    because the comparison stage rejects the FSE-compressed
    candidate whenever it would be larger.
  • Feature (zstd): the LZ77 sequences encoder now threads the
    three-entry rep-offset ring (per RFC 8478 §3.1.1.5 — initial
    (1, 4, 8)) through every chunk, so matches whose real
    distance hits one of the recent offsets collapse onto
    raw_offset = 1, 2, or 3 instead of distance + 3. The
    literal_length == 0 branch is also honoured (raw_offset 1
    selects rep[1], 2 selects rep[2], 3 selects rep[0] - 1), and
    the encoder rotates the ring the same way the decoder's
    resolve_offset does so encoder and decoder stay in
    lockstep. Payloads that hit the same distance over and over
    now compress dramatically further — a 4-byte motif repeated
    200 times shrinks below 5 % of its raw size.
  • Feature (zstd): the zstd encoder now optionally emits a
    Compressed_Block whose Sequences_Section carries real LZ77
    sequences in addition to the existing literals-only path. A
    greedy 3-byte hash-chain match finder over each 16 KiB chunk
    (32 KiB max distance) produces Sequence(literal_length, match_length, offset) triples; the sequence symbols are
    encoded under Predefined_Mode for all three FSE alphabets
    (LL / OF / ML) so the sequence section is just
    Number_of_Sequences ++ 0x00 ++ FSE_bitstream. Each chunk
    independently picks the smallest of Raw / RLE / Huffman /
    sequences, so incompressible blocks never regress. Highly
    repetitive payloads now compress dramatically below the
    literals-only floor — e.g. a 16-byte motif repeated 50 times
    (800 bytes) drops to well under 200 bytes through the
    sequences path.
  • Feature (zip): ZIP decoder now reads entries protected by the
    PKWARE "traditional" / "ZipCrypto" encryption scheme via two new
    public entry points — zip.decode_with_password and
    zip.decode_with_password_and_limits. The decoder seeds the
    three-key cipher state from the supplied password, decrypts each
    entry's 12-byte encryption header, verifies the trailing byte
    against the high byte of the entry's CRC-32 (APPNOTE §6.0), and
    hands the resulting plaintext to the matching method (store,
    deflate, bzip2, zstd, xz, lzma). Encrypted entries
    reached by the plain zip.decode API surface a typed
    ArchiveNotImplemented so the missing password is never silently
    ignored; wrong passwords come back as ArchiveInvalid rather than
    passing garbage to the codec. Strong-encryption (gp flag bit 6)
    is rejected with a typed not-implemented error rather than
    decoded as ZipCrypto.
  • Feature (zstd): the zstd Huffman literals encoder now also
    emits the FSE-compressed tree-description form (header byte
    0..127 + FSE body) when the direct-weight form can't carry the
    alphabet. Tree descriptions for byte alphabets that stream
    more than 127 weights — i.e. anything that uses byte values
    above 127 — are now Huffman-encoded instead of falling back to
    Raw / RLE. The FSE encoder builds normalised counts (floor-
    scale at accuracy_log = 6, give the remainder to the largest
    count), writes the distribution header forward, then inverts
    the decoder's fse.build_state_table to drive a two-state
    backward encoding loop with the standard zstd "highest set bit
    of the last byte" marker. A chunk whose FSE body would exceed
    the 12...
Read more