You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default module will be exposed as UMD module. In browsers will be defined as `window.lz4init`
37
+
Since WASM modules can't be easily loaded synchronously in browsers some setup for initialization have to be proceed:
38
+
-`lz4init()` call will trigger asyncronous loading of `.wasm` file and return instance of lz4module
39
+
-`lz4module` accessible right after lz4init call, but the only safe method to ensure that `.wasm` file loading finished - wait for lz4module.ready Promise
40
+
-`lz4module.ready` Promise will return fully loaded lz4module instance that can be named `lz4`
41
+
- From usage perspective not really useful to work directly with `wasm` module, there is predefined `lz4.lz4js` property that contains all useful methods and helpers.
42
+
43
+
In short all this flow can be described with next code example:
44
+
```javascript
45
+
constlz4module=lz4init();
46
+
lz4module.ready.then((lz4) => {
47
+
constlz4js=lz4.lz4js;
48
+
})
49
+
```
50
+
51
+
Or even shorter with async/await and Object destructuring
52
+
```javascript
53
+
const { lz4js } =awaitlz4init().ready;
54
+
```
55
+
56
+
### Synchronouse module mode
57
+
58
+
First of all to compile sources in synchronous module mode - set `-s WASM_ASYNC_COMPILATION=0` option in `gulp/emscripten.js` file for `DEV_ARGS` variable.
59
+
60
+
Then in node env it can be accessed easily `const lz4 = lz4init();` that's it.
61
+
BUT! There is a big issue in browsers because WASM modules are restricted for synchronous load in main thread.
62
+
There are two ways to load it, both require to pass argument into init function `lz4init({ wasmBinary: wasmModuleAsArrayBuffer });` where wasmModuleAsArrayBuffer - preloaded file as ArrayBuffer in Uint8Array view representation:
63
+
1. Manually load/preload module through XHR/fetch, etc. then transform to arrayBuffer and call
Both `async` (default) and `sync` modes available for ASM.js module but with one important difference.
91
+
For `sync` variant there **NO NEED for any extra setup**. Set `-s WASM_ASYNC_COMPILATION=0` option in `gulp/emscripten.js` and simply use as:
92
+
```javascript
93
+
constlz4=lz4init();
94
+
```
95
+
96
+
It is much easier operate with ASM.js variant is sync mode, but for some cases it operate slower than WASM variant. You can see difference in tests if target different variants in top `require` statement.
97
+
32
98
## API
33
99
34
100
### static values
35
101
36
-
*`lz4.BLOCK_MAX_SIZE_64KB`
37
-
*`lz4.BLOCK_MAX_SIZE_256KB`
38
-
*`lz4.BLOCK_MAX_SIZE_1MB`
39
-
*`lz4.BLOCK_MAX_SIZE_4MB`
102
+
-`lz4.BLOCK_MAX_SIZE['64KB']`
103
+
-`lz4.BLOCK_MAX_SIZE['256KB']`
104
+
-`lz4.BLOCK_MAX_SIZE['1MB']`
105
+
-`lz4.BLOCK_MAX_SIZE['4MB']`
40
106
41
107
### lz4.compress(source, options)
42
108
43
109
compress to a lz4 buffer.
44
110
45
-
* source `Uint8Array | Buffer`
46
-
* options
47
-
* compressionLevel `number` (range of `0-16`, default is `0`)
48
-
* blockMaxSize `number` (`lz4.BLOCK_MAX_SIZE_XX`, default is `lz4.BLOCK_MAX_SIZE_4MB`)
49
-
* blockIndependent `boolean` (default is false)
50
-
* contentChecksum `boolean` (default is false)
51
-
* return `Uint8Array | Buffer`
111
+
- source `Uint8Array | Buffer`
112
+
- options
113
+
- frameInfo
114
+
- blockSizeID: `Number [4-7]` or as alias `lz4.BLOCK_MAX_SIZE["4MB"]`. Available sizes: `{ "64KB": 4, "256KB": 5, "1MB": 6, "4MB" 7 }`
0 commit comments