Manuscript Documentation
v2026.12.0

@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.

Manuscript
type ArchiveEntry {
    path String
    data Bytes
    directory Bool
}

ArchiveEntry.data#

File contents as immutable bytes; a directory entry must have empty bytes.

Manuscript
data Bytes

ArchiveEntry.directory#

True for a directory entry, false for a regular file. Links and special files are not supported.

Manuscript
directory Bool

ArchiveEntry.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.

Manuscript
path String

ArchiveFormat Enum#

A supported archive format.

Manuscript
enum ArchiveFormat {
    Zip
    Tar
}

ArchiveFormat.Tar#

TAR files and directories.

Manuscript
Tar

ArchiveFormat.Zip#

ZIP files and directories.

Manuscript
Zip

ArchiveOptions Type#

Limits applied while unpacking untrusted archive data. A field left as null sets no limit.

Manuscript
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.

Manuscript
max_bytes Int? = null

ArchiveOptions.max_entries#

Maximum unpacked entries, including directories.

Manuscript
max_entries Int? = null

ArchiveOptions.max_entry_bytes#

Maximum unpacked bytes for each entry; zero admits only empty data.

Manuscript
max_entry_bytes Int? = null

CompressOptions Type#

Settings for compress: the DEFLATE level (0 to 9, default 6) and an optional limit on the encoded output bytes.

Manuscript
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.

Manuscript
level Int = 6

CompressOptions.max_bytes#

Maximum encoded bytes; null sets no limit.

Manuscript
max_bytes Int? = null

CompressionFormat Enum#

A compression format. Deflate is raw DEFLATE without a wrapper.

Manuscript
enum CompressionFormat {
    Gzip
    Zlib
    Deflate
}

CompressionFormat.Deflate#

Raw DEFLATE without framing.

Manuscript
Deflate

CompressionFormat.Gzip#

DEFLATE data wrapped in GZIP headers and a checksum trailer.

Manuscript
Gzip

CompressionFormat.Zlib#

DEFLATE data with ZLIB header and Adler-32 checksum framing.

Manuscript
Zlib

compress Function#

Compresses data as format. When options.max_bytes is supplied, it bounds the encoded output.

Manuscript
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.

Manuscript
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.

Manuscript
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.

Manuscript
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.

Manuscript
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.

Manuscript
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.

Manuscript
fn unpack(data Bytes, format ArchiveFormat, options ArchiveOptions = ArchiveOptions()) Result[List[ArchiveEntry], Error] { ... }