English
pack
Deterministic packing: the same files always give the same archive and the same tree digest, the source.sha256 of a chart.
Example
example.mjs
js
// Pack files into a deterministic archive: the same files always give the same digests.
import { pack, treeDigest } from "@altasystem/sdk";
const files = [
{ path: "chart.json", bytes: new TextEncoder().encode('{ "schema": "alta.chart/0.1" }\n') },
{ path: "README.md", bytes: new TextEncoder().encode("# My chart\n") },
];
const packed = pack(files);
console.log(packed.files.map(f => f.path).join(", "));
console.log("tree:", packed.tree === treeDigest(files));
console.log("same archive twice:", pack(files).sha256 === packed.sha256);Run it from a folder where the package is installed: node example.mjs.
Output
text
README.md, chart.json
tree: true
same archive twice: trueFunctions
pack
ts
function pack(input: PackFile[]): PackedPacks files into a deterministic tar, with both digests. Throws on a bad path (see checkPackFiles).
treeDigest
ts
function treeDigest(files: PackFile[]): stringThe tree digest (alta.tree/1) of files.
unpack
ts
function unpack(archive: Uint8Array): PackFile[]Reads back the files of an archive made by pack (used by tests and by alta dev on an archive).
sha256
ts
function sha256(input: Uint8Array | string): stringThe sha256 of bytes (or of a string, as UTF-8), in lower-case hex.
checkPackFiles
ts
function checkPackFiles(files: PackFile[]): string[]Problems of a list of files to pack (empty = it can be packed).
readTree
ts
function readTree(dir: string): PackFile[]Every file under dir, with posix paths relative to it, without what pack leaves out.
From @altasystem/sdk/node (reads the disk).
packDir
ts
function packDir(dir: string): PackedPacks a folder: deterministic archive, its sha256 and the tree digest (alta.tree/1).
From @altasystem/sdk/node (reads the disk).