NAME
std/archive - Small archive and compression helpers.
SYNOPSIS
from std/archive import Archive;
from std/io import Path;
let archive := {
entries: [
{ path: "hello.txt", data: to_binary( "Hello\n" ) },
{ path: "nested/world.txt", data: to_binary( "World\n" ) },
],
};
let bytes := Archive.encode( archive, "tar.gz" );
let roundtrip := Archive.decode(bytes);
let path := Path.tempdir().child("hello.zip");
Archive.dump( path, archive );
let loaded := Archive.load(path);
IMPLEMENTATION SUPPORT
This module is supported by zuzu.pl, zuzu-rust, and zuzu-js on Node and Electron. It is not supported by zuzu-js in the browser.
DESCRIPTION
This module provides a small, runtime-supported archive API centred on one exported class, Archive.
EXPORTS
Classes
ArchiveRuntime-supported archive namespace class.
Archive.decode(BinaryString bytes, String format?)Parameters:
bytesis archive or compressed data andformatis an optional format name. Returns:Dict. Decodesbytesinto an archive value.Archive.encode(Dict archive, String format?)Parameters:
archiveis an archive value andformatis an optional format name. Returns:BinaryString. Encodesarchiveinto archive or compressed data.Archive.load(Path path, String format?)Parameters:
pathis astd/ioPathandformatis an optional format name. Returns:Dict. Reads and decodes an archive file.Archive.dump(Path path, Dict archive, String format?)Parameters:
pathis astd/ioPath,archiveis an archive value, andformatis an optional format name. Returns:null. Encodes and writes an archive file.
Archive values use this shape:
{
format: "zip",
entries: [
{ path: "hello.txt", data: BinaryString },
{ path: "nested/world.txt", data: BinaryString },
],
}
Only regular file payloads are preserved in this API. Directory entries and extended archive metadata are ignored so the interface remains practical to port to other backends later.
When constructing archives for encode or dump, each entry may provide either:
dataas aBinaryStringdata_fromas astd/io::Path
For single-stream compression formats such as gz and bz2, entries contains exactly one file entry.
SUPPORTED FORMATS
Host runtimes may support:
ziptartar.gzandtgztar.bz2andtbz2gzbz2
This module is intended for host runtimes with archive and compression support. Browser runtimes should not be assumed to support it.
COPYRIGHT AND LICENCE
std/archive is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.