Français
pack
L'empaquetage déterministe : les mêmes fichiers donnent toujours la même archive et la même empreinte d'arbre, le source.sha256 d'un chart.
Les signatures et leurs descriptions sont en anglais, comme le code.
Exemple
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);Lance-le depuis un dossier où le paquet est installé : node example.mjs.
Sortie
text
README.md, chart.json
tree: true
same archive twice: trueFonctions
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.
Depuis @altasystem/sdk/node (lit le disque).
packDir
ts
function packDir(dir: string): PackedPacks a folder: deterministic archive, its sha256 and the tree digest (alta.tree/1).
Depuis @altasystem/sdk/node (lit le disque).