wao 0.9.2 → 0.10.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.
@@ -0,0 +1,264 @@
1
+ let wasm;
2
+
3
+ const heap = new Array(128).fill(undefined);
4
+
5
+ heap.push(undefined, null, true, false);
6
+
7
+ function getObject(idx) { return heap[idx]; }
8
+
9
+ let heap_next = heap.length;
10
+
11
+ function addHeapObject(obj) {
12
+ if (heap_next === heap.length) heap.push(heap.length + 1);
13
+ const idx = heap_next;
14
+ heap_next = heap[idx];
15
+
16
+ heap[idx] = obj;
17
+ return idx;
18
+ }
19
+
20
+ function dropObject(idx) {
21
+ if (idx < 132) return;
22
+ heap[idx] = heap_next;
23
+ heap_next = idx;
24
+ }
25
+
26
+ function takeObject(idx) {
27
+ const ret = getObject(idx);
28
+ dropObject(idx);
29
+ return ret;
30
+ }
31
+
32
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
33
+
34
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
35
+
36
+ let cachedUint8ArrayMemory0 = null;
37
+
38
+ function getUint8ArrayMemory0() {
39
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
40
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
41
+ }
42
+ return cachedUint8ArrayMemory0;
43
+ }
44
+
45
+ function getStringFromWasm0(ptr, len) {
46
+ ptr = ptr >>> 0;
47
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
48
+ }
49
+
50
+ let WASM_VECTOR_LEN = 0;
51
+
52
+ function passArray8ToWasm0(arg, malloc) {
53
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
54
+ getUint8ArrayMemory0().set(arg, ptr / 1);
55
+ WASM_VECTOR_LEN = arg.length;
56
+ return ptr;
57
+ }
58
+
59
+ const CompressorFinalization = (typeof FinalizationRegistry === 'undefined')
60
+ ? { register: () => {}, unregister: () => {} }
61
+ : new FinalizationRegistry(ptr => wasm.__wbg_compressor_free(ptr >>> 0, 1));
62
+
63
+ export class Compressor {
64
+
65
+ __destroy_into_raw() {
66
+ const ptr = this.__wbg_ptr;
67
+ this.__wbg_ptr = 0;
68
+ CompressorFinalization.unregister(this);
69
+ return ptr;
70
+ }
71
+
72
+ free() {
73
+ const ptr = this.__destroy_into_raw();
74
+ wasm.__wbg_compressor_free(ptr, 0);
75
+ }
76
+ constructor() {
77
+ const ret = wasm.compressor_new();
78
+ this.__wbg_ptr = ret >>> 0;
79
+ CompressorFinalization.register(this, this.__wbg_ptr, this);
80
+ return this;
81
+ }
82
+ /**
83
+ * @param {Uint8Array} data
84
+ * @returns {Uint8Array}
85
+ */
86
+ compress(data) {
87
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
88
+ const len0 = WASM_VECTOR_LEN;
89
+ const ret = wasm.compressor_compress(this.__wbg_ptr, ptr0, len0);
90
+ return takeObject(ret);
91
+ }
92
+ }
93
+
94
+ const DecompressorFinalization = (typeof FinalizationRegistry === 'undefined')
95
+ ? { register: () => {}, unregister: () => {} }
96
+ : new FinalizationRegistry(ptr => wasm.__wbg_decompressor_free(ptr >>> 0, 1));
97
+
98
+ export class Decompressor {
99
+
100
+ __destroy_into_raw() {
101
+ const ptr = this.__wbg_ptr;
102
+ this.__wbg_ptr = 0;
103
+ DecompressorFinalization.unregister(this);
104
+ return ptr;
105
+ }
106
+
107
+ free() {
108
+ const ptr = this.__destroy_into_raw();
109
+ wasm.__wbg_decompressor_free(ptr, 0);
110
+ }
111
+ constructor() {
112
+ const ret = wasm.compressor_new();
113
+ this.__wbg_ptr = ret >>> 0;
114
+ DecompressorFinalization.register(this, this.__wbg_ptr, this);
115
+ return this;
116
+ }
117
+ /**
118
+ * @param {Uint8Array} data
119
+ * @returns {Uint8Array}
120
+ */
121
+ decompress(data) {
122
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
123
+ const len0 = WASM_VECTOR_LEN;
124
+ const ret = wasm.decompressor_decompress(this.__wbg_ptr, ptr0, len0);
125
+ return takeObject(ret);
126
+ }
127
+ }
128
+
129
+ async function __wbg_load(module, imports) {
130
+ if (typeof Response === 'function' && module instanceof Response) {
131
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
132
+ try {
133
+ return await WebAssembly.instantiateStreaming(module, imports);
134
+
135
+ } catch (e) {
136
+ if (module.headers.get('Content-Type') != 'application/wasm') {
137
+ 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);
138
+
139
+ } else {
140
+ throw e;
141
+ }
142
+ }
143
+ }
144
+
145
+ const bytes = await module.arrayBuffer();
146
+ return await WebAssembly.instantiate(bytes, imports);
147
+
148
+ } else {
149
+ const instance = await WebAssembly.instantiate(module, imports);
150
+
151
+ if (instance instanceof WebAssembly.Instance) {
152
+ return { instance, module };
153
+
154
+ } else {
155
+ return instance;
156
+ }
157
+ }
158
+ }
159
+
160
+ function __wbg_get_imports() {
161
+ const imports = {};
162
+ imports.wbg = {};
163
+ imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
164
+ const ret = getObject(arg0).buffer;
165
+ return addHeapObject(ret);
166
+ };
167
+ imports.wbg.__wbg_length_a446193dc22c12f8 = function(arg0) {
168
+ const ret = getObject(arg0).length;
169
+ return ret;
170
+ };
171
+ imports.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
172
+ const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
173
+ return addHeapObject(ret);
174
+ };
175
+ imports.wbg.__wbg_newwithlength_a381634e90c276d4 = function(arg0) {
176
+ const ret = new Uint8Array(arg0 >>> 0);
177
+ return addHeapObject(ret);
178
+ };
179
+ imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
180
+ getObject(arg0).set(getObject(arg1), arg2 >>> 0);
181
+ };
182
+ imports.wbg.__wbindgen_memory = function() {
183
+ const ret = wasm.memory;
184
+ return addHeapObject(ret);
185
+ };
186
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
187
+ takeObject(arg0);
188
+ };
189
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
190
+ throw new Error(getStringFromWasm0(arg0, arg1));
191
+ };
192
+
193
+ return imports;
194
+ }
195
+
196
+ function __wbg_init_memory(imports, memory) {
197
+
198
+ }
199
+
200
+ function __wbg_finalize_init(instance, module) {
201
+ wasm = instance.exports;
202
+ __wbg_init.__wbindgen_wasm_module = module;
203
+ cachedUint8ArrayMemory0 = null;
204
+
205
+
206
+
207
+ return wasm;
208
+ }
209
+
210
+ function initSync(module) {
211
+ if (wasm !== undefined) return wasm;
212
+
213
+
214
+ if (typeof module !== 'undefined') {
215
+ if (Object.getPrototypeOf(module) === Object.prototype) {
216
+ ({module} = module)
217
+ } else {
218
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
219
+ }
220
+ }
221
+
222
+ const imports = __wbg_get_imports();
223
+
224
+ __wbg_init_memory(imports);
225
+
226
+ if (!(module instanceof WebAssembly.Module)) {
227
+ module = new WebAssembly.Module(module);
228
+ }
229
+
230
+ const instance = new WebAssembly.Instance(module, imports);
231
+
232
+ return __wbg_finalize_init(instance, module);
233
+ }
234
+
235
+ async function __wbg_init(module_or_path) {
236
+ if (wasm !== undefined) return wasm;
237
+
238
+
239
+ if (typeof module_or_path !== 'undefined') {
240
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
241
+ ({module_or_path} = module_or_path)
242
+ } else {
243
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
244
+ }
245
+ }
246
+
247
+ if (typeof module_or_path === 'undefined') {
248
+ module_or_path = new URL('waosm_bg.wasm', import.meta.url);
249
+ }
250
+ const imports = __wbg_get_imports();
251
+
252
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
253
+ module_or_path = fetch(module_or_path);
254
+ }
255
+
256
+ __wbg_init_memory(imports);
257
+
258
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
259
+
260
+ return __wbg_finalize_init(instance, module);
261
+ }
262
+
263
+ export { initSync };
264
+ export default __wbg_init;
Binary file
@@ -0,0 +1,10 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_compressor_free: (a: number, b: number) => void;
5
+ export const compressor_new: () => number;
6
+ export const compressor_compress: (a: number, b: number, c: number) => number;
7
+ export const decompressor_decompress: (a: number, b: number, c: number) => number;
8
+ export const __wbg_decompressor_free: (a: number, b: number) => void;
9
+ export const decompressor_new: () => number;
10
+ export const __wbindgen_malloc: (a: number, b: number) => number;
@@ -0,0 +1,79 @@
1
+ # Waosm Compressor
2
+
3
+ Waosm is a lightweight new compression algorithm to efficiently compress Wasm memory.
4
+
5
+ It is implemented in Rust and compiled to Wasm for better performance in browsers.
6
+
7
+ ```bash
8
+ yarn build
9
+ ```
10
+
11
+ Using Waosm in nodejs.
12
+
13
+ ```js
14
+ import init, { Compressor, Decompressor } from "../src/waosm-node.js"
15
+
16
+ const main = async ()=>{
17
+ await init()
18
+ const compressor = new Compressor()
19
+ const decompressor = new Decompressor()
20
+ const memory = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
21
+ console.log(memory)
22
+ const compressed = compressor.compress(memory)
23
+ console.log(compressed)
24
+ const decompressed = decompressor.decompress(compressed)
25
+ console.log(decompressed)
26
+ }
27
+ main()
28
+ ```
29
+
30
+ ## How Compression Works
31
+
32
+ Waosm Compression is a simple LRF variant that sequentially processes 8-bit integers. It is specifically optimized for zero-padded Wasm memory, achieving a 99% compression rate for largely idle WebAssembly memory. This enables efficient handling of large WebAssembly modules in browser environments.
33
+
34
+ The algorithm packs integers into chunks with 3 parts.
35
+
36
+ - flag
37
+ - 256-base number to tell the number of element in the current chunk
38
+ - actuall 8-bit intergers
39
+
40
+ ### Flag
41
+
42
+ A flag is a 1 byte (8 bits) integer, which ranges from 0 to 255. So there are 3 digits.
43
+
44
+ - 1st digit: `mode`
45
+ - `0`: a sequence of 0s
46
+ - `1`: a sequence of a single repeating 8 bit integer
47
+ - `2`: a sequence of multiple unique 8 bit integer
48
+ - 2nd digit:
49
+ - `0`: the 3rd digit is the number of elements, no 256-base number required in this case
50
+ - `1-9`: the number of integers to represent the 256-base number
51
+ - 3rd digit:
52
+ - if the 2nd digit is `0`, the 3rd digit represents the number of the elements, `0` represents `10`
53
+ - otherwise, the 3rd digit represents the first integer in the 256-base number representation
54
+
55
+ ### 256-Base Number
56
+
57
+ This part tells how many 8-bit integers are in the current chunk. For instance,
58
+ - `2, 200` = (256 ** 1 * 2) + 200 = 712
59
+ - `5, 50, 200` = (256 ** 2 * 5) + (256 ** 1 * 50) + 200 = 340680
60
+
61
+ Note that for space efficiency, the first integer is in the flag in some cases.
62
+
63
+ ### 8 Bit Elements
64
+
65
+ - `Mode 0`: no need for this part since we know it's a sequence of 0
66
+ - `Mode 1`: 1 integer to tell which integer of a sequence this chunk is
67
+ - `Mode 2`: the entire integers are required
68
+
69
+ ## Examples
70
+
71
+ `[ 1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]` (28 bytes)
72
+
73
+ - `204` | `-` | `1, 2, 3, 4`
74
+ - `103` | `-` | `5`
75
+ - `204` | `-` | `6, 7, 8, 9`
76
+ - `010` | `17` | `-`
77
+
78
+ It becomes `[204, 1, 2, 3, 4, 103, 5, 204, 6, 7, 8, 9, 10, 17]` (14 bytes - 50% compression rate).
79
+
@@ -0,0 +1,12 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export class Compressor {
4
+ free(): void;
5
+ constructor();
6
+ compress(data: Uint8Array): Uint8Array;
7
+ }
8
+ export class Decompressor {
9
+ free(): void;
10
+ constructor();
11
+ decompress(data: Uint8Array): Uint8Array;
12
+ }
@@ -0,0 +1,4 @@
1
+ import * as wasm from "./waosm_bg.wasm";
2
+ export * from "./waosm_bg.js";
3
+ import { __wbg_set_wasm } from "./waosm_bg.js";
4
+ __wbg_set_wasm(wasm);
@@ -0,0 +1,171 @@
1
+ let wasm;
2
+ export function __wbg_set_wasm(val) {
3
+ wasm = val;
4
+ }
5
+
6
+
7
+ const heap = new Array(128).fill(undefined);
8
+
9
+ heap.push(undefined, null, true, false);
10
+
11
+ function getObject(idx) { return heap[idx]; }
12
+
13
+ let heap_next = heap.length;
14
+
15
+ function addHeapObject(obj) {
16
+ if (heap_next === heap.length) heap.push(heap.length + 1);
17
+ const idx = heap_next;
18
+ heap_next = heap[idx];
19
+
20
+ heap[idx] = obj;
21
+ return idx;
22
+ }
23
+
24
+ function dropObject(idx) {
25
+ if (idx < 132) return;
26
+ heap[idx] = heap_next;
27
+ heap_next = idx;
28
+ }
29
+
30
+ function takeObject(idx) {
31
+ const ret = getObject(idx);
32
+ dropObject(idx);
33
+ return ret;
34
+ }
35
+
36
+ const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
37
+
38
+ let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
39
+
40
+ cachedTextDecoder.decode();
41
+
42
+ let cachedUint8ArrayMemory0 = null;
43
+
44
+ function getUint8ArrayMemory0() {
45
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
46
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
47
+ }
48
+ return cachedUint8ArrayMemory0;
49
+ }
50
+
51
+ function getStringFromWasm0(ptr, len) {
52
+ ptr = ptr >>> 0;
53
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
54
+ }
55
+
56
+ let WASM_VECTOR_LEN = 0;
57
+
58
+ function passArray8ToWasm0(arg, malloc) {
59
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
60
+ getUint8ArrayMemory0().set(arg, ptr / 1);
61
+ WASM_VECTOR_LEN = arg.length;
62
+ return ptr;
63
+ }
64
+
65
+ const CompressorFinalization = (typeof FinalizationRegistry === 'undefined')
66
+ ? { register: () => {}, unregister: () => {} }
67
+ : new FinalizationRegistry(ptr => wasm.__wbg_compressor_free(ptr >>> 0, 1));
68
+
69
+ export class Compressor {
70
+
71
+ __destroy_into_raw() {
72
+ const ptr = this.__wbg_ptr;
73
+ this.__wbg_ptr = 0;
74
+ CompressorFinalization.unregister(this);
75
+ return ptr;
76
+ }
77
+
78
+ free() {
79
+ const ptr = this.__destroy_into_raw();
80
+ wasm.__wbg_compressor_free(ptr, 0);
81
+ }
82
+ constructor() {
83
+ const ret = wasm.compressor_new();
84
+ this.__wbg_ptr = ret >>> 0;
85
+ CompressorFinalization.register(this, this.__wbg_ptr, this);
86
+ return this;
87
+ }
88
+ /**
89
+ * @param {Uint8Array} data
90
+ * @returns {Uint8Array}
91
+ */
92
+ compress(data) {
93
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
94
+ const len0 = WASM_VECTOR_LEN;
95
+ const ret = wasm.compressor_compress(this.__wbg_ptr, ptr0, len0);
96
+ return takeObject(ret);
97
+ }
98
+ }
99
+
100
+ const DecompressorFinalization = (typeof FinalizationRegistry === 'undefined')
101
+ ? { register: () => {}, unregister: () => {} }
102
+ : new FinalizationRegistry(ptr => wasm.__wbg_decompressor_free(ptr >>> 0, 1));
103
+
104
+ export class Decompressor {
105
+
106
+ __destroy_into_raw() {
107
+ const ptr = this.__wbg_ptr;
108
+ this.__wbg_ptr = 0;
109
+ DecompressorFinalization.unregister(this);
110
+ return ptr;
111
+ }
112
+
113
+ free() {
114
+ const ptr = this.__destroy_into_raw();
115
+ wasm.__wbg_decompressor_free(ptr, 0);
116
+ }
117
+ constructor() {
118
+ const ret = wasm.compressor_new();
119
+ this.__wbg_ptr = ret >>> 0;
120
+ DecompressorFinalization.register(this, this.__wbg_ptr, this);
121
+ return this;
122
+ }
123
+ /**
124
+ * @param {Uint8Array} data
125
+ * @returns {Uint8Array}
126
+ */
127
+ decompress(data) {
128
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
129
+ const len0 = WASM_VECTOR_LEN;
130
+ const ret = wasm.decompressor_decompress(this.__wbg_ptr, ptr0, len0);
131
+ return takeObject(ret);
132
+ }
133
+ }
134
+
135
+ export function __wbg_buffer_609cc3eee51ed158(arg0) {
136
+ const ret = getObject(arg0).buffer;
137
+ return addHeapObject(ret);
138
+ };
139
+
140
+ export function __wbg_length_a446193dc22c12f8(arg0) {
141
+ const ret = getObject(arg0).length;
142
+ return ret;
143
+ };
144
+
145
+ export function __wbg_newwithbyteoffsetandlength_d97e637ebe145a9a(arg0, arg1, arg2) {
146
+ const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
147
+ return addHeapObject(ret);
148
+ };
149
+
150
+ export function __wbg_newwithlength_a381634e90c276d4(arg0) {
151
+ const ret = new Uint8Array(arg0 >>> 0);
152
+ return addHeapObject(ret);
153
+ };
154
+
155
+ export function __wbg_set_65595bdd868b3009(arg0, arg1, arg2) {
156
+ getObject(arg0).set(getObject(arg1), arg2 >>> 0);
157
+ };
158
+
159
+ export function __wbindgen_memory() {
160
+ const ret = wasm.memory;
161
+ return addHeapObject(ret);
162
+ };
163
+
164
+ export function __wbindgen_object_drop_ref(arg0) {
165
+ takeObject(arg0);
166
+ };
167
+
168
+ export function __wbindgen_throw(arg0, arg1) {
169
+ throw new Error(getStringFromWasm0(arg0, arg1));
170
+ };
171
+
Binary file
@@ -0,0 +1,10 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_compressor_free: (a: number, b: number) => void;
5
+ export const compressor_new: () => number;
6
+ export const compressor_compress: (a: number, b: number, c: number) => number;
7
+ export const decompressor_decompress: (a: number, b: number, c: number) => number;
8
+ export const __wbg_decompressor_free: (a: number, b: number) => void;
9
+ export const decompressor_new: () => number;
10
+ export const __wbindgen_malloc: (a: number, b: number) => number;
@@ -0,0 +1,13 @@
1
+ export * from "./waosm-node/waosm_bg.js"
2
+ import * as wasmBindings from "./waosm-node/waosm_bg.js"
3
+ import { __wbg_set_wasm } from "./waosm-node/waosm_bg.js"
4
+ import { readFileSync } from "fs"
5
+ import { resolve } from "path"
6
+ const wasm = readFileSync(
7
+ resolve(import.meta.dirname, "./waosm-node/waosm_bg.wasm"),
8
+ )
9
+ const wasmModule = new WebAssembly.Module(wasm)
10
+ const wasmInstance = new WebAssembly.Instance(wasmModule, {
11
+ "./waosm_bg.js": wasmBindings,
12
+ })
13
+ __wbg_set_wasm(wasmInstance.exports)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wao",
3
- "version": "0.9.2",
3
+ "version": "0.10.1",
4
4
  "bin": {
5
5
  "wao": "./cjs/cli.js",
6
6
  "wao-esm": "./esm/cli.js"
@@ -27,6 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@babel/plugin-transform-modules-commonjs": "^7.24.8",
30
+ "@bokuweb/zstd-wasm": "^0.0.22",
30
31
  "@permaweb/ao-loader": "^0.0.44",
31
32
  "@permaweb/aoconnect": "^0.0.62",
32
33
  "arbundles": "^0.11.1",
@@ -39,8 +40,10 @@
39
40
  "graphql": "^16.10.0",
40
41
  "lmdb": "^3.2.2",
41
42
  "localforage": "^1.10.0",
43
+ "lz4-asm": "^0.4.2",
42
44
  "pm2": "^5.4.3",
43
45
  "ramda": "^0.30.1",
46
+ "wasm-brotli": "^2.0.2",
44
47
  "yargs": "^17.7.2"
45
48
  },
46
49
  "devDependencies": {