You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DateKeys-App/scripts/zip-ts-samples.mjs

27 lines
1.2 KiB

Format 3, step 5: the ZIP sink of the page, which archive/zip reads zipsink.ts is the sink of the page for a format 3 capsule (design of format 3, section 5). Its files go to the temporary file of OPFS: the file itself when the capsule holds one file of one segment, and otherwise a ZIP of stored entries laid out from the head before any byte arrives. Each local header is written at its offset, the bytes of the file follow as open delivers them, the CRC-32 of the entry is patched in its header with a positioned write, and commit writes the central directory and closes the file; abort discards it, also when the opening failed before begin. Each file is a contiguous range of the file written (ranges), and zipOf makes the same ZIP in memory as a Blob of its parts. tempfile.ts: the writable of a temporary file takes TempChunk, bytes at the position of the file or at a given one, as FileSystemWritableFileStream does; cancellable is generic. Interoperability: scripts/zip-ts-samples.mjs writes the samples of testing/zip.ts with ZipSink, and scripts/zip-go-read.go reads them with archive/zip of the Go standard library: names out of ASCII with bit 11, stored entries, their CRC-32 and sizes, the times of the extra fields in 1970, at 2^31 - 1 and after it, in 9999 and the time of the round for a file without one, and 65535 entries, ZIP64 by their number. The reading is frozen in testing/zip-vectors.json, and zipsink.test.ts writes each sample again, requires its SHA-256 and computes the entries Go must have read. zipsink.ts is covered at 100 %. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 week ago
#!/usr/bin/env node
// Writes the ZIP samples of the page (src/lib/dkc/testing/zip.ts), as the
// ZipSink of src/lib/inspector/zipsink.ts writes them, into a directory for
// scripts/zip-go-read.go, and prints their index as JSON: the name, the file
// and the SHA-256 of each. The samples are deterministic: zipsink.test.ts
// writes them again and requires the same SHA-256. Node runs the TypeScript
// sources directly (type stripping, Node 22.6+):
//
// node scripts/zip-ts-samples.mjs DIR > zip-samples.json
import { mkdirSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { sha256, toHex } from '../src/lib/dkc/bytes.ts';
import { writeZip, zipSamples } from '../src/lib/dkc/testing/zip.ts';
const dir = process.argv[2];
if (dir === undefined) throw new Error('usage: node scripts/zip-ts-samples.mjs DIR');
mkdirSync(dir, { recursive: true });
const samples = [];
for (const [i, s] of zipSamples().entries()) {
const { bytes } = await writeZip(s);
const file = `${i}.zip`;
writeFileSync(join(dir, file), bytes);
samples.push({ name: s.name, file, sha256: toHex(await sha256(bytes)) });
}
process.stdout.write(`${JSON.stringify({ generator: 'scripts/zip-ts-samples.mjs', samples }, null, 1)}\n`);

Powered by TurnKey Linux.