···11+# PLC Bundle V1 TypeScript Reference Implementation
22+33+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.
44+55+It is fully compliant with the [PLC Bundle v1 Specification](https://github.com/atscan/plcbundle/blob/main/SPECIFICATION.md).
66+77+## Features
88+99+- **Spec Compliant:** Correctly implements hashing, chaining, serialization, and boundary de-duplication.
1010+- **Reproducible:** Generates byte-for-byte identical bundles to the official Go implementation.
1111+- **Efficient:** Uses a memory-efficient method to handle duplicates between bundle boundaries.
1212+- **Standalone:** Single-file script with clear dependencies.
1313+1414+## Usage
1515+1616+This script can be run with **Bun (recommended)**, Deno, or Node.js.
1717+1818+The script accepts one optional argument: the path to the output directory where bundles will be stored. If omitted, it defaults to `./plc_bundles`.
1919+2020+### Bun (Recommended)
2121+2222+Bun is the fastest and easiest way to run this script, as it handles TypeScript and dependencies automatically.
2323+2424+```sh
2525+# Install dependencies
2626+bun install
2727+2828+# Run the script to create bundles in ./my_plc_bundles
2929+bun run plcbundle.ts ./my_plc_bundles
3030+```
3131+3232+### Deno
3333+3434+Deno can also run the script directly. You will need to provide permissions for network access and file system I/O.
3535+3636+```sh
3737+# Run the script with Deno
3838+deno run --allow-net --allow-read --allow-write plcbundle.ts ./my_plc_bundles
3939+```
4040+4141+### Node.js (with TypeScript)
4242+4343+If using Node.js, you must first install dependencies and compile the TypeScript file to JavaScript.
4444+4545+```sh
4646+# Install dependencies
4747+npm install
4848+4949+# Compile the script
5050+npx tsc
5151+5252+# Run the compiled JavaScript
5353+node dist/plcbundle.js ./my_plc_bundles
5454+```
5555+
+6-5
plcbundle.ts
···11-#!/usr/bin/env node
22-31/**
42 * plcbundle.ts - A compact, readable reference implementation for creating
53 * plcbundle V1 compliant archives. This script demonstrates all critical spec
64 * requirements, including hashing, serialization, ordering, and boundary handling.
55+ *
66+ * PLC Bundle v1 Specification:
77+ * https://github.com/atscan/plcbundle/blob/main/SPECIFICATION.md
78 */
8999-import fs from 'fs/promises';
1010-import path from 'path';
1111-import crypto from 'crypto';
1010+import fs from 'node:fs/promises';
1111+import path from 'node:path';
1212+import crypto from 'node:crypto';
1213import { init, compress, decompress } from '@bokuweb/zstd-wasm';
1314import axios from 'axios';
1415