@peerbit/riblt 1.0.3 → 1.0.4

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/dist/index.js CHANGED
@@ -1,483 +1,3 @@
1
- let wasm;
1
+ import "./wasm-init.js";
2
2
 
3
- function addToExternrefTable0(obj) {
4
- const idx = wasm.__externref_table_alloc();
5
- wasm.__wbindgen_export_2.set(idx, obj);
6
- return idx;
7
- }
8
-
9
- function handleError(f, args) {
10
- try {
11
- return f.apply(this, args);
12
- } catch (e) {
13
- const idx = addToExternrefTable0(e);
14
- wasm.__wbindgen_exn_store(idx);
15
- }
16
- }
17
-
18
- function isLikeNone(x) {
19
- return x === undefined || x === null;
20
- }
21
-
22
- let cachedDataViewMemory0 = null;
23
-
24
- function getDataViewMemory0() {
25
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
26
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
27
- }
28
- return cachedDataViewMemory0;
29
- }
30
-
31
- function debugString(val) {
32
- // primitive types
33
- const type = typeof val;
34
- if (type == 'number' || type == 'boolean' || val == null) {
35
- return `${val}`;
36
- }
37
- if (type == 'string') {
38
- return `"${val}"`;
39
- }
40
- if (type == 'symbol') {
41
- const description = val.description;
42
- if (description == null) {
43
- return 'Symbol';
44
- } else {
45
- return `Symbol(${description})`;
46
- }
47
- }
48
- if (type == 'function') {
49
- const name = val.name;
50
- if (typeof name == 'string' && name.length > 0) {
51
- return `Function(${name})`;
52
- } else {
53
- return 'Function';
54
- }
55
- }
56
- // objects
57
- if (Array.isArray(val)) {
58
- const length = val.length;
59
- let debug = '[';
60
- if (length > 0) {
61
- debug += debugString(val[0]);
62
- }
63
- for(let i = 1; i < length; i++) {
64
- debug += ', ' + debugString(val[i]);
65
- }
66
- debug += ']';
67
- return debug;
68
- }
69
- // Test for built-in
70
- const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
71
- let className;
72
- if (builtInMatches && builtInMatches.length > 1) {
73
- className = builtInMatches[1];
74
- } else {
75
- // Failed to match the standard '[object ClassName]'
76
- return toString.call(val);
77
- }
78
- if (className == 'Object') {
79
- // we're a user defined class or Object
80
- // JSON.stringify avoids problems with cycles, and is generally much
81
- // easier than looping through ownProperties of `val`.
82
- try {
83
- return 'Object(' + JSON.stringify(val) + ')';
84
- } catch (_) {
85
- return 'Object';
86
- }
87
- }
88
- // errors
89
- if (val instanceof Error) {
90
- return `${val.name}: ${val.message}\n${val.stack}`;
91
- }
92
- // TODO we could test for more things here, like `Set`s and `Map`s.
93
- return className;
94
- }
95
-
96
- let WASM_VECTOR_LEN = 0;
97
-
98
- let cachedUint8ArrayMemory0 = null;
99
-
100
- function getUint8ArrayMemory0() {
101
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
102
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
103
- }
104
- return cachedUint8ArrayMemory0;
105
- }
106
-
107
- const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
108
-
109
- const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
110
- ? function (arg, view) {
111
- return cachedTextEncoder.encodeInto(arg, view);
112
- }
113
- : function (arg, view) {
114
- const buf = cachedTextEncoder.encode(arg);
115
- view.set(buf);
116
- return {
117
- read: arg.length,
118
- written: buf.length
119
- };
120
- });
121
-
122
- function passStringToWasm0(arg, malloc, realloc) {
123
-
124
- if (realloc === undefined) {
125
- const buf = cachedTextEncoder.encode(arg);
126
- const ptr = malloc(buf.length, 1) >>> 0;
127
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
128
- WASM_VECTOR_LEN = buf.length;
129
- return ptr;
130
- }
131
-
132
- let len = arg.length;
133
- let ptr = malloc(len, 1) >>> 0;
134
-
135
- const mem = getUint8ArrayMemory0();
136
-
137
- let offset = 0;
138
-
139
- for (; offset < len; offset++) {
140
- const code = arg.charCodeAt(offset);
141
- if (code > 0x7F) break;
142
- mem[ptr + offset] = code;
143
- }
144
-
145
- if (offset !== len) {
146
- if (offset !== 0) {
147
- arg = arg.slice(offset);
148
- }
149
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
150
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
151
- const ret = encodeString(arg, view);
152
-
153
- offset += ret.written;
154
- ptr = realloc(ptr, len, offset, 1) >>> 0;
155
- }
156
-
157
- WASM_VECTOR_LEN = offset;
158
- return ptr;
159
- }
160
-
161
- const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
162
-
163
- if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
164
-
165
- function getStringFromWasm0(ptr, len) {
166
- ptr = ptr >>> 0;
167
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
168
- }
169
-
170
- function takeFromExternrefTable0(idx) {
171
- const value = wasm.__wbindgen_export_2.get(idx);
172
- wasm.__externref_table_dealloc(idx);
173
- return value;
174
- }
175
-
176
- const DecoderWrapperFinalization = (typeof FinalizationRegistry === 'undefined')
177
- ? { register: () => {}, unregister: () => {} }
178
- : new FinalizationRegistry(ptr => wasm.__wbg_decoderwrapper_free(ptr >>> 0, 1));
179
-
180
- export class DecoderWrapper {
181
-
182
- static __wrap(ptr) {
183
- ptr = ptr >>> 0;
184
- const obj = Object.create(DecoderWrapper.prototype);
185
- obj.__wbg_ptr = ptr;
186
- DecoderWrapperFinalization.register(obj, obj.__wbg_ptr, obj);
187
- return obj;
188
- }
189
-
190
- __destroy_into_raw() {
191
- const ptr = this.__wbg_ptr;
192
- this.__wbg_ptr = 0;
193
- DecoderWrapperFinalization.unregister(this);
194
- return ptr;
195
- }
196
-
197
- free() {
198
- const ptr = this.__destroy_into_raw();
199
- wasm.__wbg_decoderwrapper_free(ptr, 0);
200
- }
201
- constructor() {
202
- const ret = wasm.decoderwrapper_new();
203
- this.__wbg_ptr = ret >>> 0;
204
- DecoderWrapperFinalization.register(this, this.__wbg_ptr, this);
205
- return this;
206
- }
207
- /**
208
- * @param {bigint} symbol
209
- */
210
- add_symbol(symbol) {
211
- wasm.decoderwrapper_add_symbol(this.__wbg_ptr, symbol);
212
- }
213
- /**
214
- * @param {any} coded_symbol_js
215
- */
216
- add_coded_symbol(coded_symbol_js) {
217
- wasm.decoderwrapper_add_coded_symbol(this.__wbg_ptr, coded_symbol_js);
218
- }
219
- try_decode() {
220
- const ret = wasm.decoderwrapper_try_decode(this.__wbg_ptr);
221
- if (ret[1]) {
222
- throw takeFromExternrefTable0(ret[0]);
223
- }
224
- }
225
- /**
226
- * @returns {boolean}
227
- */
228
- decoded() {
229
- const ret = wasm.decoderwrapper_decoded(this.__wbg_ptr);
230
- return ret !== 0;
231
- }
232
- /**
233
- * @returns {Array<any>}
234
- */
235
- get_remote_symbols() {
236
- const ret = wasm.decoderwrapper_get_remote_symbols(this.__wbg_ptr);
237
- return ret;
238
- }
239
- /**
240
- * @returns {Array<any>}
241
- */
242
- get_local_symbols() {
243
- const ret = wasm.decoderwrapper_get_local_symbols(this.__wbg_ptr);
244
- return ret;
245
- }
246
- reset() {
247
- wasm.decoderwrapper_reset(this.__wbg_ptr);
248
- }
249
- }
250
-
251
- const EncoderWrapperFinalization = (typeof FinalizationRegistry === 'undefined')
252
- ? { register: () => {}, unregister: () => {} }
253
- : new FinalizationRegistry(ptr => wasm.__wbg_encoderwrapper_free(ptr >>> 0, 1));
254
-
255
- export class EncoderWrapper {
256
-
257
- static __wrap(ptr) {
258
- ptr = ptr >>> 0;
259
- const obj = Object.create(EncoderWrapper.prototype);
260
- obj.__wbg_ptr = ptr;
261
- EncoderWrapperFinalization.register(obj, obj.__wbg_ptr, obj);
262
- return obj;
263
- }
264
-
265
- __destroy_into_raw() {
266
- const ptr = this.__wbg_ptr;
267
- this.__wbg_ptr = 0;
268
- EncoderWrapperFinalization.unregister(this);
269
- return ptr;
270
- }
271
-
272
- free() {
273
- const ptr = this.__destroy_into_raw();
274
- wasm.__wbg_encoderwrapper_free(ptr, 0);
275
- }
276
- constructor() {
277
- const ret = wasm.encoderwrapper_new();
278
- this.__wbg_ptr = ret >>> 0;
279
- EncoderWrapperFinalization.register(this, this.__wbg_ptr, this);
280
- return this;
281
- }
282
- /**
283
- * @param {bigint} symbol
284
- */
285
- add_symbol(symbol) {
286
- wasm.encoderwrapper_add_symbol(this.__wbg_ptr, symbol);
287
- }
288
- /**
289
- * @returns {any}
290
- */
291
- produce_next_coded_symbol() {
292
- const ret = wasm.encoderwrapper_produce_next_coded_symbol(this.__wbg_ptr);
293
- return ret;
294
- }
295
- reset() {
296
- wasm.encoderwrapper_reset(this.__wbg_ptr);
297
- }
298
- /**
299
- * @returns {DecoderWrapper}
300
- */
301
- to_decoder() {
302
- const ret = wasm.encoderwrapper_to_decoder(this.__wbg_ptr);
303
- return DecoderWrapper.__wrap(ret);
304
- }
305
- /**
306
- * @returns {EncoderWrapper}
307
- */
308
- clone() {
309
- const ret = wasm.encoderwrapper_clone(this.__wbg_ptr);
310
- return EncoderWrapper.__wrap(ret);
311
- }
312
- }
313
-
314
- async function __wbg_load(module, imports) {
315
- if (typeof Response === 'function' && module instanceof Response) {
316
- if (typeof WebAssembly.instantiateStreaming === 'function') {
317
- try {
318
- return await WebAssembly.instantiateStreaming(module, imports);
319
-
320
- } catch (e) {
321
- if (module.headers.get('Content-Type') != 'application/wasm') {
322
- 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);
323
-
324
- } else {
325
- throw e;
326
- }
327
- }
328
- }
329
-
330
- const bytes = await module.arrayBuffer();
331
- return await WebAssembly.instantiate(bytes, imports);
332
-
333
- } else {
334
- const instance = await WebAssembly.instantiate(module, imports);
335
-
336
- if (instance instanceof WebAssembly.Instance) {
337
- return { instance, module };
338
-
339
- } else {
340
- return instance;
341
- }
342
- }
343
- }
344
-
345
- function __wbg_get_imports() {
346
- const imports = {};
347
- imports.wbg = {};
348
- imports.wbg.__wbg_get_bbccf8970793c087 = function() { return handleError(function (arg0, arg1) {
349
- const ret = Reflect.get(arg0, arg1);
350
- return ret;
351
- }, arguments) };
352
- imports.wbg.__wbg_new_254fa9eac11932ae = function() {
353
- const ret = new Array();
354
- return ret;
355
- };
356
- imports.wbg.__wbg_new_688846f374351c92 = function() {
357
- const ret = new Object();
358
- return ret;
359
- };
360
- imports.wbg.__wbg_push_6edad0df4b546b2c = function(arg0, arg1) {
361
- const ret = arg0.push(arg1);
362
- return ret;
363
- };
364
- imports.wbg.__wbg_set_4e647025551483bd = function() { return handleError(function (arg0, arg1, arg2) {
365
- const ret = Reflect.set(arg0, arg1, arg2);
366
- return ret;
367
- }, arguments) };
368
- imports.wbg.__wbindgen_bigint_from_i64 = function(arg0) {
369
- const ret = arg0;
370
- return ret;
371
- };
372
- imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
373
- const ret = BigInt.asUintN(64, arg0);
374
- return ret;
375
- };
376
- imports.wbg.__wbindgen_bigint_get_as_i64 = function(arg0, arg1) {
377
- const v = arg1;
378
- const ret = typeof(v) === 'bigint' ? v : undefined;
379
- getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
380
- getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
381
- };
382
- imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
383
- const ret = debugString(arg1);
384
- const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
385
- const len1 = WASM_VECTOR_LEN;
386
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
387
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
388
- };
389
- imports.wbg.__wbindgen_init_externref_table = function() {
390
- const table = wasm.__wbindgen_export_2;
391
- const offset = table.grow(4);
392
- table.set(0, undefined);
393
- table.set(offset + 0, undefined);
394
- table.set(offset + 1, null);
395
- table.set(offset + 2, true);
396
- table.set(offset + 3, false);
397
- ;
398
- };
399
- imports.wbg.__wbindgen_jsval_eq = function(arg0, arg1) {
400
- const ret = arg0 === arg1;
401
- return ret;
402
- };
403
- imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
404
- const ret = getStringFromWasm0(arg0, arg1);
405
- return ret;
406
- };
407
- imports.wbg.__wbindgen_throw = function(arg0, arg1) {
408
- throw new Error(getStringFromWasm0(arg0, arg1));
409
- };
410
-
411
- return imports;
412
- }
413
-
414
- function __wbg_init_memory(imports, memory) {
415
-
416
- }
417
-
418
- function __wbg_finalize_init(instance, module) {
419
- wasm = instance.exports;
420
- __wbg_init.__wbindgen_wasm_module = module;
421
- cachedDataViewMemory0 = null;
422
- cachedUint8ArrayMemory0 = null;
423
-
424
-
425
- wasm.__wbindgen_start();
426
- return wasm;
427
- }
428
-
429
- function initSync(module) {
430
- if (wasm !== undefined) return wasm;
431
-
432
-
433
- if (typeof module !== 'undefined') {
434
- if (Object.getPrototypeOf(module) === Object.prototype) {
435
- ({module} = module)
436
- } else {
437
- console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
438
- }
439
- }
440
-
441
- const imports = __wbg_get_imports();
442
-
443
- __wbg_init_memory(imports);
444
-
445
- if (!(module instanceof WebAssembly.Module)) {
446
- module = new WebAssembly.Module(module);
447
- }
448
-
449
- const instance = new WebAssembly.Instance(module, imports);
450
-
451
- return __wbg_finalize_init(instance, module);
452
- }
453
-
454
- async function __wbg_init(module_or_path) {
455
- if (wasm !== undefined) return wasm;
456
-
457
-
458
- if (typeof module_or_path !== 'undefined') {
459
- if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
460
- ({module_or_path} = module_or_path)
461
- } else {
462
- console.warn('using deprecated parameters for the initialization function; pass a single object instead')
463
- }
464
- }
465
-
466
- if (typeof module_or_path === 'undefined') {
467
- module_or_path = new URL('index_bg.wasm', import.meta.url);
468
- }
469
- const imports = __wbg_get_imports();
470
-
471
- if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
472
- module_or_path = fetch(module_or_path);
473
- }
474
-
475
- __wbg_init_memory(imports);
476
-
477
- const { instance, module } = await __wbg_load(await module_or_path, imports);
478
-
479
- return __wbg_finalize_init(instance, module);
480
- }
481
-
482
- export { initSync };
483
- export default __wbg_init;
3
+ export { DecoderWrapper, EncoderWrapper, initSync } from "./rateless_iblt.js";
@@ -0,0 +1,483 @@
1
+ let wasm;
2
+
3
+ function addToExternrefTable0(obj) {
4
+ const idx = wasm.__externref_table_alloc();
5
+ wasm.__wbindgen_export_2.set(idx, obj);
6
+ return idx;
7
+ }
8
+
9
+ function handleError(f, args) {
10
+ try {
11
+ return f.apply(this, args);
12
+ } catch (e) {
13
+ const idx = addToExternrefTable0(e);
14
+ wasm.__wbindgen_exn_store(idx);
15
+ }
16
+ }
17
+
18
+ function isLikeNone(x) {
19
+ return x === undefined || x === null;
20
+ }
21
+
22
+ let cachedDataViewMemory0 = null;
23
+
24
+ function getDataViewMemory0() {
25
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
26
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
27
+ }
28
+ return cachedDataViewMemory0;
29
+ }
30
+
31
+ function debugString(val) {
32
+ // primitive types
33
+ const type = typeof val;
34
+ if (type == 'number' || type == 'boolean' || val == null) {
35
+ return `${val}`;
36
+ }
37
+ if (type == 'string') {
38
+ return `"${val}"`;
39
+ }
40
+ if (type == 'symbol') {
41
+ const description = val.description;
42
+ if (description == null) {
43
+ return 'Symbol';
44
+ } else {
45
+ return `Symbol(${description})`;
46
+ }
47
+ }
48
+ if (type == 'function') {
49
+ const name = val.name;
50
+ if (typeof name == 'string' && name.length > 0) {
51
+ return `Function(${name})`;
52
+ } else {
53
+ return 'Function';
54
+ }
55
+ }
56
+ // objects
57
+ if (Array.isArray(val)) {
58
+ const length = val.length;
59
+ let debug = '[';
60
+ if (length > 0) {
61
+ debug += debugString(val[0]);
62
+ }
63
+ for(let i = 1; i < length; i++) {
64
+ debug += ', ' + debugString(val[i]);
65
+ }
66
+ debug += ']';
67
+ return debug;
68
+ }
69
+ // Test for built-in
70
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
71
+ let className;
72
+ if (builtInMatches && builtInMatches.length > 1) {
73
+ className = builtInMatches[1];
74
+ } else {
75
+ // Failed to match the standard '[object ClassName]'
76
+ return toString.call(val);
77
+ }
78
+ if (className == 'Object') {
79
+ // we're a user defined class or Object
80
+ // JSON.stringify avoids problems with cycles, and is generally much
81
+ // easier than looping through ownProperties of `val`.
82
+ try {
83
+ return 'Object(' + JSON.stringify(val) + ')';
84
+ } catch (_) {
85
+ return 'Object';
86
+ }
87
+ }
88
+ // errors
89
+ if (val instanceof Error) {
90
+ return `${val.name}: ${val.message}\n${val.stack}`;
91
+ }
92
+ // TODO we could test for more things here, like `Set`s and `Map`s.
93
+ return className;
94
+ }
95
+
96
+ let WASM_VECTOR_LEN = 0;
97
+
98
+ let cachedUint8ArrayMemory0 = null;
99
+
100
+ function getUint8ArrayMemory0() {
101
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
102
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
103
+ }
104
+ return cachedUint8ArrayMemory0;
105
+ }
106
+
107
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
108
+
109
+ const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
110
+ ? function (arg, view) {
111
+ return cachedTextEncoder.encodeInto(arg, view);
112
+ }
113
+ : function (arg, view) {
114
+ const buf = cachedTextEncoder.encode(arg);
115
+ view.set(buf);
116
+ return {
117
+ read: arg.length,
118
+ written: buf.length
119
+ };
120
+ });
121
+
122
+ function passStringToWasm0(arg, malloc, realloc) {
123
+
124
+ if (realloc === undefined) {
125
+ const buf = cachedTextEncoder.encode(arg);
126
+ const ptr = malloc(buf.length, 1) >>> 0;
127
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
128
+ WASM_VECTOR_LEN = buf.length;
129
+ return ptr;
130
+ }
131
+
132
+ let len = arg.length;
133
+ let ptr = malloc(len, 1) >>> 0;
134
+
135
+ const mem = getUint8ArrayMemory0();
136
+
137
+ let offset = 0;
138
+
139
+ for (; offset < len; offset++) {
140
+ const code = arg.charCodeAt(offset);
141
+ if (code > 0x7F) break;
142
+ mem[ptr + offset] = code;
143
+ }
144
+
145
+ if (offset !== len) {
146
+ if (offset !== 0) {
147
+ arg = arg.slice(offset);
148
+ }
149
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
150
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
151
+ const ret = encodeString(arg, view);
152
+
153
+ offset += ret.written;
154
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
155
+ }
156
+
157
+ WASM_VECTOR_LEN = offset;
158
+ return ptr;
159
+ }
160
+
161
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
162
+
163
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
164
+
165
+ function getStringFromWasm0(ptr, len) {
166
+ ptr = ptr >>> 0;
167
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
168
+ }
169
+
170
+ function takeFromExternrefTable0(idx) {
171
+ const value = wasm.__wbindgen_export_2.get(idx);
172
+ wasm.__externref_table_dealloc(idx);
173
+ return value;
174
+ }
175
+
176
+ const DecoderWrapperFinalization = (typeof FinalizationRegistry === 'undefined')
177
+ ? { register: () => {}, unregister: () => {} }
178
+ : new FinalizationRegistry(ptr => wasm.__wbg_decoderwrapper_free(ptr >>> 0, 1));
179
+
180
+ export class DecoderWrapper {
181
+
182
+ static __wrap(ptr) {
183
+ ptr = ptr >>> 0;
184
+ const obj = Object.create(DecoderWrapper.prototype);
185
+ obj.__wbg_ptr = ptr;
186
+ DecoderWrapperFinalization.register(obj, obj.__wbg_ptr, obj);
187
+ return obj;
188
+ }
189
+
190
+ __destroy_into_raw() {
191
+ const ptr = this.__wbg_ptr;
192
+ this.__wbg_ptr = 0;
193
+ DecoderWrapperFinalization.unregister(this);
194
+ return ptr;
195
+ }
196
+
197
+ free() {
198
+ const ptr = this.__destroy_into_raw();
199
+ wasm.__wbg_decoderwrapper_free(ptr, 0);
200
+ }
201
+ constructor() {
202
+ const ret = wasm.decoderwrapper_new();
203
+ this.__wbg_ptr = ret >>> 0;
204
+ DecoderWrapperFinalization.register(this, this.__wbg_ptr, this);
205
+ return this;
206
+ }
207
+ /**
208
+ * @param {bigint} symbol
209
+ */
210
+ add_symbol(symbol) {
211
+ wasm.decoderwrapper_add_symbol(this.__wbg_ptr, symbol);
212
+ }
213
+ /**
214
+ * @param {any} coded_symbol_js
215
+ */
216
+ add_coded_symbol(coded_symbol_js) {
217
+ wasm.decoderwrapper_add_coded_symbol(this.__wbg_ptr, coded_symbol_js);
218
+ }
219
+ try_decode() {
220
+ const ret = wasm.decoderwrapper_try_decode(this.__wbg_ptr);
221
+ if (ret[1]) {
222
+ throw takeFromExternrefTable0(ret[0]);
223
+ }
224
+ }
225
+ /**
226
+ * @returns {boolean}
227
+ */
228
+ decoded() {
229
+ const ret = wasm.decoderwrapper_decoded(this.__wbg_ptr);
230
+ return ret !== 0;
231
+ }
232
+ /**
233
+ * @returns {Array<any>}
234
+ */
235
+ get_remote_symbols() {
236
+ const ret = wasm.decoderwrapper_get_remote_symbols(this.__wbg_ptr);
237
+ return ret;
238
+ }
239
+ /**
240
+ * @returns {Array<any>}
241
+ */
242
+ get_local_symbols() {
243
+ const ret = wasm.decoderwrapper_get_local_symbols(this.__wbg_ptr);
244
+ return ret;
245
+ }
246
+ reset() {
247
+ wasm.decoderwrapper_reset(this.__wbg_ptr);
248
+ }
249
+ }
250
+
251
+ const EncoderWrapperFinalization = (typeof FinalizationRegistry === 'undefined')
252
+ ? { register: () => {}, unregister: () => {} }
253
+ : new FinalizationRegistry(ptr => wasm.__wbg_encoderwrapper_free(ptr >>> 0, 1));
254
+
255
+ export class EncoderWrapper {
256
+
257
+ static __wrap(ptr) {
258
+ ptr = ptr >>> 0;
259
+ const obj = Object.create(EncoderWrapper.prototype);
260
+ obj.__wbg_ptr = ptr;
261
+ EncoderWrapperFinalization.register(obj, obj.__wbg_ptr, obj);
262
+ return obj;
263
+ }
264
+
265
+ __destroy_into_raw() {
266
+ const ptr = this.__wbg_ptr;
267
+ this.__wbg_ptr = 0;
268
+ EncoderWrapperFinalization.unregister(this);
269
+ return ptr;
270
+ }
271
+
272
+ free() {
273
+ const ptr = this.__destroy_into_raw();
274
+ wasm.__wbg_encoderwrapper_free(ptr, 0);
275
+ }
276
+ constructor() {
277
+ const ret = wasm.encoderwrapper_new();
278
+ this.__wbg_ptr = ret >>> 0;
279
+ EncoderWrapperFinalization.register(this, this.__wbg_ptr, this);
280
+ return this;
281
+ }
282
+ /**
283
+ * @param {bigint} symbol
284
+ */
285
+ add_symbol(symbol) {
286
+ wasm.encoderwrapper_add_symbol(this.__wbg_ptr, symbol);
287
+ }
288
+ /**
289
+ * @returns {any}
290
+ */
291
+ produce_next_coded_symbol() {
292
+ const ret = wasm.encoderwrapper_produce_next_coded_symbol(this.__wbg_ptr);
293
+ return ret;
294
+ }
295
+ reset() {
296
+ wasm.encoderwrapper_reset(this.__wbg_ptr);
297
+ }
298
+ /**
299
+ * @returns {DecoderWrapper}
300
+ */
301
+ to_decoder() {
302
+ const ret = wasm.encoderwrapper_to_decoder(this.__wbg_ptr);
303
+ return DecoderWrapper.__wrap(ret);
304
+ }
305
+ /**
306
+ * @returns {EncoderWrapper}
307
+ */
308
+ clone() {
309
+ const ret = wasm.encoderwrapper_clone(this.__wbg_ptr);
310
+ return EncoderWrapper.__wrap(ret);
311
+ }
312
+ }
313
+
314
+ async function __wbg_load(module, imports) {
315
+ if (typeof Response === 'function' && module instanceof Response) {
316
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
317
+ try {
318
+ return await WebAssembly.instantiateStreaming(module, imports);
319
+
320
+ } catch (e) {
321
+ if (module.headers.get('Content-Type') != 'application/wasm') {
322
+ 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);
323
+
324
+ } else {
325
+ throw e;
326
+ }
327
+ }
328
+ }
329
+
330
+ const bytes = await module.arrayBuffer();
331
+ return await WebAssembly.instantiate(bytes, imports);
332
+
333
+ } else {
334
+ const instance = await WebAssembly.instantiate(module, imports);
335
+
336
+ if (instance instanceof WebAssembly.Instance) {
337
+ return { instance, module };
338
+
339
+ } else {
340
+ return instance;
341
+ }
342
+ }
343
+ }
344
+
345
+ function __wbg_get_imports() {
346
+ const imports = {};
347
+ imports.wbg = {};
348
+ imports.wbg.__wbg_get_bbccf8970793c087 = function() { return handleError(function (arg0, arg1) {
349
+ const ret = Reflect.get(arg0, arg1);
350
+ return ret;
351
+ }, arguments) };
352
+ imports.wbg.__wbg_new_254fa9eac11932ae = function() {
353
+ const ret = new Array();
354
+ return ret;
355
+ };
356
+ imports.wbg.__wbg_new_688846f374351c92 = function() {
357
+ const ret = new Object();
358
+ return ret;
359
+ };
360
+ imports.wbg.__wbg_push_6edad0df4b546b2c = function(arg0, arg1) {
361
+ const ret = arg0.push(arg1);
362
+ return ret;
363
+ };
364
+ imports.wbg.__wbg_set_4e647025551483bd = function() { return handleError(function (arg0, arg1, arg2) {
365
+ const ret = Reflect.set(arg0, arg1, arg2);
366
+ return ret;
367
+ }, arguments) };
368
+ imports.wbg.__wbindgen_bigint_from_i64 = function(arg0) {
369
+ const ret = arg0;
370
+ return ret;
371
+ };
372
+ imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
373
+ const ret = BigInt.asUintN(64, arg0);
374
+ return ret;
375
+ };
376
+ imports.wbg.__wbindgen_bigint_get_as_i64 = function(arg0, arg1) {
377
+ const v = arg1;
378
+ const ret = typeof(v) === 'bigint' ? v : undefined;
379
+ getDataViewMemory0().setBigInt64(arg0 + 8 * 1, isLikeNone(ret) ? BigInt(0) : ret, true);
380
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
381
+ };
382
+ imports.wbg.__wbindgen_debug_string = function(arg0, arg1) {
383
+ const ret = debugString(arg1);
384
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
385
+ const len1 = WASM_VECTOR_LEN;
386
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
387
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
388
+ };
389
+ imports.wbg.__wbindgen_init_externref_table = function() {
390
+ const table = wasm.__wbindgen_export_2;
391
+ const offset = table.grow(4);
392
+ table.set(0, undefined);
393
+ table.set(offset + 0, undefined);
394
+ table.set(offset + 1, null);
395
+ table.set(offset + 2, true);
396
+ table.set(offset + 3, false);
397
+ ;
398
+ };
399
+ imports.wbg.__wbindgen_jsval_eq = function(arg0, arg1) {
400
+ const ret = arg0 === arg1;
401
+ return ret;
402
+ };
403
+ imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
404
+ const ret = getStringFromWasm0(arg0, arg1);
405
+ return ret;
406
+ };
407
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
408
+ throw new Error(getStringFromWasm0(arg0, arg1));
409
+ };
410
+
411
+ return imports;
412
+ }
413
+
414
+ function __wbg_init_memory(imports, memory) {
415
+
416
+ }
417
+
418
+ function __wbg_finalize_init(instance, module) {
419
+ wasm = instance.exports;
420
+ __wbg_init.__wbindgen_wasm_module = module;
421
+ cachedDataViewMemory0 = null;
422
+ cachedUint8ArrayMemory0 = null;
423
+
424
+
425
+ wasm.__wbindgen_start();
426
+ return wasm;
427
+ }
428
+
429
+ function initSync(module) {
430
+ if (wasm !== undefined) return wasm;
431
+
432
+
433
+ if (typeof module !== 'undefined') {
434
+ if (Object.getPrototypeOf(module) === Object.prototype) {
435
+ ({module} = module)
436
+ } else {
437
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
438
+ }
439
+ }
440
+
441
+ const imports = __wbg_get_imports();
442
+
443
+ __wbg_init_memory(imports);
444
+
445
+ if (!(module instanceof WebAssembly.Module)) {
446
+ module = new WebAssembly.Module(module);
447
+ }
448
+
449
+ const instance = new WebAssembly.Instance(module, imports);
450
+
451
+ return __wbg_finalize_init(instance, module);
452
+ }
453
+
454
+ async function __wbg_init(module_or_path) {
455
+ if (wasm !== undefined) return wasm;
456
+
457
+
458
+ if (typeof module_or_path !== 'undefined') {
459
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
460
+ ({module_or_path} = module_or_path)
461
+ } else {
462
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
463
+ }
464
+ }
465
+
466
+ if (typeof module_or_path === 'undefined') {
467
+ module_or_path = new URL('rateless_iblt_bg.wasm', import.meta.url);
468
+ }
469
+ const imports = __wbg_get_imports();
470
+
471
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
472
+ module_or_path = fetch(module_or_path);
473
+ }
474
+
475
+ __wbg_init_memory(imports);
476
+
477
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
478
+
479
+ return __wbg_finalize_init(instance, module);
480
+ }
481
+
482
+ export { initSync };
483
+ export default __wbg_init;
@@ -0,0 +1,4 @@
1
+ // nothing to do since 'fetch' works as expected in the browsere
2
+ import init from "./rateless_iblt.js";
3
+
4
+ init(new URL("/peerbit/rateless_iblt_bg.wasm", import.meta.url));
@@ -0,0 +1,17 @@
1
+ // Override globalThis.fetch to intercept .wasm requests
2
+ import { readFile } from "fs/promises";
3
+ import init from "./rateless_iblt.js";
4
+
5
+ const defaultFetch = globalThis.fetch.bind(globalThis);
6
+ globalThis.fetch = async (url, options) => {
7
+ // If you have multiple wasm files, you might use some logic to handle them.
8
+ // Here, we assume any request ending in `.wasm` is local on disk at the same path.
9
+ if (url.toString().endsWith(".wasm")) {
10
+ // Return a NodeResponse that looks enough like a fetch Response
11
+ return readFile(url);
12
+ }
13
+
14
+ return defaultFetch(url, options);
15
+ };
16
+
17
+ await init();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peerbit/riblt",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Riblt",
5
5
  "sideEffects": false,
6
6
  "type": "module",
@@ -31,6 +31,9 @@
31
31
  "import": "./dist/index.js"
32
32
  }
33
33
  },
34
+ "browser": {
35
+ "./dist/wasm-init.js": "./dist/wasm-init.browser.js"
36
+ },
34
37
  "eslintConfig": {
35
38
  "extends": "peerbit",
36
39
  "parserOptions": {
@@ -49,7 +52,8 @@
49
52
  "scripts": {
50
53
  "benchmark": "cargo bench",
51
54
  "clean": "cargo clear",
52
- "build": "wasm-pack build --target web --out-dir dist --out-name index && shx rm -rf ./dist/.gitignore && shx rm -rf ./dist/package.json",
55
+ "cp-src-js": "shx cp -r ./src_js/* ./dist",
56
+ "build": "wasm-pack build --target web --out-dir dist --out-name rateless_iblt && shx rm -rf ./dist/.gitignore && shx rm -rf ./dist/package.json && npm run cp-src-js",
53
57
  "test": "cargo test && aegir test",
54
58
  "lint": "cargo fmt"
55
59
  },
File without changes
File without changes