Repository navigation
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.