@icure/lzma-wasm 0.0.0-stage → 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.
package/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Taktik sa - B12 Consulting
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ The compiled WebAssembly module (dist/lzma.wasm) includes liblzma from
24
+ XZ Utils 5.6.4, which is licensed under the BSD Zero Clause License (0BSD).
25
+ See LICENSE.liblzma.
@@ -0,0 +1,11 @@
1
+ Permission to use, copy, modify, and/or distribute this
2
+ software for any purpose with or without fee is hereby granted.
3
+
4
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
5
+ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
6
+ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
7
+ THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
8
+ CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
9
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
10
+ NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
11
+ CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,44 @@
1
- # Temporary Holding Version
1
+ # @icure/lzma-wasm
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ LZMA2 / XZ compression and decompression for browsers, web workers and Node.js, using
4
+ [liblzma](https://tukaani.org/xz/) (XZ Utils 5.6.4) compiled to WebAssembly with Emscripten.
5
+
6
+ Output is a standard `.xz` stream (LZMA2 filter, CRC64 check) that interoperates with the `xz` CLI.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install @icure/lzma-wasm
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ts
17
+ import { lzmaWasmCompress, lzmaWasmDecompress } from '@icure/lzma-wasm'
18
+
19
+ const compressed: ArrayBuffer = await lzmaWasmCompress(new TextEncoder().encode('hello'), 6) // preset 0-9, default 6
20
+ const decompressed: ArrayBuffer = await lzmaWasmDecompress(compressed)
21
+ ```
22
+
23
+ Both functions accept an `ArrayBuffer` or a `Uint8Array` and never modify their input.
24
+ The WASM module is loaded lazily on first call. `getLzmaModule()` gives access to the raw Emscripten module.
25
+
26
+ ### Bundlers
27
+
28
+ `dist/lzma.js` locates `lzma.wasm` next to itself. When bundling for the browser, make sure
29
+ `lzma.wasm` is emitted as an asset alongside the bundled glue code (e.g. webpack `asset/resource`,
30
+ or copy it to your public directory).
31
+
32
+ ## Rebuilding the WASM module
33
+
34
+ The prebuilt `src/lzma.js` and `src/lzma.wasm` are committed. To rebuild them you need
35
+ [Emscripten](https://emscripten.org/) (`emcc`) on your `PATH`:
36
+
37
+ ```bash
38
+ npm run build:wasm # downloads xz 5.6.4 into src/build, compiles src/lzma_wasm.c + liblzma
39
+ npm test
40
+ ```
41
+
42
+ ## License
43
+
44
+ MIT for the code in this repository. liblzma is 0BSD (see `LICENSE.liblzma`).
@@ -0,0 +1,21 @@
1
+ /**
2
+ * WASM-based LZMA2/XZ compression using liblzma compiled via Emscripten.
3
+ * The WASM module is lazy-loaded on first use.
4
+ */
5
+ import type { LzmaWasmModule } from './lzma.js';
6
+ export type { LzmaWasmModule };
7
+ /**
8
+ * Returns the (lazily instantiated) raw Emscripten module, for advanced use.
9
+ */
10
+ export declare function getLzmaModule(): Promise<LzmaWasmModule>;
11
+ /**
12
+ * Compresses data into the .xz container format (LZMA2 filter, CRC64 check).
13
+ * @param data the data to compress
14
+ * @param preset the xz preset level (0-9), defaults to 6
15
+ */
16
+ export declare function lzmaWasmCompress(data: ArrayBuffer | Uint8Array, preset?: number): Promise<ArrayBuffer>;
17
+ /**
18
+ * Decompresses data in the .xz container format.
19
+ * @param data the compressed data
20
+ */
21
+ export declare function lzmaWasmDecompress(data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer>;
package/dist/index.js ADDED
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /**
3
+ * WASM-based LZMA2/XZ compression using liblzma compiled via Emscripten.
4
+ * The WASM module is lazy-loaded on first use.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getLzmaModule = getLzmaModule;
8
+ exports.lzmaWasmCompress = lzmaWasmCompress;
9
+ exports.lzmaWasmDecompress = lzmaWasmDecompress;
10
+ let modulePromise = null;
11
+ /**
12
+ * Returns the (lazily instantiated) raw Emscripten module, for advanced use.
13
+ */
14
+ function getLzmaModule() {
15
+ if (!modulePromise) {
16
+ modulePromise = (async () => {
17
+ // Dynamic import of the Emscripten glue code
18
+ const factory = (await Promise.resolve().then(() => require('./lzma.js'))).default;
19
+ return factory();
20
+ })();
21
+ }
22
+ return modulePromise;
23
+ }
24
+ function run(mod, input, op, call) {
25
+ const inputPtr = mod._malloc(input.length);
26
+ if (!inputPtr)
27
+ throw new Error('WASM malloc failed for input');
28
+ try {
29
+ mod.HEAPU8.set(input, inputPtr);
30
+ const ret = call(inputPtr, input.length);
31
+ if (ret !== 0) {
32
+ mod._free_result();
33
+ throw new Error(`LZMA WASM ${op} failed with code ${ret}`);
34
+ }
35
+ const resultPtr = mod._get_result_ptr();
36
+ const resultLen = mod._get_result_len();
37
+ const output = new Uint8Array(resultLen);
38
+ output.set(mod.HEAPU8.subarray(resultPtr, resultPtr + resultLen));
39
+ mod._free_result();
40
+ return output.buffer;
41
+ }
42
+ finally {
43
+ mod._free(inputPtr);
44
+ }
45
+ }
46
+ /**
47
+ * Compresses data into the .xz container format (LZMA2 filter, CRC64 check).
48
+ * @param data the data to compress
49
+ * @param preset the xz preset level (0-9), defaults to 6
50
+ */
51
+ async function lzmaWasmCompress(data, preset = 6) {
52
+ const mod = await getLzmaModule();
53
+ const input = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
54
+ return run(mod, input, 'compress', (ptr, len) => mod._lzma_wasm_compress(ptr, len, preset));
55
+ }
56
+ /**
57
+ * Decompresses data in the .xz container format.
58
+ * @param data the compressed data
59
+ */
60
+ async function lzmaWasmDecompress(data) {
61
+ const mod = await getLzmaModule();
62
+ const input = data instanceof ArrayBuffer ? new Uint8Array(data) : data;
63
+ return run(mod, input, 'decompress', (ptr, len) => mod._lzma_wasm_decompress(ptr, len));
64
+ }
65
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAWH,sCASC;AA8BD,4CAIC;AAMD,gDAIC;AA1DD,IAAI,aAAa,GAAmC,IAAI,CAAA;AAExD;;GAEG;AACH,SAAgB,aAAa;IAC3B,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,CAAC,KAAK,IAAI,EAAE;YAC1B,6CAA6C;YAC7C,MAAM,OAAO,GAAkC,CAAC,2CAAa,WAAW,EAAC,CAAC,CAAC,OAAO,CAAA;YAClF,OAAO,OAAO,EAAE,CAAA;QAClB,CAAC,CAAC,EAAE,CAAA;IACN,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC;AAED,SAAS,GAAG,CAAC,GAAmB,EAAE,KAAiB,EAAE,EAA6B,EAAE,IAA0C;IAC5H,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;IAC1C,IAAI,CAAC,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IAE9D,IAAI,CAAC;QACH,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;QAC/B,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QACxC,IAAI,GAAG,KAAK,CAAC,EAAE,CAAC;YACd,GAAG,CAAC,YAAY,EAAE,CAAA;YAClB,MAAM,IAAI,KAAK,CAAC,aAAa,EAAE,qBAAqB,GAAG,EAAE,CAAC,CAAA;QAC5D,CAAC;QAED,MAAM,SAAS,GAAG,GAAG,CAAC,eAAe,EAAE,CAAA;QACvC,MAAM,SAAS,GAAG,GAAG,CAAC,eAAe,EAAE,CAAA;QACvC,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAA;QACxC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC,CAAC,CAAA;QACjE,GAAG,CAAC,YAAY,EAAE,CAAA;QAClB,OAAO,MAAM,CAAC,MAAM,CAAA;IACtB,CAAC;YAAS,CAAC;QACT,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IACrB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACI,KAAK,UAAU,gBAAgB,CAAC,IAA8B,EAAE,SAAiB,CAAC;IACvF,MAAM,GAAG,GAAG,MAAM,aAAa,EAAE,CAAA;IACjC,MAAM,KAAK,GAAG,IAAI,YAAY,WAAW,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACvE,OAAO,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAA;AAC7F,CAAC;AAED;;;GAGG;AACI,KAAK,UAAU,kBAAkB,CAAC,IAA8B;IACrE,MAAM,GAAG,GAAG,MAAM,aAAa,EAAE,CAAA;IACjC,MAAM,KAAK,GAAG,IAAI,YAAY,WAAW,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACvE,OAAO,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,qBAAqB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AACzF,CAAC","sourcesContent":["/**\n * WASM-based LZMA2/XZ compression using liblzma compiled via Emscripten.\n * The WASM module is lazy-loaded on first use.\n */\n\nimport type { LzmaWasmModule } from './lzma.js'\n\nexport type { LzmaWasmModule }\n\nlet modulePromise: Promise<LzmaWasmModule> | null = null\n\n/**\n * Returns the (lazily instantiated) raw Emscripten module, for advanced use.\n */\nexport function getLzmaModule(): Promise<LzmaWasmModule> {\n if (!modulePromise) {\n modulePromise = (async () => {\n // Dynamic import of the Emscripten glue code\n const factory: () => Promise<LzmaWasmModule> = (await import('./lzma.js')).default\n return factory()\n })()\n }\n return modulePromise\n}\n\nfunction run(mod: LzmaWasmModule, input: Uint8Array, op: 'compress' | 'decompress', call: (ptr: number, len: number) => number): ArrayBuffer {\n const inputPtr = mod._malloc(input.length)\n if (!inputPtr) throw new Error('WASM malloc failed for input')\n\n try {\n mod.HEAPU8.set(input, inputPtr)\n const ret = call(inputPtr, input.length)\n if (ret !== 0) {\n mod._free_result()\n throw new Error(`LZMA WASM ${op} failed with code ${ret}`)\n }\n\n const resultPtr = mod._get_result_ptr()\n const resultLen = mod._get_result_len()\n const output = new Uint8Array(resultLen)\n output.set(mod.HEAPU8.subarray(resultPtr, resultPtr + resultLen))\n mod._free_result()\n return output.buffer\n } finally {\n mod._free(inputPtr)\n }\n}\n\n/**\n * Compresses data into the .xz container format (LZMA2 filter, CRC64 check).\n * @param data the data to compress\n * @param preset the xz preset level (0-9), defaults to 6\n */\nexport async function lzmaWasmCompress(data: ArrayBuffer | Uint8Array, preset: number = 6): Promise<ArrayBuffer> {\n const mod = await getLzmaModule()\n const input = data instanceof ArrayBuffer ? new Uint8Array(data) : data\n return run(mod, input, 'compress', (ptr, len) => mod._lzma_wasm_compress(ptr, len, preset))\n}\n\n/**\n * Decompresses data in the .xz container format.\n * @param data the compressed data\n */\nexport async function lzmaWasmDecompress(data: ArrayBuffer | Uint8Array): Promise<ArrayBuffer> {\n const mod = await getLzmaModule()\n const input = data instanceof ArrayBuffer ? new Uint8Array(data) : data\n return run(mod, input, 'decompress', (ptr, len) => mod._lzma_wasm_decompress(ptr, len))\n}\n"]}
package/dist/lzma.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export interface LzmaWasmModule {
2
+ _lzma_wasm_compress(ptr: number, len: number, preset: number): number
3
+ _lzma_wasm_decompress(ptr: number, len: number): number
4
+ _get_result_ptr(): number
5
+ _get_result_len(): number
6
+ _free_result(): void
7
+ _malloc(size: number): number
8
+ _free(ptr: number): void
9
+ HEAPU8: Uint8Array
10
+ }
11
+
12
+ declare function createLzmaModule(): Promise<LzmaWasmModule>
13
+ export default createLzmaModule
package/dist/lzma.js ADDED
@@ -0,0 +1,507 @@
1
+ var createLzmaModule = (() => {
2
+ var _scriptName = globalThis.document?.currentScript?.src;
3
+ return async function (moduleArg = {}) {
4
+ var moduleRtn;
5
+ var Module = moduleArg;
6
+ var ENVIRONMENT_IS_WEB = !!globalThis.window;
7
+ var ENVIRONMENT_IS_WORKER = !!globalThis.WorkerGlobalScope;
8
+ var ENVIRONMENT_IS_NODE = globalThis.process?.versions?.node && globalThis.process?.type != "renderer";
9
+ var arguments_ = [];
10
+ var thisProgram = "./this.program";
11
+ var quit_ = (status, toThrow) => {
12
+ throw toThrow
13
+ };
14
+ if (typeof __filename != "undefined") {
15
+ _scriptName = __filename
16
+ } else if (ENVIRONMENT_IS_WORKER) {
17
+ _scriptName = self.location.href
18
+ }
19
+ var scriptDirectory = "";
20
+
21
+ function locateFile(path) {
22
+ if (Module["locateFile"]) {
23
+ return Module["locateFile"](path, scriptDirectory)
24
+ }
25
+ return scriptDirectory + path
26
+ }
27
+
28
+ var readAsync, readBinary;
29
+ if (ENVIRONMENT_IS_NODE) {
30
+ // Aliased require so bundlers (esbuild/webpack on Vercel, Next.js, ...) don't try to
31
+ // statically resolve the Node-only "node:fs" builtin when bundling for the browser/edge.
32
+ // This branch only runs under Node, where `require` is available.
33
+ var nodeRequire = typeof require === "function" ? require : undefined;
34
+ var fs = nodeRequire("node:fs");
35
+ scriptDirectory = __dirname + "/";
36
+ readBinary = filename => {
37
+ filename = isFileURI(filename) ? new URL(filename) : filename;
38
+ var ret = fs.readFileSync(filename);
39
+ return ret
40
+ };
41
+ readAsync = async (filename, binary = true) => {
42
+ filename = isFileURI(filename) ? new URL(filename) : filename;
43
+ var ret = fs.readFileSync(filename, binary ? undefined : "utf8");
44
+ return ret
45
+ };
46
+ if (process.argv.length > 1) {
47
+ thisProgram = process.argv[1].replace(/\\/g, "/")
48
+ }
49
+ arguments_ = process.argv.slice(2);
50
+ quit_ = (status, toThrow) => {
51
+ process.exitCode = status;
52
+ throw toThrow
53
+ }
54
+ } else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
55
+ try {
56
+ scriptDirectory = new URL(".", _scriptName).href
57
+ } catch {
58
+ }
59
+ {
60
+ if (ENVIRONMENT_IS_WORKER) {
61
+ readBinary = url => {
62
+ var xhr = new XMLHttpRequest;
63
+ xhr.open("GET", url, false);
64
+ xhr.responseType = "arraybuffer";
65
+ xhr.send(null);
66
+ return new Uint8Array(xhr.response)
67
+ }
68
+ }
69
+ readAsync = async url => {
70
+ var response = await fetch(url, {credentials: "same-origin"});
71
+ if (response.ok) {
72
+ return response.arrayBuffer()
73
+ }
74
+ throw new Error(response.status + " : " + response.url)
75
+ }
76
+ }
77
+ } else {
78
+ }
79
+ var out = console.log.bind(console);
80
+ var err = console.error.bind(console);
81
+ var wasmBinary;
82
+ var ABORT = false;
83
+ var isFileURI = filename => filename.startsWith("file://");
84
+ var readyPromiseResolve, readyPromiseReject;
85
+ var HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64;
86
+ var HEAP64, HEAPU64;
87
+ var runtimeInitialized = false;
88
+
89
+ function updateMemoryViews() {
90
+ var b = wasmMemory.buffer;
91
+ HEAP8 = new Int8Array(b);
92
+ HEAP16 = new Int16Array(b);
93
+ Module["HEAPU8"] = HEAPU8 = new Uint8Array(b);
94
+ HEAPU16 = new Uint16Array(b);
95
+ HEAP32 = new Int32Array(b);
96
+ HEAPU32 = new Uint32Array(b);
97
+ HEAPF32 = new Float32Array(b);
98
+ HEAPF64 = new Float64Array(b);
99
+ HEAP64 = new BigInt64Array(b);
100
+ HEAPU64 = new BigUint64Array(b)
101
+ }
102
+
103
+ function preRun() {
104
+ if (Module["preRun"]) {
105
+ if (typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]];
106
+ while (Module["preRun"].length) {
107
+ addOnPreRun(Module["preRun"].shift())
108
+ }
109
+ }
110
+ callRuntimeCallbacks(onPreRuns)
111
+ }
112
+
113
+ function initRuntime() {
114
+ runtimeInitialized = true;
115
+ wasmExports["c"]()
116
+ }
117
+
118
+ function postRun() {
119
+ if (Module["postRun"]) {
120
+ if (typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]];
121
+ while (Module["postRun"].length) {
122
+ addOnPostRun(Module["postRun"].shift())
123
+ }
124
+ }
125
+ callRuntimeCallbacks(onPostRuns)
126
+ }
127
+
128
+ function abort(what) {
129
+ Module["onAbort"]?.(what);
130
+ what = "Aborted(" + what + ")";
131
+ err(what);
132
+ ABORT = true;
133
+ what += ". Build with -sASSERTIONS for more info.";
134
+ var e = new WebAssembly.RuntimeError(what);
135
+ readyPromiseReject?.(e);
136
+ throw e
137
+ }
138
+
139
+ var wasmBinaryFile;
140
+
141
+ function findWasmBinary() {
142
+ return locateFile("lzma.wasm")
143
+ }
144
+
145
+ function getBinarySync(file) {
146
+ if (file == wasmBinaryFile && wasmBinary) {
147
+ return new Uint8Array(wasmBinary)
148
+ }
149
+ if (readBinary) {
150
+ return readBinary(file)
151
+ }
152
+ throw "both async and sync fetching of the wasm failed"
153
+ }
154
+
155
+ async function getWasmBinary(binaryFile) {
156
+ if (!wasmBinary) {
157
+ try {
158
+ var response = await readAsync(binaryFile);
159
+ return new Uint8Array(response)
160
+ } catch {
161
+ }
162
+ }
163
+ return getBinarySync(binaryFile)
164
+ }
165
+
166
+ async function instantiateArrayBuffer(binaryFile, imports) {
167
+ try {
168
+ var binary = await getWasmBinary(binaryFile);
169
+ var instance = await WebAssembly.instantiate(binary, imports);
170
+ return instance
171
+ } catch (reason) {
172
+ err(`failed to asynchronously prepare wasm: ${reason}`);
173
+ abort(reason)
174
+ }
175
+ }
176
+
177
+ async function instantiateAsync(binary, binaryFile, imports) {
178
+ if (!binary && !ENVIRONMENT_IS_NODE) {
179
+ try {
180
+ var response = fetch(binaryFile, {credentials: "same-origin"});
181
+ var instantiationResult = await WebAssembly.instantiateStreaming(response, imports);
182
+ return instantiationResult
183
+ } catch (reason) {
184
+ err(`wasm streaming compile failed: ${reason}`);
185
+ err("falling back to ArrayBuffer instantiation")
186
+ }
187
+ }
188
+ return instantiateArrayBuffer(binaryFile, imports)
189
+ }
190
+
191
+ function getWasmImports() {
192
+ var imports = {a: wasmImports};
193
+ return imports
194
+ }
195
+
196
+ async function createWasm() {
197
+ function receiveInstance(instance, module) {
198
+ wasmExports = instance.exports;
199
+ assignWasmExports(wasmExports);
200
+ updateMemoryViews();
201
+ return wasmExports
202
+ }
203
+
204
+ function receiveInstantiationResult(result) {
205
+ return receiveInstance(result["instance"])
206
+ }
207
+
208
+ var info = getWasmImports();
209
+ if (Module["instantiateWasm"]) {
210
+ return new Promise((resolve, reject) => {
211
+ Module["instantiateWasm"](info, (inst, mod) => {
212
+ resolve(receiveInstance(inst, mod))
213
+ })
214
+ })
215
+ }
216
+ wasmBinaryFile ??= findWasmBinary();
217
+ var result = await instantiateAsync(wasmBinary, wasmBinaryFile, info);
218
+ var exports = receiveInstantiationResult(result);
219
+ return exports
220
+ }
221
+
222
+ class ExitStatus {
223
+ name = "ExitStatus";
224
+
225
+ constructor(status) {
226
+ this.message = `Program terminated with exit(${status})`;
227
+ this.status = status
228
+ }
229
+ }
230
+
231
+ var callRuntimeCallbacks = callbacks => {
232
+ while (callbacks.length > 0) {
233
+ callbacks.shift()(Module)
234
+ }
235
+ };
236
+ var onPostRuns = [];
237
+ var addOnPostRun = cb => onPostRuns.push(cb);
238
+ var onPreRuns = [];
239
+ var addOnPreRun = cb => onPreRuns.push(cb);
240
+ var noExitRuntime = true;
241
+ var stackRestore = val => __emscripten_stack_restore(val);
242
+ var stackSave = () => _emscripten_stack_get_current();
243
+ var getHeapMax = () => 2147483648;
244
+ var alignMemory = (size, alignment) => Math.ceil(size / alignment) * alignment;
245
+ var growMemory = size => {
246
+ var oldHeapSize = wasmMemory.buffer.byteLength;
247
+ var pages = (size - oldHeapSize + 65535) / 65536 | 0;
248
+ try {
249
+ wasmMemory.grow(pages);
250
+ updateMemoryViews();
251
+ return 1
252
+ } catch (e) {
253
+ }
254
+ };
255
+ var _emscripten_resize_heap = requestedSize => {
256
+ var oldSize = HEAPU8.length;
257
+ requestedSize >>>= 0;
258
+ var maxHeapSize = getHeapMax();
259
+ if (requestedSize > maxHeapSize) {
260
+ return false
261
+ }
262
+ for (var cutDown = 1; cutDown <= 4; cutDown *= 2) {
263
+ var overGrownHeapSize = oldSize * (1 + .2 / cutDown);
264
+ overGrownHeapSize = Math.min(overGrownHeapSize, requestedSize + 100663296);
265
+ var newSize = Math.min(maxHeapSize, alignMemory(Math.max(requestedSize, overGrownHeapSize), 65536));
266
+ var replacement = growMemory(newSize);
267
+ if (replacement) {
268
+ return true
269
+ }
270
+ }
271
+ return false
272
+ };
273
+ var getCFunc = ident => {
274
+ var func = Module["_" + ident];
275
+ return func
276
+ };
277
+ var writeArrayToMemory = (array, buffer) => {
278
+ HEAP8.set(array, buffer)
279
+ };
280
+ var lengthBytesUTF8 = str => {
281
+ var len = 0;
282
+ for (var i = 0; i < str.length; ++i) {
283
+ var c = str.charCodeAt(i);
284
+ if (c <= 127) {
285
+ len++
286
+ } else if (c <= 2047) {
287
+ len += 2
288
+ } else if (c >= 55296 && c <= 57343) {
289
+ len += 4;
290
+ ++i
291
+ } else {
292
+ len += 3
293
+ }
294
+ }
295
+ return len
296
+ };
297
+ var stringToUTF8Array = (str, heap, outIdx, maxBytesToWrite) => {
298
+ if (!(maxBytesToWrite > 0)) return 0;
299
+ var startIdx = outIdx;
300
+ var endIdx = outIdx + maxBytesToWrite - 1;
301
+ for (var i = 0; i < str.length; ++i) {
302
+ var u = str.codePointAt(i);
303
+ if (u <= 127) {
304
+ if (outIdx >= endIdx) break;
305
+ heap[outIdx++] = u
306
+ } else if (u <= 2047) {
307
+ if (outIdx + 1 >= endIdx) break;
308
+ heap[outIdx++] = 192 | u >> 6;
309
+ heap[outIdx++] = 128 | u & 63
310
+ } else if (u <= 65535) {
311
+ if (outIdx + 2 >= endIdx) break;
312
+ heap[outIdx++] = 224 | u >> 12;
313
+ heap[outIdx++] = 128 | u >> 6 & 63;
314
+ heap[outIdx++] = 128 | u & 63
315
+ } else {
316
+ if (outIdx + 3 >= endIdx) break;
317
+ heap[outIdx++] = 240 | u >> 18;
318
+ heap[outIdx++] = 128 | u >> 12 & 63;
319
+ heap[outIdx++] = 128 | u >> 6 & 63;
320
+ heap[outIdx++] = 128 | u & 63;
321
+ i++
322
+ }
323
+ }
324
+ heap[outIdx] = 0;
325
+ return outIdx - startIdx
326
+ };
327
+ var stringToUTF8 = (str, outPtr, maxBytesToWrite) => stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite);
328
+ var stackAlloc = sz => __emscripten_stack_alloc(sz);
329
+ var stringToUTF8OnStack = str => {
330
+ var size = lengthBytesUTF8(str) + 1;
331
+ var ret = stackAlloc(size);
332
+ stringToUTF8(str, ret, size);
333
+ return ret
334
+ };
335
+ var UTF8Decoder = globalThis.TextDecoder && new TextDecoder;
336
+ var findStringEnd = (heapOrArray, idx, maxBytesToRead, ignoreNul) => {
337
+ var maxIdx = idx + maxBytesToRead;
338
+ if (ignoreNul) return maxIdx;
339
+ while (heapOrArray[idx] && !(idx >= maxIdx)) ++idx;
340
+ return idx
341
+ };
342
+ var UTF8ArrayToString = (heapOrArray, idx = 0, maxBytesToRead, ignoreNul) => {
343
+ var endPtr = findStringEnd(heapOrArray, idx, maxBytesToRead, ignoreNul);
344
+ if (endPtr - idx > 16 && heapOrArray.buffer && UTF8Decoder) {
345
+ return UTF8Decoder.decode(heapOrArray.subarray(idx, endPtr))
346
+ }
347
+ var str = "";
348
+ while (idx < endPtr) {
349
+ var u0 = heapOrArray[idx++];
350
+ if (!(u0 & 128)) {
351
+ str += String.fromCharCode(u0);
352
+ continue
353
+ }
354
+ var u1 = heapOrArray[idx++] & 63;
355
+ if ((u0 & 224) == 192) {
356
+ str += String.fromCharCode((u0 & 31) << 6 | u1);
357
+ continue
358
+ }
359
+ var u2 = heapOrArray[idx++] & 63;
360
+ if ((u0 & 240) == 224) {
361
+ u0 = (u0 & 15) << 12 | u1 << 6 | u2
362
+ } else {
363
+ u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | heapOrArray[idx++] & 63
364
+ }
365
+ if (u0 < 65536) {
366
+ str += String.fromCharCode(u0)
367
+ } else {
368
+ var ch = u0 - 65536;
369
+ str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023)
370
+ }
371
+ }
372
+ return str
373
+ };
374
+ var UTF8ToString = (ptr, maxBytesToRead, ignoreNul) => ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead, ignoreNul) : "";
375
+ var ccall = (ident, returnType, argTypes, args, opts) => {
376
+ var toC = {
377
+ string: str => {
378
+ var ret = 0;
379
+ if (str !== null && str !== undefined && str !== 0) {
380
+ ret = stringToUTF8OnStack(str)
381
+ }
382
+ return ret
383
+ }, array: arr => {
384
+ var ret = stackAlloc(arr.length);
385
+ writeArrayToMemory(arr, ret);
386
+ return ret
387
+ }
388
+ };
389
+
390
+ function convertReturnValue(ret) {
391
+ if (returnType === "string") {
392
+ return UTF8ToString(ret)
393
+ }
394
+ if (returnType === "boolean") return Boolean(ret);
395
+ return ret
396
+ }
397
+
398
+ var func = getCFunc(ident);
399
+ var cArgs = [];
400
+ var stack = 0;
401
+ if (args) {
402
+ for (var i = 0; i < args.length; i++) {
403
+ var converter = toC[argTypes[i]];
404
+ if (converter) {
405
+ if (stack === 0) stack = stackSave();
406
+ cArgs[i] = converter(args[i])
407
+ } else {
408
+ cArgs[i] = args[i]
409
+ }
410
+ }
411
+ }
412
+ var ret = func(...cArgs);
413
+
414
+ function onDone(ret) {
415
+ if (stack !== 0) stackRestore(stack);
416
+ return convertReturnValue(ret)
417
+ }
418
+
419
+ ret = onDone(ret);
420
+ return ret
421
+ };
422
+ var cwrap = (ident, returnType, argTypes, opts) => {
423
+ var numericArgs = !argTypes || argTypes.every(type => type === "number" || type === "boolean");
424
+ var numericRet = returnType !== "string";
425
+ if (numericRet && numericArgs && !opts) {
426
+ return getCFunc(ident)
427
+ }
428
+ return (...args) => ccall(ident, returnType, argTypes, args, opts)
429
+ };
430
+ {
431
+ if (Module["noExitRuntime"]) noExitRuntime = Module["noExitRuntime"];
432
+ if (Module["print"]) out = Module["print"];
433
+ if (Module["printErr"]) err = Module["printErr"];
434
+ if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"];
435
+ if (Module["arguments"]) arguments_ = Module["arguments"];
436
+ if (Module["thisProgram"]) thisProgram = Module["thisProgram"];
437
+ if (Module["preInit"]) {
438
+ if (typeof Module["preInit"] == "function") Module["preInit"] = [Module["preInit"]];
439
+ while (Module["preInit"].length > 0) {
440
+ Module["preInit"].shift()()
441
+ }
442
+ }
443
+ }
444
+ Module["ccall"] = ccall;
445
+ Module["cwrap"] = cwrap;
446
+ var _get_result_len, _get_result_ptr, _free_result, _free, _lzma_wasm_compress, _malloc, _lzma_wasm_decompress, __emscripten_stack_restore,
447
+ __emscripten_stack_alloc, _emscripten_stack_get_current, memory, __indirect_function_table, wasmMemory;
448
+
449
+ function assignWasmExports(wasmExports) {
450
+ _get_result_len = Module["_get_result_len"] = wasmExports["d"];
451
+ _get_result_ptr = Module["_get_result_ptr"] = wasmExports["e"];
452
+ _free_result = Module["_free_result"] = wasmExports["f"];
453
+ _free = Module["_free"] = wasmExports["g"];
454
+ _lzma_wasm_compress = Module["_lzma_wasm_compress"] = wasmExports["h"];
455
+ _malloc = Module["_malloc"] = wasmExports["i"];
456
+ _lzma_wasm_decompress = Module["_lzma_wasm_decompress"] = wasmExports["j"];
457
+ __emscripten_stack_restore = wasmExports["k"];
458
+ __emscripten_stack_alloc = wasmExports["l"];
459
+ _emscripten_stack_get_current = wasmExports["m"];
460
+ memory = wasmMemory = wasmExports["b"];
461
+ __indirect_function_table = wasmExports["__indirect_function_table"]
462
+ }
463
+
464
+ var wasmImports = {a: _emscripten_resize_heap};
465
+
466
+ function run() {
467
+ preRun();
468
+
469
+ function doRun() {
470
+ Module["calledRun"] = true;
471
+ if (ABORT) return;
472
+ initRuntime();
473
+ readyPromiseResolve?.(Module);
474
+ Module["onRuntimeInitialized"]?.();
475
+ postRun()
476
+ }
477
+
478
+ if (Module["setStatus"]) {
479
+ Module["setStatus"]("Running...");
480
+ setTimeout(() => {
481
+ setTimeout(() => Module["setStatus"](""), 1);
482
+ doRun()
483
+ }, 1)
484
+ } else {
485
+ doRun()
486
+ }
487
+ }
488
+
489
+ var wasmExports;
490
+ wasmExports = await (createWasm());
491
+ run();
492
+ if (runtimeInitialized) {
493
+ moduleRtn = Module
494
+ } else {
495
+ moduleRtn = new Promise((resolve, reject) => {
496
+ readyPromiseResolve = resolve;
497
+ readyPromiseReject = reject
498
+ })
499
+ }
500
+ ;
501
+ return moduleRtn
502
+ }
503
+ })();
504
+ if (typeof exports === "object" && typeof module === "object") {
505
+ module.exports = createLzmaModule;
506
+ module.exports.default = createLzmaModule
507
+ } else if (typeof define === "function" && define["amd"]) define([], () => createLzmaModule);
package/dist/lzma.wasm ADDED
Binary file
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@icure/lzma-wasm",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "LZMA2/XZ compression and decompression for browsers and Node.js, using liblzma compiled to WebAssembly",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "LICENSE",
10
+ "LICENSE.liblzma"
11
+ ],
12
+ "scripts": {
13
+ "build": "rm -rf dist && tsc && cp src/lzma.js src/lzma.wasm src/lzma.d.ts dist/",
14
+ "build:wasm": "./src/build.sh",
15
+ "test": "npm run build && tsc -p test && node --test test-dist/*.test.js",
16
+ "prepublishOnly": "npm test"
17
+ },
18
+ "keywords": [
19
+ "lzma",
20
+ "lzma2",
21
+ "xz",
22
+ "compression",
23
+ "wasm",
24
+ "webassembly"
25
+ ],
26
+ "author": "Taktik sa - B12 Consulting",
27
+ "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git+https://github.com/icure/lzma-wasm.git"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/icure/lzma-wasm/issues"
34
+ },
35
+ "homepage": "https://github.com/icure/lzma-wasm#readme",
36
+ "devDependencies": {
37
+ "@types/node": "^18.19.75",
38
+ "typescript": "^5.8.2"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ }
43
+ }