Repository navigation
Releases
v0.6.1
Fixed
- Reverted the breaking change in 0.6.0:
codec.EmptyInputis removed again, andpackkit.decompressandgzip.decodereturnInvalidDatafor 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 packkitSee HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.
v0.6.0
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.decompressandgzip.decodereturn the newcodec.EmptyInputerror for empty input with every codec exceptIdentity, instead ofInvalidDatawith a different truncation message per format such as"gzip header truncated". Code that matches everyCodecErrorvariant needs an arm forEmptyInput.
Install
gleam add packkitSee HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.
v0.5.1
Fixed
- The 7z reader checks
max_entry_name_bytes, and the tar, cpio and ar readers and theIdentitycodec checkmax_output_bytes, like the other readers and codecs. - The 7z reader returns
EntryRejectedfor an unsafe entry path, like the other readers, instead ofInvalidData. - 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
pathorlinkpathwith 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
InvalidDatafor an unpaired surrogate, and the 7z writer writes such names instead of returningEntryRejected. - 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 packkitSee HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.
v0.5.0
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,CodecandLimitsare 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,kindandname;codec.with_level,clear_level,with_dictionary,clear_dictionary,dictionary,dictionary_bytes,kind,name,level,dictionary_ofandhas_dictionary; and thelimitgetters,with_max_*setters,newandnew_checked.packkit/entrymerges intopackkit/archive.EntryKindcarries the body or the link target (File(body),Directory,Symlink(target),Hardlink(target)), andarchive.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.encodeandseven_z.encodereturnEntryRejectedfor 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_checkedconstructors are removed.packkit/erroris removed.CodecErrormoves topackkit/codecandArchiveErrortopackkit/archive, and the variants lose their prefix, soCodecInvalidDatabecomescodec.InvalidDataandArchiveEntryRejectedbecomesarchive.EntryRejected.CodecNotImplementedandArchiveNotImplementedbecomeUnsupported,FormatMismatchandCommentUnsupportedcarryArchiveFormatvalues, andCodecDictionaryRequiredhas no field.format_codec_errorandformat_archive_errorbecomecodec.error_to_stringandarchive.error_to_string.RecipeError,DetectError,ArchiveUnsupported,CodecOptionUnsupportedandCodecDictionaryMismatchare removed.packkit/recipeandpackkit/detectmove intopackkit.Recipe(format:, codecs:)lists codecs from the inside out; the 18 shortcut constructors,archive_only,archive_with,wrap, the getters anddescriptionare removed. Detection returnsResult(Detected, Nil), whereDetectedisCompressed(codec)orArchived(recipe), frompackkit.detect_filename,detect_bytesanddetect(wasdetect_path_or_bytes).packkit/levelis 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/streamand the gzipDecoderare removed. They kept every chunk in memory and decoded once at the end; join the chunks and callpackkit.decompressinstead.packkit/checksumand the modules for tar, cpio, ar and every codec except gzip are internal now. Usepackkit.compress,decompress,readandwrite. Their extra functions (deflate.encode_stored_only,encode_dynamicanddecode_with_remainder,bzip2.encode_with_level,lz4.encode_with_content_size,lzw.encode_with_options, the Snappy raw block functions andzstd.frame_header_for_size) are no longer public.- The first argument of
compress,decompress,read,unpack,packand their_with_limitsforms has no label, andwritetakes only the archive, because the archive knows its format.packkit.package_versionis removed. gzip.Headeris a record withname,comment,modified_atandextra.gzip.encode(bytes, header:)checks the header and returnsHeaderError, whose variants lose theHeaderprefix.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_limitsandcodecare removed.zip.Methodandseven_z.Methodare plain custom types such aszip.Deflateandseven_z.Lzma.zip.encode(archive, method:)replacesencodeandencode_with_method, andseven_z.encode(archive, method:, encryption:)withUnencrypted,EncryptContents(password)orEncryptContentsAndHeaders(password)replaces the sixencode_*functions.decode_with_password(bytes:, password:, limits:)replaces the two password decoders in each module.format,new,decode,decode_with_limits,zip.nameandzip.inner_codecare removed.Limitslosesmax_window_bits. A zlib stream whose window is over 32 KiB is nowInvalidData, 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
0o100644produced an archive packkit could not read. It now keeps only the permission bits. - ZIP returns
FieldOverflowfor 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 packkitSee HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.
v0.4.0
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 packkitSee HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.
v0.3.0
Documentation
- README:
archive.entry_by_pathreturns the first of two entries with the same path, whiletar -xfleaves the last one on disk; the "Inspecting an archive" section now says so and shows how to get the last one (search the reversedarchive.entries). A test pins that recipe. (#4)
Install
gleam add packkitSee HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.
v0.2.0
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_stdlib1.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_membersandlimit.with_max_entry_depthnow point to the clamp-to-1 contract oflimit.with_max_input_bytes, like the other unchecked setters.
Install
gleam add packkitSee HexDocs for the API
reference and
CHANGELOG.md
for the implementation history.
v0.1.0
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 typedgzip header CRC16 mismatchon 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 oldergzipproducers no longer
surface as"gzip header string is not UTF-8". - Fix (archive):
archive.entry_by_pathsearches in insertion order
(the order the docstring promises andentries() |> 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_commentpanic on embedded NUL
to keep the round-trip lawname(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, andcopy_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 withRangeError: Maximum call stack size exceeded. - Fix (detect):
from_path_or_bytessurfaces the caller-supplied
pathin theDetectUnknownFormat.inputfield 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 bytest/packkit/readme_examples_test.gleamso it cannot
silently rot);doc/reference/spec.mdremoved (it was local-only,
gitignored, and stale). - Workflows: the GitHub Release body now points at
CHANGELOG.mdrather 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 acell_idx ≥ 2IC 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 referencebrotliCLI. - Fix (brotli encoder, single-symbol Huffman codes):
assign_brotli_canonical_codesnow matches the decoder's
canonicalise_from_pairsspecial case for single-active-symbol
alphabets: the decoder treats them as zero-bit codes
(decode_prefix_walkexits 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-
breakingLitseparators, 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
inread_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.abcx 100, mostly-zero tar headers) round-trip through both
packkit's own decoder and the referencebrotliCLI. - Fix (brotli decoder, JS target):
emit_literals_loopand
decode_prefix_walkpreviously called themselves through
use <- result.try(...)closures and through mutually-recursive
helpers, so the Gleam JS compiler could not emit awhileloop.
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 explicitLiteralStep/
inlined-casedispatcher so the recursive call stays in tail
position, restoring single-frame iteration on JS. - Feature (zstd): the sequences encoder now also emits
FSE_Compressed_Modefor 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-sidefse.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
the0xA8mode byte (all three alphabets at value 2 =
FSE_Compressed_Mode); otherwise it falls back to the
predefined-tables path with the original0x00mode byte.
Highly-biased inputs (e.g. anABCDXmotif 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, or3instead ofdistance + 3. The
literal_length == 0branch 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_offsetdoes 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) producesSequence(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_passwordand
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 plainzip.decodeAPI surface a typed
ArchiveNotImplementedso the missing password is never silently
ignored; wrong passwords come back asArchiveInvalidrather 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'sfse.build_state_tableto 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...