@std/io/archive.ms#
Import each required symbol with import Name from "@std/io/archive.ms".
ArchiveEntry Type#
One file or directory in an archive. Paths use forward slashes.
type ArchiveEntry {
path String
data Bytes
directory Bool
}ArchiveEntry.data#
File contents as immutable bytes; a directory entry must have empty bytes.
data BytesArchiveEntry.directory#
True for a directory entry, false for a regular file. Links and special files are not supported.
directory BoolArchiveEntry.path#
Relative forward-slash path. pack and unpack reject path traversal, absolute
paths and duplicate normalized names. Tar unpack also skips a bare ./ entry
and strips a leading ./ from member names (as in tar -cf x.tar .); pack is
strict. unpack returns directory paths without a trailing slash.
path StringArchiveFormat Enum#
A supported archive format.
enum ArchiveFormat {
Zip
Tar
}ArchiveFormat.Tar#
TAR files and directories.
TarArchiveFormat.Zip#
ZIP files and directories.
ZipArchiveOptions Type#
Limits applied while unpacking untrusted archive data. A field left as null sets
no limit.
type ArchiveOptions {
max_entries Int? = null
max_entry_bytes Int? = null
max_bytes Int? = null
}ArchiveOptions.max_bytes#
Maximum unpacked file bytes summed across all entries.
max_bytes Int? = nullArchiveOptions.max_entries#
Maximum unpacked entries, including directories.
max_entries Int? = nullArchiveOptions.max_entry_bytes#
Maximum unpacked bytes for each entry; zero admits only empty data.
max_entry_bytes Int? = nullCompressOptions Type#
Settings for compress: the DEFLATE level (0 to 9, default 6) and an optional limit
on the encoded output bytes.
type CompressOptions {
level Int = 6
max_bytes Int? = null
}CompressOptions.level#
Compression level 0 to 9, where 0 stores the data uncompressed and 6 is balanced.
Other levels return EINVAL.
level Int = 6CompressOptions.max_bytes#
Maximum encoded bytes; null sets no limit.
max_bytes Int? = nullCompressionFormat Enum#
A compression format. Deflate is raw DEFLATE without a wrapper.
enum CompressionFormat {
Gzip
Zlib
Deflate
}CompressionFormat.Deflate#
Raw DEFLATE without framing.
DeflateCompressionFormat.Gzip#
DEFLATE data wrapped in GZIP headers and a checksum trailer.
GzipCompressionFormat.Zlib#
DEFLATE data with ZLIB header and Adler-32 checksum framing.
Zlibcompress Function#
Compresses data as format. When options.max_bytes is supplied, it bounds the
encoded output.
fn compress(data Bytes, format CompressionFormat, options CompressOptions = CompressOptions()) Result[Bytes, Error] { ... }compressed Function#
Compresses a byte stream into format, chunk by chunk, holding only the codec’s
window in memory. level defaults to 6 and must be 0 to 9; otherwise reads fail
with EINVAL. Closing the result closes input.
fn compressed(move input ReadStream[Bytes], format CompressionFormat, level Int = 6) ReadStream[Bytes] { ... }decompress Function#
Decompresses data from format. Output beyond max_bytes stops with
EOVERFLOW.
fn decompress(data Bytes, format CompressionFormat, max_bytes Int? = null) Result[Bytes, Error] { ... }decompressed Function#
Decompresses a byte stream from format, chunk by chunk. Malformed or truncated
data, or bytes after the payload, fail the read with EBADMSG. max_bytes bounds
the total output, and exceeding it fails with EOVERFLOW. Closing the result closes
input.
fn decompressed(move input ReadStream[Bytes], format CompressionFormat, max_bytes Int? = null) ReadStream[Bytes] { ... }pack Function#
Encodes entries as format. When max_bytes is supplied, it bounds the encoded
output.
fn pack(entries List[ArchiveEntry], format ArchiveFormat, max_bytes Int? = null) Result[Bytes, Error] { ... }tar_entries Function#
Reads the entries of a tar byte stream one at a time, for archives too big to hold
in memory. Each entry is validated as unpack does. max_entry_bytes bounds one
entry, and max_entries and max_bytes bound the whole archive; exceeding a limit
fails the read with EOVERFLOW. A truncated archive fails with EBADMSG.
Like unpack, it stops at the first zero block and ignores what follows, since
archives are often padded to a blocking factor. It accepts a last member whose data
is complete but whose padding is short. Unlike a compression stream, a tar has no
trailer to check. Closing the result closes input.
fn tar_entries(move input ReadStream[Bytes], options ArchiveOptions = ArchiveOptions()) ReadStream[ArchiveEntry] { ... }unpack Function#
Decodes archive data in format, applying the entry and size limits in
options.
fn unpack(data Bytes, format ArchiveFormat, options ArchiveOptions = ArchiveOptions()) Result[List[ArchiveEntry], Error] { ... }