Corbie

Plugins

compress

This plugin compresses data with gzip, and makes and reads archives.

compress.gzip(data, { as })the data, compressed compress.gunzip(data, { as })the data, decompressed compress.list(archive)the files: [{ name, size }], size in bytes uncompressed compress.read(archive, { entry, as })the contents of one file compress.archive(files, { format, as })an archive of the files

data, an archive and a file's contents are text, bytes or a blob. files maps each file's name to its contents. An archive is a zip, a tar or a gzipped tar, detected from its first bytes.

Options:

as"bytes", "text", "json" or "blob"; default "bytes" entrythe name of the file to read; required format"zip", "tar" or "tar.gz"; default "zip"

Only files are entries: directories and links are skipped. One file of a zip is read without reading the rest. A result that is not a blob is at most 64 MiB (blobs).

Errors:

bad_inputdata that is not gzip, an archive that cannot be read, an entry's name that starts with / or contains .., or a result over 64 MiB that is not a blob not_foundcompress.read: the archive has no file of that name

Needs nothing.

This script compresses text and decompresses it.

const packed = compress.gzip("hello")
compress.gunzip(packed, { as: "text" })                       // gives "hello"

This script makes a zip, lists it and reads one file.

const zip = compress.archive({ "a.txt": "one", "notes/b.txt": "two" })
compress.list(zip)                                            // gives [{ name: "a.txt", size: 3 }, { name: "notes/b.txt", size: 3 }]
compress.read(zip, { entry: "notes/b.txt", as: "text" })      // gives "two"