···1+# PLC Bundle V1 TypeScript Reference Implementation
2+3+This script is a compact, readable reference implementation for creating PLC Bundle v1 archives. It fetches operations from the PLC directory and generates a complete, verifiable repository of data bundles.
4+5+It is fully compliant with the [PLC Bundle v1 Specification](https://github.com/atscan/plcbundle/blob/main/SPECIFICATION.md).
6+7+## Features
8+9+- **Spec Compliant:** Correctly implements hashing, chaining, serialization, and boundary de-duplication.
10+- **Reproducible:** Generates byte-for-byte identical bundles to the official Go implementation.
11+- **Efficient:** Uses a memory-efficient method to handle duplicates between bundle boundaries.
12+- **Standalone:** Single-file script with clear dependencies.
13+14+## Usage
15+16+This script can be run with **Bun (recommended)**, Deno, or Node.js.
17+18+The script accepts one optional argument: the path to the output directory where bundles will be stored. If omitted, it defaults to `./plc_bundles`.
19+20+### Bun (Recommended)
21+22+Bun is the fastest and easiest way to run this script, as it handles TypeScript and dependencies automatically.
23+24+```sh
25+# Install dependencies
26+bun install
27+28+# Run the script to create bundles in ./my_plc_bundles
29+bun run plcbundle.ts ./my_plc_bundles
30+```
31+32+### Deno
33+34+Deno can also run the script directly. You will need to provide permissions for network access and file system I/O.
35+36+```sh
37+# Run the script with Deno
38+deno run --allow-net --allow-read --allow-write plcbundle.ts ./my_plc_bundles
39+```
40+41+### Node.js (with TypeScript)
42+43+If using Node.js, you must first install dependencies and compile the TypeScript file to JavaScript.
44+45+```sh
46+# Install dependencies
47+npm install
48+49+# Compile the script
50+npx tsc
51+52+# Run the compiled JavaScript
53+node dist/plcbundle.js ./my_plc_bundles
54+```
55+
+6-5
plcbundle.ts
···1-#!/usr/bin/env node
2-3/**
4 * plcbundle.ts - A compact, readable reference implementation for creating
5 * plcbundle V1 compliant archives. This script demonstrates all critical spec
6 * requirements, including hashing, serialization, ordering, and boundary handling.
0007 */
89-import fs from 'fs/promises';
10-import path from 'path';
11-import crypto from 'crypto';
12import { init, compress, decompress } from '@bokuweb/zstd-wasm';
13import axios from 'axios';
14
···001/**
2 * plcbundle.ts - A compact, readable reference implementation for creating
3 * plcbundle V1 compliant archives. This script demonstrates all critical spec
4 * requirements, including hashing, serialization, ordering, and boundary handling.
5+ *
6+ * PLC Bundle v1 Specification:
7+ * https://github.com/atscan/plcbundle/blob/main/SPECIFICATION.md
8 */
910+import fs from 'node:fs/promises';
11+import path from 'node:path';
12+import crypto from 'node:crypto';
13import { init, compress, decompress } from '@bokuweb/zstd-wasm';
14import axios from 'axios';
15