compress-utils 0.7.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +144 -0
- package/dist/algorithms/brotli/brotli.wasm +0 -0
- package/dist/algorithms/brotli/index.d.ts +12 -0
- package/dist/algorithms/brotli/index.d.ts.map +1 -0
- package/dist/algorithms/brotli/index.js +17 -0
- package/dist/algorithms/brotli/index.js.map +1 -0
- package/dist/algorithms/bz2/bz2.wasm +0 -0
- package/dist/algorithms/bz2/index.d.ts +12 -0
- package/dist/algorithms/bz2/index.d.ts.map +1 -0
- package/dist/algorithms/bz2/index.js +17 -0
- package/dist/algorithms/bz2/index.js.map +1 -0
- package/dist/algorithms/lz4/index.d.ts +12 -0
- package/dist/algorithms/lz4/index.d.ts.map +1 -0
- package/dist/algorithms/lz4/index.js +17 -0
- package/dist/algorithms/lz4/index.js.map +1 -0
- package/dist/algorithms/lz4/lz4.wasm +0 -0
- package/dist/algorithms/xz/index.d.ts +12 -0
- package/dist/algorithms/xz/index.d.ts.map +1 -0
- package/dist/algorithms/xz/index.js +17 -0
- package/dist/algorithms/xz/index.js.map +1 -0
- package/dist/algorithms/xz/xz.wasm +0 -0
- package/dist/algorithms/zlib/index.d.ts +12 -0
- package/dist/algorithms/zlib/index.d.ts.map +1 -0
- package/dist/algorithms/zlib/index.js +17 -0
- package/dist/algorithms/zlib/index.js.map +1 -0
- package/dist/algorithms/zlib/zlib.wasm +0 -0
- package/dist/algorithms/zstd/index.d.ts +12 -0
- package/dist/algorithms/zstd/index.d.ts.map +1 -0
- package/dist/algorithms/zstd/index.js +17 -0
- package/dist/algorithms/zstd/index.js.map +1 -0
- package/dist/algorithms/zstd/zstd.wasm +0 -0
- package/dist/core/algorithm.d.ts +17 -0
- package/dist/core/algorithm.d.ts.map +1 -0
- package/dist/core/algorithm.js +19 -0
- package/dist/core/algorithm.js.map +1 -0
- package/dist/core/dispatch.d.ts +83 -0
- package/dist/core/dispatch.d.ts.map +1 -0
- package/dist/core/dispatch.js +370 -0
- package/dist/core/dispatch.js.map +1 -0
- package/dist/core/loader.d.ts +47 -0
- package/dist/core/loader.d.ts.map +1 -0
- package/dist/core/loader.js +121 -0
- package/dist/core/loader.js.map +1 -0
- package/dist/core/resolve-browser.d.ts +12 -0
- package/dist/core/resolve-browser.d.ts.map +1 -0
- package/dist/core/resolve-browser.js +11 -0
- package/dist/core/resolve-browser.js.map +1 -0
- package/dist/core/resolve-default.d.ts +11 -0
- package/dist/core/resolve-default.d.ts.map +1 -0
- package/dist/core/resolve-default.js +27 -0
- package/dist/core/resolve-default.js.map +1 -0
- package/dist/core/resolve-node.d.ts +13 -0
- package/dist/core/resolve-node.d.ts.map +1 -0
- package/dist/core/resolve-node.js +13 -0
- package/dist/core/resolve-node.js.map +1 -0
- package/dist/core/types.d.ts +54 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +47 -0
- package/dist/core/types.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic JS→C ABI dispatcher.
|
|
3
|
+
*
|
|
4
|
+
* Per-algorithm modules (algorithms/<algo>/index.ts) call `createBindings`
|
|
5
|
+
* with their algorithm enum + wasm URL; that factory returns the public
|
|
6
|
+
* surface (compress, decompress, streams, version, etc.) bound to a
|
|
7
|
+
* lazily-instantiated wasm module. The dispatcher itself doesn't ship in
|
|
8
|
+
* any user bundle — only the slice of it the algorithm uses, after
|
|
9
|
+
* tree-shaking.
|
|
10
|
+
*/
|
|
11
|
+
import { checkStatus, decodeCString, loadModule, } from "./loader.js";
|
|
12
|
+
import { CompressError, Status, } from "./types.js";
|
|
13
|
+
const DEFAULT_LEVEL = 5;
|
|
14
|
+
const STREAM_DRAIN_CHUNK = 64 * 1024;
|
|
15
|
+
/* Safety cap on drain() iterations. A correct codec returns Ok within a
|
|
16
|
+
* few iterations per write — anything past this many BUF_TOO_SMALL retries
|
|
17
|
+
* means the C side is stuck in a state where it neither emits output nor
|
|
18
|
+
* signals completion. Throw rather than spin forever. */
|
|
19
|
+
const DRAIN_MAX_ITERATIONS = 1 << 16;
|
|
20
|
+
/** Tracks allocations so a single try/finally can free them all. */
|
|
21
|
+
class Arena {
|
|
22
|
+
exports;
|
|
23
|
+
ptrs = [];
|
|
24
|
+
constructor(exports) { this.exports = exports; }
|
|
25
|
+
alloc(bytes, algoName) {
|
|
26
|
+
// Empty-input compress/decompress is a valid edge case (codecs
|
|
27
|
+
// produce a non-empty header/footer for an empty payload). Bump
|
|
28
|
+
// zero-byte requests to 1 so cu_alloc returns a real pointer
|
|
29
|
+
// backing zero useful bytes — passing the resulting (ptr, 0) to
|
|
30
|
+
// the C ABI is well-defined; passing (NULL, 0) is not.
|
|
31
|
+
if (bytes === 0)
|
|
32
|
+
bytes = 1;
|
|
33
|
+
const ptr = this.exports.cu_alloc(bytes);
|
|
34
|
+
if (ptr === 0) {
|
|
35
|
+
throw new CompressError(Status.Oom, algoName, `cu_alloc(${bytes}) returned NULL`);
|
|
36
|
+
}
|
|
37
|
+
this.ptrs.push(ptr);
|
|
38
|
+
return ptr;
|
|
39
|
+
}
|
|
40
|
+
freeAll() {
|
|
41
|
+
for (const p of this.ptrs)
|
|
42
|
+
this.exports.cu_free(p);
|
|
43
|
+
this.ptrs.length = 0;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export class Dispatcher {
|
|
47
|
+
algorithm;
|
|
48
|
+
algorithmName;
|
|
49
|
+
/** @internal */ exports;
|
|
50
|
+
constructor(exports, algorithm, algorithmName) {
|
|
51
|
+
this.exports = exports;
|
|
52
|
+
this.algorithm = algorithm;
|
|
53
|
+
this.algorithmName = algorithmName;
|
|
54
|
+
if (exports.cu_algorithm_available(algorithm) === 0) {
|
|
55
|
+
throw new CompressError(Status.UnsupportedAlgo, algorithmName, `algorithm "${algorithmName}" not compiled into this .wasm module`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
version() {
|
|
59
|
+
return decodeCString(this.exports.memory, this.exports.cu_version());
|
|
60
|
+
}
|
|
61
|
+
setMaxDecompressedSize(bytes) {
|
|
62
|
+
this.exports.cu_set_max_decompressed_size?.(bytes);
|
|
63
|
+
}
|
|
64
|
+
/* ---------- one-shot ---------- */
|
|
65
|
+
compress(input, opts = {}) {
|
|
66
|
+
const level = opts.level ?? DEFAULT_LEVEL;
|
|
67
|
+
const inLen = input.byteLength;
|
|
68
|
+
const bound = this.exports.cu_compress_bound(inLen, this.algorithm);
|
|
69
|
+
const arena = new Arena(this.exports);
|
|
70
|
+
try {
|
|
71
|
+
const inPtr = arena.alloc(inLen, this.algorithmName);
|
|
72
|
+
const outPtr = arena.alloc(bound, this.algorithmName);
|
|
73
|
+
const outLenPtr = arena.alloc(4, this.algorithmName);
|
|
74
|
+
this.writeBytes(inPtr, input);
|
|
75
|
+
this.writeU32(outLenPtr, bound);
|
|
76
|
+
const status = this.exports.cu_compress(this.algorithm, inPtr, inLen, outPtr, outLenPtr, level);
|
|
77
|
+
checkStatus(this.exports, status, this.algorithmName);
|
|
78
|
+
return this.readBytes(outPtr, this.readU32(outLenPtr));
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
arena.freeAll();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
decompress(input, opts = {}) {
|
|
85
|
+
const inLen = input.byteLength;
|
|
86
|
+
const arena = new Arena(this.exports);
|
|
87
|
+
try {
|
|
88
|
+
const inPtr = arena.alloc(inLen, this.algorithmName);
|
|
89
|
+
this.writeBytes(inPtr, input);
|
|
90
|
+
const outSize = opts.expectedSize ?? this.tryProbeSize(arena, inPtr, inLen);
|
|
91
|
+
if (outSize === undefined) {
|
|
92
|
+
// Wire format doesn't carry size (bz2, brotli, raw deflate,
|
|
93
|
+
// raw LZ4, current xz size_hint impl). Fall through to a
|
|
94
|
+
// streaming decode so the one-shot API still works.
|
|
95
|
+
return this.decompressStreaming(input);
|
|
96
|
+
}
|
|
97
|
+
const outPtr = arena.alloc(outSize, this.algorithmName);
|
|
98
|
+
const outLenPtr = arena.alloc(4, this.algorithmName);
|
|
99
|
+
this.writeU32(outLenPtr, outSize);
|
|
100
|
+
const status = this.exports.cu_decompress(this.algorithm, inPtr, inLen, outPtr, outLenPtr);
|
|
101
|
+
checkStatus(this.exports, status, this.algorithmName);
|
|
102
|
+
return this.readBytes(outPtr, this.readU32(outLenPtr));
|
|
103
|
+
}
|
|
104
|
+
finally {
|
|
105
|
+
arena.freeAll();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
decompressStreaming(input) {
|
|
109
|
+
const stream = this.createDecompressStream();
|
|
110
|
+
try {
|
|
111
|
+
const body = stream.write(input);
|
|
112
|
+
const tail = stream.finish();
|
|
113
|
+
if (tail.byteLength === 0)
|
|
114
|
+
return body;
|
|
115
|
+
const out = new Uint8Array(body.byteLength + tail.byteLength);
|
|
116
|
+
out.set(body, 0);
|
|
117
|
+
out.set(tail, body.byteLength);
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
stream.destroy();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
tryProbeSize(arena, inPtr, inLen) {
|
|
125
|
+
const sizePtr = arena.alloc(4, this.algorithmName);
|
|
126
|
+
this.writeU32(sizePtr, 0);
|
|
127
|
+
const status = this.exports.cu_decompress_size_hint(this.algorithm, inPtr, inLen, sizePtr);
|
|
128
|
+
if (status === Status.Ok)
|
|
129
|
+
return this.readU32(sizePtr);
|
|
130
|
+
if (status === Status.SizeUnknown)
|
|
131
|
+
return undefined;
|
|
132
|
+
checkStatus(this.exports, status, this.algorithmName);
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
/* ---------- streaming ---------- */
|
|
136
|
+
createCompressStream(opts = {}) {
|
|
137
|
+
const level = opts.level ?? DEFAULT_LEVEL;
|
|
138
|
+
const arena = new Arena(this.exports);
|
|
139
|
+
try {
|
|
140
|
+
const streamPP = arena.alloc(4, this.algorithmName);
|
|
141
|
+
this.writeU32(streamPP, 0);
|
|
142
|
+
const status = this.exports.cu_compress_stream_create(this.algorithm, level, streamPP);
|
|
143
|
+
checkStatus(this.exports, status, this.algorithmName);
|
|
144
|
+
return new CompressStream(this, this.readU32(streamPP));
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
arena.freeAll();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
createDecompressStream() {
|
|
151
|
+
const arena = new Arena(this.exports);
|
|
152
|
+
try {
|
|
153
|
+
const streamPP = arena.alloc(4, this.algorithmName);
|
|
154
|
+
this.writeU32(streamPP, 0);
|
|
155
|
+
const status = this.exports.cu_decompress_stream_create(this.algorithm, streamPP);
|
|
156
|
+
checkStatus(this.exports, status, this.algorithmName);
|
|
157
|
+
return new DecompressStream(this, this.readU32(streamPP));
|
|
158
|
+
}
|
|
159
|
+
finally {
|
|
160
|
+
arena.freeAll();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/* ---------- internal helpers (used by stream classes) ---------- */
|
|
164
|
+
/** @internal */ writeBytes(ptr, src) {
|
|
165
|
+
new Uint8Array(this.exports.memory.buffer, ptr, src.byteLength).set(src);
|
|
166
|
+
}
|
|
167
|
+
/** @internal */ readBytes(ptr, len) {
|
|
168
|
+
return new Uint8Array(new Uint8Array(this.exports.memory.buffer, ptr, len));
|
|
169
|
+
}
|
|
170
|
+
/** @internal */ writeU32(ptr, value) {
|
|
171
|
+
new DataView(this.exports.memory.buffer).setUint32(ptr, value, true);
|
|
172
|
+
}
|
|
173
|
+
/** @internal */ readU32(ptr) {
|
|
174
|
+
return new DataView(this.exports.memory.buffer).getUint32(ptr, true);
|
|
175
|
+
}
|
|
176
|
+
/** @internal */ newArena() { return new Arena(this.exports); }
|
|
177
|
+
}
|
|
178
|
+
const streamFinalizer = new FinalizationRegistry((c) => {
|
|
179
|
+
if (c.handle !== 0)
|
|
180
|
+
c.destroy(c.handle);
|
|
181
|
+
});
|
|
182
|
+
class StreamBase {
|
|
183
|
+
dispatcher;
|
|
184
|
+
handle;
|
|
185
|
+
finished = false;
|
|
186
|
+
cleanup;
|
|
187
|
+
constructor(dispatcher, handle, destroyFn) {
|
|
188
|
+
this.dispatcher = dispatcher;
|
|
189
|
+
this.handle = handle;
|
|
190
|
+
this.cleanup = { destroy: destroyFn, handle };
|
|
191
|
+
streamFinalizer.register(this, this.cleanup, this);
|
|
192
|
+
}
|
|
193
|
+
ensureLive() {
|
|
194
|
+
if (this.handle === 0) {
|
|
195
|
+
throw new CompressError(Status.StreamState, this.dispatcher.algorithmName, "stream has been destroyed");
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
destroy() {
|
|
199
|
+
if (this.handle !== 0) {
|
|
200
|
+
this.cleanup.destroy(this.handle);
|
|
201
|
+
this.handle = 0;
|
|
202
|
+
this.cleanup.handle = 0;
|
|
203
|
+
streamFinalizer.unregister(this);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** Symbol.dispose — enables `using stream = await create*()`. */
|
|
207
|
+
[Symbol.dispose]() { this.destroy(); }
|
|
208
|
+
}
|
|
209
|
+
export class CompressStream extends StreamBase {
|
|
210
|
+
constructor(dispatcher, handle) {
|
|
211
|
+
super(dispatcher, handle, (h) => dispatcher.exports.cu_compress_stream_destroy(h));
|
|
212
|
+
}
|
|
213
|
+
write(chunk) {
|
|
214
|
+
this.ensureLive();
|
|
215
|
+
if (this.finished) {
|
|
216
|
+
throw new CompressError(Status.StreamFinished, this.dispatcher.algorithmName, "write after finish");
|
|
217
|
+
}
|
|
218
|
+
return drain(this.dispatcher, chunk, (inPtr, inLen, outPtr, outLenPtr) => this.dispatcher.exports.cu_compress_stream_write(this.handle, inPtr, inLen, outPtr, outLenPtr));
|
|
219
|
+
}
|
|
220
|
+
finish() {
|
|
221
|
+
this.ensureLive();
|
|
222
|
+
this.finished = true;
|
|
223
|
+
return drain(this.dispatcher, null, (_in, _len, outPtr, outLenPtr) => this.dispatcher.exports.cu_compress_stream_finish(this.handle, outPtr, outLenPtr));
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export class DecompressStream extends StreamBase {
|
|
227
|
+
constructor(dispatcher, handle) {
|
|
228
|
+
super(dispatcher, handle, (h) => dispatcher.exports.cu_decompress_stream_destroy(h));
|
|
229
|
+
}
|
|
230
|
+
write(chunk) {
|
|
231
|
+
this.ensureLive();
|
|
232
|
+
return drain(this.dispatcher, chunk, (inPtr, inLen, outPtr, outLenPtr) => this.dispatcher.exports.cu_decompress_stream_write(this.handle, inPtr, inLen, outPtr, outLenPtr));
|
|
233
|
+
}
|
|
234
|
+
finish() {
|
|
235
|
+
this.ensureLive();
|
|
236
|
+
this.finished = true;
|
|
237
|
+
return drain(this.dispatcher, null, (_in, _len, outPtr, outLenPtr) => this.dispatcher.exports.cu_decompress_stream_finish(this.handle, outPtr, outLenPtr));
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Drain protocol: repeat the call until it returns Ok with no overflow.
|
|
242
|
+
* BUF_TOO_SMALL means the stream has more output buffered; the C side
|
|
243
|
+
* remembers any unconsumed input, so on retry we pass (NULL, 0).
|
|
244
|
+
*/
|
|
245
|
+
function drain(dispatcher, input, call) {
|
|
246
|
+
const arena = dispatcher.newArena();
|
|
247
|
+
const chunks = [];
|
|
248
|
+
let total = 0;
|
|
249
|
+
try {
|
|
250
|
+
const inLen = input?.byteLength ?? 0;
|
|
251
|
+
const inPtr0 = inLen > 0 ? arena.alloc(inLen, dispatcher.algorithmName) : 0;
|
|
252
|
+
if (inPtr0 !== 0 && input)
|
|
253
|
+
dispatcher.writeBytes(inPtr0, input);
|
|
254
|
+
const outPtr = arena.alloc(STREAM_DRAIN_CHUNK, dispatcher.algorithmName);
|
|
255
|
+
const outLenPtr = arena.alloc(4, dispatcher.algorithmName);
|
|
256
|
+
let inPtr = inPtr0;
|
|
257
|
+
let remainingIn = inLen;
|
|
258
|
+
for (let i = 0;; i++) {
|
|
259
|
+
if (i >= DRAIN_MAX_ITERATIONS) {
|
|
260
|
+
throw new CompressError(Status.StreamState, dispatcher.algorithmName, `drain exceeded ${DRAIN_MAX_ITERATIONS} iterations without completion`);
|
|
261
|
+
}
|
|
262
|
+
dispatcher.writeU32(outLenPtr, STREAM_DRAIN_CHUNK);
|
|
263
|
+
const status = call(inPtr, remainingIn, outPtr, outLenPtr);
|
|
264
|
+
const produced = dispatcher.readU32(outLenPtr);
|
|
265
|
+
if (produced > 0) {
|
|
266
|
+
chunks.push(dispatcher.readBytes(outPtr, produced));
|
|
267
|
+
total += produced;
|
|
268
|
+
}
|
|
269
|
+
if (status === Status.Ok)
|
|
270
|
+
break;
|
|
271
|
+
if (status !== Status.BufTooSmall) {
|
|
272
|
+
checkStatus(dispatcher.exports, status, dispatcher.algorithmName);
|
|
273
|
+
}
|
|
274
|
+
inPtr = 0;
|
|
275
|
+
remainingIn = 0;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
finally {
|
|
279
|
+
arena.freeAll();
|
|
280
|
+
}
|
|
281
|
+
if (chunks.length === 1)
|
|
282
|
+
return chunks[0];
|
|
283
|
+
const merged = new Uint8Array(total);
|
|
284
|
+
let off = 0;
|
|
285
|
+
for (const c of chunks) {
|
|
286
|
+
merged.set(c, off);
|
|
287
|
+
off += c.byteLength;
|
|
288
|
+
}
|
|
289
|
+
return merged;
|
|
290
|
+
}
|
|
291
|
+
export function createBindings(algorithm, name, wasmUrl, resolveWasm) {
|
|
292
|
+
let dispatcherPromise = null;
|
|
293
|
+
const getDispatcher = () => {
|
|
294
|
+
if (!dispatcherPromise) {
|
|
295
|
+
dispatcherPromise = (async () => {
|
|
296
|
+
const source = await resolveWasm(wasmUrl);
|
|
297
|
+
const exports = await loadModule(source);
|
|
298
|
+
return new Dispatcher(exports, algorithm, name);
|
|
299
|
+
})();
|
|
300
|
+
}
|
|
301
|
+
return dispatcherPromise;
|
|
302
|
+
};
|
|
303
|
+
return {
|
|
304
|
+
async compress(input, opts) {
|
|
305
|
+
return (await getDispatcher()).compress(input, opts);
|
|
306
|
+
},
|
|
307
|
+
async decompress(input, opts) {
|
|
308
|
+
return (await getDispatcher()).decompress(input, opts);
|
|
309
|
+
},
|
|
310
|
+
async createCompressStream(opts) {
|
|
311
|
+
return (await getDispatcher()).createCompressStream(opts);
|
|
312
|
+
},
|
|
313
|
+
async createDecompressStream() {
|
|
314
|
+
return (await getDispatcher()).createDecompressStream();
|
|
315
|
+
},
|
|
316
|
+
compressionStream(opts) {
|
|
317
|
+
let stream;
|
|
318
|
+
return new TransformStream({
|
|
319
|
+
async start() {
|
|
320
|
+
stream = (await getDispatcher()).createCompressStream(opts);
|
|
321
|
+
},
|
|
322
|
+
transform(chunk, controller) {
|
|
323
|
+
const out = stream.write(chunk);
|
|
324
|
+
if (out.byteLength > 0)
|
|
325
|
+
controller.enqueue(out);
|
|
326
|
+
},
|
|
327
|
+
flush(controller) {
|
|
328
|
+
try {
|
|
329
|
+
const tail = stream.finish();
|
|
330
|
+
if (tail.byteLength > 0)
|
|
331
|
+
controller.enqueue(tail);
|
|
332
|
+
}
|
|
333
|
+
finally {
|
|
334
|
+
stream.destroy();
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
});
|
|
338
|
+
},
|
|
339
|
+
decompressionStream() {
|
|
340
|
+
let stream;
|
|
341
|
+
return new TransformStream({
|
|
342
|
+
async start() {
|
|
343
|
+
stream = (await getDispatcher()).createDecompressStream();
|
|
344
|
+
},
|
|
345
|
+
transform(chunk, controller) {
|
|
346
|
+
const out = stream.write(chunk);
|
|
347
|
+
if (out.byteLength > 0)
|
|
348
|
+
controller.enqueue(out);
|
|
349
|
+
},
|
|
350
|
+
flush(controller) {
|
|
351
|
+
try {
|
|
352
|
+
const tail = stream.finish();
|
|
353
|
+
if (tail.byteLength > 0)
|
|
354
|
+
controller.enqueue(tail);
|
|
355
|
+
}
|
|
356
|
+
finally {
|
|
357
|
+
stream.destroy();
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
},
|
|
362
|
+
async version() {
|
|
363
|
+
return (await getDispatcher()).version();
|
|
364
|
+
},
|
|
365
|
+
async setMaxDecompressedSize(bytes) {
|
|
366
|
+
(await getDispatcher()).setMaxDecompressedSize(bytes);
|
|
367
|
+
},
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=dispatch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatch.js","sourceRoot":"","sources":["../../src/core/dispatch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACH,WAAW,EACX,aAAa,EACb,UAAU,GAEb,MAAM,aAAa,CAAC;AACrB,OAAO,EAEH,aAAa,EACb,MAAM,GAIT,MAAM,YAAY,CAAC;AAEpB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AACrC;;;yDAGyD;AACzD,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,CAAC;AAErC,oEAAoE;AACpE,MAAM,KAAK;IACU,OAAO,CAAc;IACrB,IAAI,GAAa,EAAE,CAAC;IAErC,YAAY,OAAoB,IAAI,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;IAE7D,KAAK,CAAC,KAAa,EAAE,QAAuB;QACxC,+DAA+D;QAC/D,gEAAgE;QAChE,6DAA6D;QAC7D,gEAAgE;QAChE,uDAAuD;QACvD,IAAI,KAAK,KAAK,CAAC;YAAE,KAAK,GAAG,CAAC,CAAC;QAC3B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;YACZ,MAAM,IAAI,aAAa,CACnB,MAAM,CAAC,GAAG,EAAE,QAAQ,EACpB,YAAY,KAAK,iBAAiB,CACrC,C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MAAM,aAAa,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QAC7C,CAAC;QACD,KAAK,CAAC,sBAAsB,CAAC,KAAK;YAC9B,CAAC,MAAM,aAAa,EAAE,CAAC,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;QAC1D,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM module loader + minimal WASI reactor shim.
|
|
3
|
+
*
|
|
4
|
+
* Our .wasm modules are built as `wasm32-wasi -mexec-model=reactor`. This
|
|
5
|
+
* means they (a) export their full ABI under default names, (b) expect a
|
|
6
|
+
* `_initialize` call after instantiation, and (c) import a handful of WASI
|
|
7
|
+
* preview1 functions even though our code paths don't actually use them
|
|
8
|
+
* (libc startup pulls in a few stubs).
|
|
9
|
+
*
|
|
10
|
+
* The shim below implements just enough WASI to keep the imports resolved.
|
|
11
|
+
* Real WASI operations (fd_write, random_get) are stubbed with safe
|
|
12
|
+
* defaults — the codec paths don't hit them in practice, but if a future
|
|
13
|
+
* upstream lib starts logging to stderr we'll see "fd_write: not
|
|
14
|
+
* implemented" instead of a cryptic trap.
|
|
15
|
+
*
|
|
16
|
+
* If we ever need actual WASI (e.g. for `wasi:filesystem`), swap this for
|
|
17
|
+
* @bjorn3/browser_wasi_shim or @cloudflare/workers-types.
|
|
18
|
+
*/
|
|
19
|
+
import { type AlgorithmName } from "./types.js";
|
|
20
|
+
export interface WasmExports {
|
|
21
|
+
readonly memory: WebAssembly.Memory;
|
|
22
|
+
readonly _initialize: () => void;
|
|
23
|
+
readonly cu_alloc: (bytes: number) => number;
|
|
24
|
+
readonly cu_free: (ptr: number) => void;
|
|
25
|
+
readonly cu_version: () => number;
|
|
26
|
+
readonly cu_algorithm_available: (algo: number) => number;
|
|
27
|
+
readonly cu_last_error: () => number;
|
|
28
|
+
readonly cu_strerror: (code: number) => number;
|
|
29
|
+
readonly cu_compress_bound: (in_len: number, algo: number) => number;
|
|
30
|
+
readonly cu_compress: (algo: number, in_ptr: number, in_len: number, out_ptr: number, out_len_ptr: number, level: number) => number;
|
|
31
|
+
readonly cu_decompress: (algo: number, in_ptr: number, in_len: number, out_ptr: number, out_len_ptr: number) => number;
|
|
32
|
+
readonly cu_decompress_size_hint: (algo: number, in_ptr: number, in_len: number, out_size_ptr: number) => number;
|
|
33
|
+
readonly cu_compress_stream_create: (algo: number, level: number, out_stream_pp: number) => number;
|
|
34
|
+
readonly cu_compress_stream_write: (stream: number, in_ptr: number, in_len: number, out_ptr: number, out_len_ptr: number) => number;
|
|
35
|
+
readonly cu_compress_stream_finish: (stream: number, out_ptr: number, out_len_ptr: number) => number;
|
|
36
|
+
readonly cu_compress_stream_destroy: (stream: number) => void;
|
|
37
|
+
readonly cu_decompress_stream_create: (algo: number, out_stream_pp: number) => number;
|
|
38
|
+
readonly cu_decompress_stream_write: (stream: number, in_ptr: number, in_len: number, out_ptr: number, out_len_ptr: number) => number;
|
|
39
|
+
readonly cu_decompress_stream_finish: (stream: number, out_ptr: number, out_len_ptr: number) => number;
|
|
40
|
+
readonly cu_decompress_stream_destroy: (stream: number) => void;
|
|
41
|
+
readonly cu_set_max_decompressed_size?: (bytes: number) => void;
|
|
42
|
+
}
|
|
43
|
+
export declare function loadModule(source: BufferSource | Response | PromiseLike<Response>): Promise<WasmExports>;
|
|
44
|
+
export declare function decodeCString(memory: WebAssembly.Memory, ptr: number, maxLen?: number): string;
|
|
45
|
+
/** Convert a non-Ok status into a thrown CompressError using the C side's message. */
|
|
46
|
+
export declare function checkStatus(exports: WasmExports, status: number, algorithm: AlgorithmName): void;
|
|
47
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/core/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAyB,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC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AACtF,wBAAgB,WAAW,CACvB,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,GAC/D,IAAI,CAMN"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WASM module loader + minimal WASI reactor shim.
|
|
3
|
+
*
|
|
4
|
+
* Our .wasm modules are built as `wasm32-wasi -mexec-model=reactor`. This
|
|
5
|
+
* means they (a) export their full ABI under default names, (b) expect a
|
|
6
|
+
* `_initialize` call after instantiation, and (c) import a handful of WASI
|
|
7
|
+
* preview1 functions even though our code paths don't actually use them
|
|
8
|
+
* (libc startup pulls in a few stubs).
|
|
9
|
+
*
|
|
10
|
+
* The shim below implements just enough WASI to keep the imports resolved.
|
|
11
|
+
* Real WASI operations (fd_write, random_get) are stubbed with safe
|
|
12
|
+
* defaults — the codec paths don't hit them in practice, but if a future
|
|
13
|
+
* upstream lib starts logging to stderr we'll see "fd_write: not
|
|
14
|
+
* implemented" instead of a cryptic trap.
|
|
15
|
+
*
|
|
16
|
+
* If we ever need actual WASI (e.g. for `wasi:filesystem`), swap this for
|
|
17
|
+
* @bjorn3/browser_wasi_shim or @cloudflare/workers-types.
|
|
18
|
+
*/
|
|
19
|
+
import { CompressError, Status } from "./types.js";
|
|
20
|
+
const ERRNO_BADF = 8;
|
|
21
|
+
const ERRNO_IO = 29;
|
|
22
|
+
const ERRNO_NOSYS = 52;
|
|
23
|
+
/* crypto.getRandomValues caps each call at 65536 bytes (per WebCrypto spec).
|
|
24
|
+
* Larger random_get requests get split. We've never seen a codec ask for
|
|
25
|
+
* more than a few bytes, but the loop is cheap insurance. */
|
|
26
|
+
const CRYPTO_MAX_CHUNK = 65536;
|
|
27
|
+
/* Resolved once, lazily: globalThis.crypto is present in browsers, Deno,
|
|
28
|
+
* Bun, and Node ≥19. Node 18 has it behind `node:crypto`'s webcrypto
|
|
29
|
+
* export — we don't try to load that here because our `engines.node` is
|
|
30
|
+
* ≥18 but the test matrix only covers Node 20+. Falling back to `null`
|
|
31
|
+
* makes random_get fail loudly instead of returning all-zeros. */
|
|
32
|
+
const webCrypto = typeof globalThis.crypto !== "undefined" &&
|
|
33
|
+
typeof globalThis.crypto.getRandomValues === "function"
|
|
34
|
+
? globalThis.crypto
|
|
35
|
+
: null;
|
|
36
|
+
function wasiImports(getMemory) {
|
|
37
|
+
return {
|
|
38
|
+
// proc_exit: codec code paths shouldn't call this, but if libc
|
|
39
|
+
// startup hits an unrecoverable error it does. Throw so callers
|
|
40
|
+
// see a real stack instead of a silent exit.
|
|
41
|
+
proc_exit(code) {
|
|
42
|
+
throw new Error(`wasm proc_exit(${code})`);
|
|
43
|
+
},
|
|
44
|
+
// fd_write: silently swallow. zstd/etc don't log; if they did,
|
|
45
|
+
// we'd want to wire this to console.warn — but that needs us to
|
|
46
|
+
// read iovs out of linear memory, which the caller doesn't have
|
|
47
|
+
// a handle to at import-resolution time.
|
|
48
|
+
fd_write() { return ERRNO_NOSYS; },
|
|
49
|
+
fd_close() { return ERRNO_NOSYS; },
|
|
50
|
+
fd_seek() { return ERRNO_NOSYS; },
|
|
51
|
+
fd_read() { return ERRNO_NOSYS; },
|
|
52
|
+
fd_fdstat_get() { return ERRNO_NOSYS; },
|
|
53
|
+
fd_fdstat_set_flags() { return ERRNO_NOSYS; },
|
|
54
|
+
// EBADF terminates the wasi-libc preopen scan cleanly. ENOSYS
|
|
55
|
+
// makes the libc init path think the syscall is implemented but
|
|
56
|
+
// failed unexpectedly, and on some libc builds aborts.
|
|
57
|
+
fd_prestat_get() { return ERRNO_BADF; },
|
|
58
|
+
fd_prestat_dir_name() { return ERRNO_BADF; },
|
|
59
|
+
fd_filestat_get() { return ERRNO_NOSYS; },
|
|
60
|
+
path_open() { return ERRNO_NOSYS; },
|
|
61
|
+
poll_oneoff() { return ERRNO_NOSYS; },
|
|
62
|
+
sched_yield() { return 0; },
|
|
63
|
+
environ_sizes_get() { return 0; },
|
|
64
|
+
environ_get() { return 0; },
|
|
65
|
+
clock_time_get() { return ERRNO_NOSYS; },
|
|
66
|
+
// random_get: fill `len` bytes at `buf` with CSPRNG output.
|
|
67
|
+
// Fails loud (ERRNO_IO) if no crypto is available — the previous
|
|
68
|
+
// silent zero-fill was a correctness footgun for any future codec
|
|
69
|
+
// that actually seeds from entropy.
|
|
70
|
+
random_get(buf, len) {
|
|
71
|
+
if (!webCrypto)
|
|
72
|
+
return ERRNO_IO;
|
|
73
|
+
const memory = getMemory();
|
|
74
|
+
for (let off = 0; off < len; off += CRYPTO_MAX_CHUNK) {
|
|
75
|
+
const chunk = Math.min(CRYPTO_MAX_CHUNK, len - off);
|
|
76
|
+
webCrypto.getRandomValues(new Uint8Array(memory.buffer, buf + off, chunk));
|
|
77
|
+
}
|
|
78
|
+
return 0;
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export async function loadModule(source) {
|
|
83
|
+
// random_get needs `instance.exports.memory`, which doesn't exist
|
|
84
|
+
// until after `WebAssembly.instantiate` returns. The closure captures
|
|
85
|
+
// a lazy accessor; the import object itself is built first.
|
|
86
|
+
let instance;
|
|
87
|
+
const imports = {
|
|
88
|
+
wasi_snapshot_preview1: wasiImports(() => instance.exports.memory),
|
|
89
|
+
};
|
|
90
|
+
if (source instanceof ArrayBuffer || ArrayBuffer.isView(source)) {
|
|
91
|
+
const { instance: inst } = await WebAssembly.instantiate(source, imports);
|
|
92
|
+
instance = inst;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const { instance: inst } = await WebAssembly.instantiateStreaming(source, imports);
|
|
96
|
+
instance = inst;
|
|
97
|
+
}
|
|
98
|
+
const exports = instance.exports;
|
|
99
|
+
exports._initialize?.();
|
|
100
|
+
return exports;
|
|
101
|
+
}
|
|
102
|
+
export function decodeCString(memory, ptr, maxLen = 4096) {
|
|
103
|
+
if (ptr === 0)
|
|
104
|
+
return "";
|
|
105
|
+
const view = new Uint8Array(memory.buffer, ptr);
|
|
106
|
+
let end = 0;
|
|
107
|
+
while (end < maxLen && view[end] !== 0)
|
|
108
|
+
end++;
|
|
109
|
+
return new TextDecoder("utf-8").decode(view.subarray(0, end));
|
|
110
|
+
}
|
|
111
|
+
/** Convert a non-Ok status into a thrown CompressError using the C side's message. */
|
|
112
|
+
export function checkStatus(exports, status, algorithm) {
|
|
113
|
+
if (status === Status.Ok)
|
|
114
|
+
return;
|
|
115
|
+
const lastErrPtr = exports.cu_last_error();
|
|
116
|
+
let msg = decodeCString(exports.memory, lastErrPtr);
|
|
117
|
+
if (!msg)
|
|
118
|
+
msg = decodeCString(exports.memory, exports.cu_strerror(status));
|
|
119
|
+
throw new CompressError(status, algorithm, msg || `status ${status}`);
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/core/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,EAAsB,MAAM,YAAY,CAAC;AAkEvE,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;6DAE6D;AAC7D,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B;;;;kEAIkE;AAClE,MAAM,SAAS,GACX,OAAO,UAAU,CAAC,MAAM,KAAK,WAAW;IACxC,OAAO,UAAU,CAAC,MAAM,CAAC,eAAe,KAAK,UAAU;IACnD,CAAC,CAAC,UAAU,CAAC,MAAM;IACnB,CAAC,CAAC,IAAI,CAAC;AAEf,SAAS,WAAW,CAAC,SAAmC;IACpD,OAAO;QACH,+DAA+D;QAC/D,gEAAgE;QAChE,6CAA6C;QAC7C,SAAS,CAAC,IAAY;YAClB,MAAM,IAAI,KAAK,CAAC,kBAAkB,IAAI,GAAG,CAAC,CAAC;QAC/C,CAAC;QACD,+D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AM,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,GAAG,EAAE,CAAC;IAC9C,OAAO,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,sFAAsF;AACtF,MAAM,UAAU,WAAW,CACvB,OAAoB,EAAE,MAAc,EAAE,SAAwB;IAE9D,IAAI,MAAM,KAAK,MAAM,CAAC,EAAE;QAAE,OAAO;IACjC,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAC3C,IAAI,GAAG,GAAG,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACpD,IAAI,CAAC,GAAG;QAAE,GAAG,GAAG,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAC3E,MAAM,IAAI,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,UAAU,MAAM,EAAE,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser / Deno / Bun resolver: fetch returns a Response, the loader
|
|
3
|
+
* passes it to `WebAssembly.instantiateStreaming` for concurrent
|
|
4
|
+
* download+compile.
|
|
5
|
+
*
|
|
6
|
+
* This file contains zero references to `node:*` modules, so bundlers
|
|
7
|
+
* targeting the browser never see them in the import graph — no
|
|
8
|
+
* `external: ["node:*"]` config required at the consumer.
|
|
9
|
+
*/
|
|
10
|
+
import type { WasmResolver } from "./dispatch.js";
|
|
11
|
+
export declare const resolveWasm: WasmResolver;
|
|
12
|
+
//# sourceMappingURL=resolve-browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-browser.d.ts","sourceRoot":"","sources":["../../src/core/resolve-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,eAAO,MAAM,WAAW,EAAE,YAAkC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser / Deno / Bun resolver: fetch returns a Response, the loader
|
|
3
|
+
* passes it to `WebAssembly.instantiateStreaming` for concurrent
|
|
4
|
+
* download+compile.
|
|
5
|
+
*
|
|
6
|
+
* This file contains zero references to `node:*` modules, so bundlers
|
|
7
|
+
* targeting the browser never see them in the import graph — no
|
|
8
|
+
* `external: ["node:*"]` config required at the consumer.
|
|
9
|
+
*/
|
|
10
|
+
export const resolveWasm = (url) => fetch(url);
|
|
11
|
+
//# sourceMappingURL=resolve-browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-browser.js","sourceRoot":"","sources":["../../src/core/resolve-browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,CAAC,MAAM,WAAW,GAAiB,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default resolver: detects the runtime at module load and picks fetch
|
|
3
|
+
* vs. fs.readFile. Used as a fallback when the consumer doesn't honor
|
|
4
|
+
* the package.json `browser` / `node` / `deno` / `bun` export conditions.
|
|
5
|
+
*
|
|
6
|
+
* Modern bundlers and runtimes hit the conditional exports instead and
|
|
7
|
+
* never load this file. It's a belt-and-braces fallback.
|
|
8
|
+
*/
|
|
9
|
+
import type { WasmResolver } from "./dispatch.js";
|
|
10
|
+
export declare const resolveWasm: WasmResolver;
|
|
11
|
+
//# sourceMappingURL=resolve-default.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-default.d.ts","sourceRoot":"","sources":["../../src/core/resolve-default.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAKlD,eAAO,MAAM,WAAW,EAAE,YAkBzB,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default resolver: detects the runtime at module load and picks fetch
|
|
3
|
+
* vs. fs.readFile. Used as a fallback when the consumer doesn't honor
|
|
4
|
+
* the package.json `browser` / `node` / `deno` / `bun` export conditions.
|
|
5
|
+
*
|
|
6
|
+
* Modern bundlers and runtimes hit the conditional exports instead and
|
|
7
|
+
* never load this file. It's a belt-and-braces fallback.
|
|
8
|
+
*/
|
|
9
|
+
export const resolveWasm = async (url) => {
|
|
10
|
+
const hasFetch = typeof fetch === "function";
|
|
11
|
+
const isDeno = typeof Deno !== "undefined";
|
|
12
|
+
const isBun = typeof Bun !== "undefined";
|
|
13
|
+
const isNode = typeof process !== "undefined" &&
|
|
14
|
+
process.versions?.node !== undefined &&
|
|
15
|
+
!isDeno && !isBun;
|
|
16
|
+
// Node's fetch can't do file://. Everyone else's can (Deno + Bun
|
|
17
|
+
// natively; browsers only see http(s)). So Node is the only path
|
|
18
|
+
// that needs fs.readFile.
|
|
19
|
+
if (isNode && url.protocol === "file:") {
|
|
20
|
+
const { readFile } = await import("node:fs/promises");
|
|
21
|
+
return readFile(url);
|
|
22
|
+
}
|
|
23
|
+
if (hasFetch)
|
|
24
|
+
return fetch(url);
|
|
25
|
+
throw new Error("no wasm resolver available in this runtime");
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=resolve-default.js.map
|