@addmaple/lz4 0.1.0 → 0.1.2
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/README.md +3 -2
- package/dist/browser-inline.d.ts +4 -1
- package/dist/browser-inline.js +16 -9
- package/dist/browser.d.ts +4 -1
- package/dist/browser.js +16 -9
- package/dist/core.d.ts +10 -2
- package/dist/core.js +163 -7
- package/dist/custom.js +330 -5
- package/dist/node-inline.d.ts +4 -1
- package/dist/node-inline.js +16 -9
- package/dist/node.d.ts +4 -1
- package/dist/node.js +14 -11
- package/dist/util.js +30 -0
- package/dist/wasm/lz4.base.wasm +0 -0
- package/dist/wasm/lz4.simd.wasm +0 -0
- package/dist/wasm-inline/lz4.base.wasm.js +1 -1
- package/dist/wasm-inline/lz4.simd.wasm.js +1 -1
- package/package.json +8 -5
package/dist/node-inline.js
CHANGED
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { setInstance, registerInit } from "./core.js";
|
|
2
|
-
import {
|
|
2
|
+
import { instantiateWithBackend } from "./util.js";
|
|
3
3
|
|
|
4
|
-
import { wasmBytes as
|
|
5
|
-
import { wasmBytes as
|
|
4
|
+
import { wasmBytes as _simdBytes } from "./wasm-inline/lz4.simd.wasm.js";
|
|
5
|
+
import { wasmBytes as _baseBytes } from "./wasm-inline/lz4.base.wasm.js";
|
|
6
6
|
|
|
7
|
-
async function
|
|
8
|
-
return
|
|
7
|
+
async function getSimdBytes() {
|
|
8
|
+
return _simdBytes;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function getBaseBytes() {
|
|
12
|
+
return _baseBytes;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
|
|
12
16
|
let _ready = null;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
let _backend = null;
|
|
18
|
+
export function init(imports = {}, opts = {}) {
|
|
19
|
+
const backend = opts.backend || 'auto';
|
|
20
|
+
if (_ready && _backend === backend) return _ready;
|
|
21
|
+
_backend = backend;
|
|
22
|
+
return (_ready = (async () => {
|
|
23
|
+
const { instance } = await instantiateWithBackend({ getSimdBytes, getBaseBytes, imports, backend });
|
|
17
24
|
setInstance(instance);
|
|
18
25
|
})());
|
|
19
26
|
}
|
package/dist/node.d.ts
CHANGED
package/dist/node.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { setInstance, registerInit } from "./core.js";
|
|
2
|
-
import {
|
|
2
|
+
import { instantiateWithBackend } from "./util.js";
|
|
3
3
|
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -7,20 +7,23 @@ import { fileURLToPath } from "node:url";
|
|
|
7
7
|
const simdPath = fileURLToPath(new URL("./wasm/lz4.simd.wasm", import.meta.url));
|
|
8
8
|
const basePath = fileURLToPath(new URL("./wasm/lz4.base.wasm", import.meta.url));
|
|
9
9
|
|
|
10
|
-
async function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
10
|
+
async function getSimdBytes() {
|
|
11
|
+
return readFile(simdPath);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function getBaseBytes() {
|
|
15
|
+
return readFile(basePath);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
let _ready = null;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
let _backend = null;
|
|
21
|
+
export function init(imports = {}, opts = {}) {
|
|
22
|
+
const backend = opts.backend || 'auto';
|
|
23
|
+
if (_ready && _backend === backend) return _ready;
|
|
24
|
+
_backend = backend;
|
|
25
|
+
return (_ready = (async () => {
|
|
26
|
+
const { instance } = await instantiateWithBackend({ getSimdBytes, getBaseBytes, imports, backend });
|
|
24
27
|
setInstance(instance);
|
|
25
28
|
})());
|
|
26
29
|
}
|
package/dist/util.js
CHANGED
|
@@ -12,3 +12,33 @@ export async function instantiateWithFallback(
|
|
|
12
12
|
return { instance, backend: 'wasm' }
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
export async function instantiateWithBackend({
|
|
17
|
+
getSimdBytes,
|
|
18
|
+
getBaseBytes,
|
|
19
|
+
imports,
|
|
20
|
+
backend = 'auto',
|
|
21
|
+
}) {
|
|
22
|
+
if (backend === 'base') {
|
|
23
|
+
const baseBytes = await getBaseBytes()
|
|
24
|
+
const { instance } = await WebAssembly.instantiate(baseBytes, imports)
|
|
25
|
+
return { instance, backend: 'wasm' }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (backend === 'simd') {
|
|
29
|
+
const simdBytes = await getSimdBytes()
|
|
30
|
+
const { instance } = await WebAssembly.instantiate(simdBytes, imports)
|
|
31
|
+
return { instance, backend: 'wasm-simd' }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// auto: try simd first, then fallback to baseline
|
|
35
|
+
try {
|
|
36
|
+
const simdBytes = await getSimdBytes()
|
|
37
|
+
const { instance } = await WebAssembly.instantiate(simdBytes, imports)
|
|
38
|
+
return { instance, backend: 'wasm-simd' }
|
|
39
|
+
} catch {
|
|
40
|
+
const baseBytes = await getBaseBytes()
|
|
41
|
+
const { instance } = await WebAssembly.instantiate(baseBytes, imports)
|
|
42
|
+
return { instance, backend: 'wasm' }
|
|
43
|
+
}
|
|
44
|
+
}
|
package/dist/wasm/lz4.base.wasm
CHANGED
|
Binary file
|
package/dist/wasm/lz4.simd.wasm
CHANGED
|
Binary file
|