zstd-wasm-vn 1.0.0

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.
@@ -0,0 +1,434 @@
1
+ let wasm;
2
+
3
+ let cachedUint8ArrayMemory0 = null;
4
+
5
+ function getUint8ArrayMemory0() {
6
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
7
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
8
+ }
9
+ return cachedUint8ArrayMemory0;
10
+ }
11
+
12
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
13
+
14
+ cachedTextDecoder.decode();
15
+
16
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
17
+ let numBytesDecoded = 0;
18
+ function decodeText(ptr, len) {
19
+ numBytesDecoded += len;
20
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
21
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
22
+ cachedTextDecoder.decode();
23
+ numBytesDecoded = len;
24
+ }
25
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
26
+ }
27
+
28
+ function getStringFromWasm0(ptr, len) {
29
+ ptr = ptr >>> 0;
30
+ return decodeText(ptr, len);
31
+ }
32
+
33
+ let WASM_VECTOR_LEN = 0;
34
+
35
+ function passArray8ToWasm0(arg, malloc) {
36
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
37
+ getUint8ArrayMemory0().set(arg, ptr / 1);
38
+ WASM_VECTOR_LEN = arg.length;
39
+ return ptr;
40
+ }
41
+
42
+ function isLikeNone(x) {
43
+ return x === undefined || x === null;
44
+ }
45
+
46
+ function takeFromExternrefTable0(idx) {
47
+ const value = wasm.__wbindgen_export_0.get(idx);
48
+ wasm.__externref_table_dealloc(idx);
49
+ return value;
50
+ }
51
+
52
+ function getArrayU8FromWasm0(ptr, len) {
53
+ ptr = ptr >>> 0;
54
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
55
+ }
56
+
57
+ const ZstdFinalization = (typeof FinalizationRegistry === 'undefined')
58
+ ? { register: () => {}, unregister: () => {} }
59
+ : new FinalizationRegistry(ptr => wasm.__wbg_zstd_free(ptr >>> 0, 1));
60
+ /**
61
+ * ZSTD compression and decompression for WebAssembly
62
+ */
63
+ export class Zstd {
64
+
65
+ __destroy_into_raw() {
66
+ const ptr = this.__wbg_ptr;
67
+ this.__wbg_ptr = 0;
68
+ ZstdFinalization.unregister(this);
69
+ return ptr;
70
+ }
71
+
72
+ free() {
73
+ const ptr = this.__destroy_into_raw();
74
+ wasm.__wbg_zstd_free(ptr, 0);
75
+ }
76
+ /**
77
+ * Compresses data using Zstandard compression
78
+ *
79
+ * # Arguments
80
+ *
81
+ * * `data` - Input data to compress
82
+ * * `level` - Compression level (1-22, default 3). Higher = better compression but slower
83
+ * @param {Uint8Array} data
84
+ * @param {number | null} [level]
85
+ * @returns {Uint8Array}
86
+ */
87
+ static compress(data, level) {
88
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
89
+ const len0 = WASM_VECTOR_LEN;
90
+ const ret = wasm.zstd_compress(ptr0, len0, isLikeNone(level) ? 0x100000001 : (level) >> 0);
91
+ if (ret[3]) {
92
+ throw takeFromExternrefTable0(ret[2]);
93
+ }
94
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
95
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
96
+ return v2;
97
+ }
98
+ /**
99
+ * Decompresses Zstandard compressed data
100
+ *
101
+ * # Arguments
102
+ *
103
+ * * `compressed_data` - Zstandard compressed data
104
+ * @param {Uint8Array} compressed_data
105
+ * @returns {Uint8Array}
106
+ */
107
+ static decompress(compressed_data) {
108
+ const ptr0 = passArray8ToWasm0(compressed_data, wasm.__wbindgen_malloc);
109
+ const len0 = WASM_VECTOR_LEN;
110
+ const ret = wasm.zstd_decompress(ptr0, len0);
111
+ if (ret[3]) {
112
+ throw takeFromExternrefTable0(ret[2]);
113
+ }
114
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
115
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
116
+ return v2;
117
+ }
118
+ /**
119
+ * Returns the recommended default compression level
120
+ * @returns {number}
121
+ */
122
+ static defaultCompressionLevel() {
123
+ const ret = wasm.zstd_defaultCompressionLevel();
124
+ return ret;
125
+ }
126
+ /**
127
+ * Returns the minimum compression level
128
+ * @returns {number}
129
+ */
130
+ static minCompressionLevel() {
131
+ const ret = wasm.zstd_minCompressionLevel();
132
+ return ret;
133
+ }
134
+ /**
135
+ * Returns the maximum compression level
136
+ * @returns {number}
137
+ */
138
+ static maxCompressionLevel() {
139
+ const ret = wasm.zstd_maxCompressionLevel();
140
+ return ret;
141
+ }
142
+ /**
143
+ * Estimates the compressed size for planning purposes
144
+ * @param {number} input_size
145
+ * @returns {number}
146
+ */
147
+ static compressBound(input_size) {
148
+ const ret = wasm.zstd_compressBound(input_size);
149
+ return ret >>> 0;
150
+ }
151
+ /**
152
+ * Calculates compression ratio (smaller = better compression)
153
+ * @param {number} original_size
154
+ * @param {number} compressed_size
155
+ * @returns {number}
156
+ */
157
+ static compressionRatio(original_size, compressed_size) {
158
+ const ret = wasm.zstd_compressionRatio(original_size, compressed_size);
159
+ return ret;
160
+ }
161
+ /**
162
+ * Calculates space savings percentage
163
+ * @param {number} original_size
164
+ * @param {number} compressed_size
165
+ * @returns {number}
166
+ */
167
+ static spaceSavings(original_size, compressed_size) {
168
+ const ret = wasm.zstd_spaceSavings(original_size, compressed_size);
169
+ return ret;
170
+ }
171
+ }
172
+ if (Symbol.dispose) Zstd.prototype[Symbol.dispose] = Zstd.prototype.free;
173
+
174
+ const ZstdCompressorFinalization = (typeof FinalizationRegistry === 'undefined')
175
+ ? { register: () => {}, unregister: () => {} }
176
+ : new FinalizationRegistry(ptr => wasm.__wbg_zstdcompressor_free(ptr >>> 0, 1));
177
+ /**
178
+ * Streaming compression for large data
179
+ */
180
+ export class ZstdCompressor {
181
+
182
+ __destroy_into_raw() {
183
+ const ptr = this.__wbg_ptr;
184
+ this.__wbg_ptr = 0;
185
+ ZstdCompressorFinalization.unregister(this);
186
+ return ptr;
187
+ }
188
+
189
+ free() {
190
+ const ptr = this.__destroy_into_raw();
191
+ wasm.__wbg_zstdcompressor_free(ptr, 0);
192
+ }
193
+ /**
194
+ * Creates a new streaming compressor
195
+ * @param {number | null} [level]
196
+ */
197
+ constructor(level) {
198
+ const ret = wasm.zstdcompressor_new(isLikeNone(level) ? 0x100000001 : (level) >> 0);
199
+ if (ret[2]) {
200
+ throw takeFromExternrefTable0(ret[1]);
201
+ }
202
+ this.__wbg_ptr = ret[0] >>> 0;
203
+ ZstdCompressorFinalization.register(this, this.__wbg_ptr, this);
204
+ return this;
205
+ }
206
+ /**
207
+ * Compresses a chunk of data
208
+ * @param {Uint8Array} data
209
+ */
210
+ compress_chunk(data) {
211
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
212
+ const len0 = WASM_VECTOR_LEN;
213
+ const ret = wasm.zstdcompressor_compress_chunk(this.__wbg_ptr, ptr0, len0);
214
+ if (ret[1]) {
215
+ throw takeFromExternrefTable0(ret[0]);
216
+ }
217
+ }
218
+ /**
219
+ * Finalizes compression and returns the compressed data
220
+ * @returns {Uint8Array}
221
+ */
222
+ finalize() {
223
+ const ret = wasm.zstdcompressor_finalize(this.__wbg_ptr);
224
+ if (ret[3]) {
225
+ throw takeFromExternrefTable0(ret[2]);
226
+ }
227
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
228
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
229
+ return v1;
230
+ }
231
+ /**
232
+ * Gets the current compression level
233
+ * @returns {number}
234
+ */
235
+ get level() {
236
+ const ret = wasm.zstdcompressor_level(this.__wbg_ptr);
237
+ return ret;
238
+ }
239
+ }
240
+ if (Symbol.dispose) ZstdCompressor.prototype[Symbol.dispose] = ZstdCompressor.prototype.free;
241
+
242
+ const ZstdDecompressorFinalization = (typeof FinalizationRegistry === 'undefined')
243
+ ? { register: () => {}, unregister: () => {} }
244
+ : new FinalizationRegistry(ptr => wasm.__wbg_zstddecompressor_free(ptr >>> 0, 1));
245
+ /**
246
+ * Streaming decompression for large data
247
+ */
248
+ export class ZstdDecompressor {
249
+
250
+ __destroy_into_raw() {
251
+ const ptr = this.__wbg_ptr;
252
+ this.__wbg_ptr = 0;
253
+ ZstdDecompressorFinalization.unregister(this);
254
+ return ptr;
255
+ }
256
+
257
+ free() {
258
+ const ptr = this.__destroy_into_raw();
259
+ wasm.__wbg_zstddecompressor_free(ptr, 0);
260
+ }
261
+ /**
262
+ * Creates a new streaming decompressor
263
+ * @param {Uint8Array} compressed_data
264
+ */
265
+ constructor(compressed_data) {
266
+ const ptr0 = passArray8ToWasm0(compressed_data, wasm.__wbindgen_malloc);
267
+ const len0 = WASM_VECTOR_LEN;
268
+ const ret = wasm.zstddecompressor_new(ptr0, len0);
269
+ if (ret[2]) {
270
+ throw takeFromExternrefTable0(ret[1]);
271
+ }
272
+ this.__wbg_ptr = ret[0] >>> 0;
273
+ ZstdDecompressorFinalization.register(this, this.__wbg_ptr, this);
274
+ return this;
275
+ }
276
+ /**
277
+ * Decompresses a chunk of data
278
+ * @param {number} max_output_size
279
+ * @returns {Uint8Array}
280
+ */
281
+ decompress_chunk(max_output_size) {
282
+ const ret = wasm.zstddecompressor_decompress_chunk(this.__wbg_ptr, max_output_size);
283
+ if (ret[3]) {
284
+ throw takeFromExternrefTable0(ret[2]);
285
+ }
286
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
287
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
288
+ return v1;
289
+ }
290
+ /**
291
+ * Decompresses all remaining data
292
+ * @returns {Uint8Array}
293
+ */
294
+ finalize() {
295
+ const ret = wasm.zstddecompressor_finalize(this.__wbg_ptr);
296
+ if (ret[3]) {
297
+ throw takeFromExternrefTable0(ret[2]);
298
+ }
299
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
300
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
301
+ return v1;
302
+ }
303
+ }
304
+ if (Symbol.dispose) ZstdDecompressor.prototype[Symbol.dispose] = ZstdDecompressor.prototype.free;
305
+
306
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
307
+
308
+ async function __wbg_load(module, imports) {
309
+ if (typeof Response === 'function' && module instanceof Response) {
310
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
311
+ try {
312
+ return await WebAssembly.instantiateStreaming(module, imports);
313
+
314
+ } catch (e) {
315
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
316
+
317
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
318
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
319
+
320
+ } else {
321
+ throw e;
322
+ }
323
+ }
324
+ }
325
+
326
+ const bytes = await module.arrayBuffer();
327
+ return await WebAssembly.instantiate(bytes, imports);
328
+
329
+ } else {
330
+ const instance = await WebAssembly.instantiate(module, imports);
331
+
332
+ if (instance instanceof WebAssembly.Instance) {
333
+ return { instance, module };
334
+
335
+ } else {
336
+ return instance;
337
+ }
338
+ }
339
+ }
340
+
341
+ function __wbg_get_imports() {
342
+ const imports = {};
343
+ imports.wbg = {};
344
+ imports.wbg.__wbg_wbindgenthrow_451ec1a8469d7eb6 = function(arg0, arg1) {
345
+ throw new Error(getStringFromWasm0(arg0, arg1));
346
+ };
347
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
348
+ // Cast intrinsic for `Ref(String) -> Externref`.
349
+ const ret = getStringFromWasm0(arg0, arg1);
350
+ return ret;
351
+ };
352
+ imports.wbg.__wbindgen_init_externref_table = function() {
353
+ const table = wasm.__wbindgen_export_0;
354
+ const offset = table.grow(4);
355
+ table.set(0, undefined);
356
+ table.set(offset + 0, undefined);
357
+ table.set(offset + 1, null);
358
+ table.set(offset + 2, true);
359
+ table.set(offset + 3, false);
360
+ ;
361
+ };
362
+
363
+ return imports;
364
+ }
365
+
366
+ function __wbg_init_memory(imports, memory) {
367
+
368
+ }
369
+
370
+ function __wbg_finalize_init(instance, module) {
371
+ wasm = instance.exports;
372
+ __wbg_init.__wbindgen_wasm_module = module;
373
+ cachedUint8ArrayMemory0 = null;
374
+
375
+
376
+ wasm.__wbindgen_start();
377
+ return wasm;
378
+ }
379
+
380
+ function initSync(module) {
381
+ if (wasm !== undefined) return wasm;
382
+
383
+
384
+ if (typeof module !== 'undefined') {
385
+ if (Object.getPrototypeOf(module) === Object.prototype) {
386
+ ({module} = module)
387
+ } else {
388
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
389
+ }
390
+ }
391
+
392
+ const imports = __wbg_get_imports();
393
+
394
+ __wbg_init_memory(imports);
395
+
396
+ if (!(module instanceof WebAssembly.Module)) {
397
+ module = new WebAssembly.Module(module);
398
+ }
399
+
400
+ const instance = new WebAssembly.Instance(module, imports);
401
+
402
+ return __wbg_finalize_init(instance, module);
403
+ }
404
+
405
+ async function __wbg_init(module_or_path) {
406
+ if (wasm !== undefined) return wasm;
407
+
408
+
409
+ if (typeof module_or_path !== 'undefined') {
410
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
411
+ ({module_or_path} = module_or_path)
412
+ } else {
413
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
414
+ }
415
+ }
416
+
417
+ if (typeof module_or_path === 'undefined') {
418
+ module_or_path = new URL('zstd_wasm_vn_bg.wasm', import.meta.url);
419
+ }
420
+ const imports = __wbg_get_imports();
421
+
422
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
423
+ module_or_path = fetch(module_or_path);
424
+ }
425
+
426
+ __wbg_init_memory(imports);
427
+
428
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
429
+
430
+ return __wbg_finalize_init(instance, module);
431
+ }
432
+
433
+ export { initSync };
434
+ export default __wbg_init;
Binary file
@@ -0,0 +1,34 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_zstd_free: (a: number, b: number) => void;
5
+ export const zstd_compress: (a: number, b: number, c: number) => [number, number, number, number];
6
+ export const zstd_decompress: (a: number, b: number) => [number, number, number, number];
7
+ export const zstd_defaultCompressionLevel: () => number;
8
+ export const zstd_minCompressionLevel: () => number;
9
+ export const zstd_maxCompressionLevel: () => number;
10
+ export const zstd_compressBound: (a: number) => number;
11
+ export const zstd_compressionRatio: (a: number, b: number) => number;
12
+ export const zstd_spaceSavings: (a: number, b: number) => number;
13
+ export const __wbg_zstdcompressor_free: (a: number, b: number) => void;
14
+ export const zstdcompressor_new: (a: number) => [number, number, number];
15
+ export const zstdcompressor_compress_chunk: (a: number, b: number, c: number) => [number, number];
16
+ export const zstdcompressor_finalize: (a: number) => [number, number, number, number];
17
+ export const zstdcompressor_level: (a: number) => number;
18
+ export const __wbg_zstddecompressor_free: (a: number, b: number) => void;
19
+ export const zstddecompressor_new: (a: number, b: number) => [number, number, number];
20
+ export const zstddecompressor_decompress_chunk: (a: number, b: number) => [number, number, number, number];
21
+ export const zstddecompressor_finalize: (a: number) => [number, number, number, number];
22
+ export const rust_zstd_wasm_shim_qsort: (a: number, b: number, c: number, d: number) => void;
23
+ export const rust_zstd_wasm_shim_malloc: (a: number) => number;
24
+ export const rust_zstd_wasm_shim_memcmp: (a: number, b: number, c: number) => number;
25
+ export const rust_zstd_wasm_shim_calloc: (a: number, b: number) => number;
26
+ export const rust_zstd_wasm_shim_free: (a: number) => void;
27
+ export const rust_zstd_wasm_shim_memcpy: (a: number, b: number, c: number) => number;
28
+ export const rust_zstd_wasm_shim_memmove: (a: number, b: number, c: number) => number;
29
+ export const rust_zstd_wasm_shim_memset: (a: number, b: number, c: number) => number;
30
+ export const __wbindgen_export_0: WebAssembly.Table;
31
+ export const __wbindgen_malloc: (a: number, b: number) => number;
32
+ export const __externref_table_dealloc: (a: number) => void;
33
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
34
+ export const __wbindgen_start: () => void;