compress-utils 0.7.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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -0
  3. package/dist/algorithms/brotli/brotli.wasm +0 -0
  4. package/dist/algorithms/brotli/index.d.ts +12 -0
  5. package/dist/algorithms/brotli/index.d.ts.map +1 -0
  6. package/dist/algorithms/brotli/index.js +17 -0
  7. package/dist/algorithms/brotli/index.js.map +1 -0
  8. package/dist/algorithms/bz2/bz2.wasm +0 -0
  9. package/dist/algorithms/bz2/index.d.ts +12 -0
  10. package/dist/algorithms/bz2/index.d.ts.map +1 -0
  11. package/dist/algorithms/bz2/index.js +17 -0
  12. package/dist/algorithms/bz2/index.js.map +1 -0
  13. package/dist/algorithms/lz4/index.d.ts +12 -0
  14. package/dist/algorithms/lz4/index.d.ts.map +1 -0
  15. package/dist/algorithms/lz4/index.js +17 -0
  16. package/dist/algorithms/lz4/index.js.map +1 -0
  17. package/dist/algorithms/lz4/lz4.wasm +0 -0
  18. package/dist/algorithms/xz/index.d.ts +12 -0
  19. package/dist/algorithms/xz/index.d.ts.map +1 -0
  20. package/dist/algorithms/xz/index.js +17 -0
  21. package/dist/algorithms/xz/index.js.map +1 -0
  22. package/dist/algorithms/xz/xz.wasm +0 -0
  23. package/dist/algorithms/zlib/index.d.ts +12 -0
  24. package/dist/algorithms/zlib/index.d.ts.map +1 -0
  25. package/dist/algorithms/zlib/index.js +17 -0
  26. package/dist/algorithms/zlib/index.js.map +1 -0
  27. package/dist/algorithms/zlib/zlib.wasm +0 -0
  28. package/dist/algorithms/zstd/index.d.ts +12 -0
  29. package/dist/algorithms/zstd/index.d.ts.map +1 -0
  30. package/dist/algorithms/zstd/index.js +17 -0
  31. package/dist/algorithms/zstd/index.js.map +1 -0
  32. package/dist/algorithms/zstd/zstd.wasm +0 -0
  33. package/dist/core/algorithm.d.ts +17 -0
  34. package/dist/core/algorithm.d.ts.map +1 -0
  35. package/dist/core/algorithm.js +19 -0
  36. package/dist/core/algorithm.js.map +1 -0
  37. package/dist/core/dispatch.d.ts +83 -0
  38. package/dist/core/dispatch.d.ts.map +1 -0
  39. package/dist/core/dispatch.js +376 -0
  40. package/dist/core/dispatch.js.map +1 -0
  41. package/dist/core/loader.d.ts +47 -0
  42. package/dist/core/loader.d.ts.map +1 -0
  43. package/dist/core/loader.js +151 -0
  44. package/dist/core/loader.js.map +1 -0
  45. package/dist/core/resolve-browser.d.ts +12 -0
  46. package/dist/core/resolve-browser.d.ts.map +1 -0
  47. package/dist/core/resolve-browser.js +11 -0
  48. package/dist/core/resolve-browser.js.map +1 -0
  49. package/dist/core/resolve-default.d.ts +11 -0
  50. package/dist/core/resolve-default.d.ts.map +1 -0
  51. package/dist/core/resolve-default.js +25 -0
  52. package/dist/core/resolve-default.js.map +1 -0
  53. package/dist/core/resolve-node.d.ts +13 -0
  54. package/dist/core/resolve-node.d.ts.map +1 -0
  55. package/dist/core/resolve-node.js +13 -0
  56. package/dist/core/resolve-node.js.map +1 -0
  57. package/dist/core/types.d.ts +54 -0
  58. package/dist/core/types.d.ts.map +1 -0
  59. package/dist/core/types.js +47 -0
  60. package/dist/core/types.js.map +1 -0
  61. package/package.json +84 -0
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Default resolver: detects the runtime at module load and picks fetch
3
+ * vs. fs.readFile. Used as a fallback when the consumer doesn't honor
4
+ * the package.json `browser` / `node` / `deno` / `bun` export conditions.
5
+ *
6
+ * Modern bundlers and runtimes hit the conditional exports instead and
7
+ * never load this file. It's a belt-and-braces fallback.
8
+ */
9
+ export const resolveWasm = async (url) => {
10
+ const hasFetch = typeof fetch === "function";
11
+ const isDeno = typeof Deno !== "undefined";
12
+ const isBun = typeof Bun !== "undefined";
13
+ const isNode = typeof process !== "undefined" && process.versions?.node !== undefined && !isDeno && !isBun;
14
+ // Node's fetch can't do file://. Everyone else's can (Deno + Bun
15
+ // natively; browsers only see http(s)). So Node is the only path
16
+ // that needs fs.readFile.
17
+ if (isNode && url.protocol === "file:") {
18
+ const { readFile } = await import("node:fs/promises");
19
+ return readFile(url);
20
+ }
21
+ if (hasFetch)
22
+ return fetch(url);
23
+ throw new Error("no wasm resolver available in this runtime");
24
+ };
25
+ //# sourceMappingURL=resolve-default.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-default.js","sourceRoot":"","sources":["../../src/core/resolve-default.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,MAAM,CAAC,MAAM,WAAW,GAAiB,KAAK,EAAE,GAAG,EAAE,EAAE;IACnD,MAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,UAAU,CAAC;IAC7C,MAAM,MAAM,GAAG,OAAO,IAAI,KAAK,WAAW,CAAC;IAC3C,MAAM,KAAK,GAAG,OAAO,GAAG,KAAK,WAAW,CAAC;IACzC,MAAM,MAAM,GACR,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,QAAQ,EAAE,IAAI,KAAK,SAAS,IAAI,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC;IAEhG,iEAAiE;IACjE,iEAAiE;IACjE,0BAA0B;IAC1B,IAAI,MAAM,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACrC,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACtD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;IACzB,CAAC;IACD,IAAI,QAAQ;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;AAClE,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Node resolver: read the wasm bytes from disk via `fs.readFile`, hand
3
+ * the loader an ArrayBuffer for the non-streaming `WebAssembly.instantiate`
4
+ * path.
5
+ *
6
+ * Why not `fetch`: Node's built-in fetch (undici) deliberately rejects
7
+ * the `file:` scheme with ERR_INVALID_URL_SCHEME. The streaming-compile
8
+ * benefit is also moot here — disk reads aren't latency-bound the way
9
+ * network fetches are.
10
+ */
11
+ import type { WasmResolver } from "./dispatch.js";
12
+ export declare const resolveWasm: WasmResolver;
13
+ //# sourceMappingURL=resolve-node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-node.d.ts","sourceRoot":"","sources":["../../src/core/resolve-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,eAAO,MAAM,WAAW,EAAE,YAAqC,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Node resolver: read the wasm bytes from disk via `fs.readFile`, hand
3
+ * the loader an ArrayBuffer for the non-streaming `WebAssembly.instantiate`
4
+ * path.
5
+ *
6
+ * Why not `fetch`: Node's built-in fetch (undici) deliberately rejects
7
+ * the `file:` scheme with ERR_INVALID_URL_SCHEME. The streaming-compile
8
+ * benefit is also moot here — disk reads aren't latency-bound the way
9
+ * network fetches are.
10
+ */
11
+ import { readFile } from "node:fs/promises";
12
+ export const resolveWasm = (url) => readFile(url);
13
+ //# sourceMappingURL=resolve-node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-node.js","sourceRoot":"","sources":["../../src/core/resolve-node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,MAAM,CAAC,MAAM,WAAW,GAAiB,CAAC,GAAG,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Public types. The Algorithm enum is internal — users see string names
3
+ * via CompressError.algorithm. Each subpath knows its own algorithm,
4
+ * so users never need to pass one.
5
+ */
6
+ /** @internal */
7
+ export declare const enum Algorithm {
8
+ Zstd = 0,
9
+ Brotli = 1,
10
+ Zlib = 2,
11
+ Bz2 = 3,
12
+ Lz4 = 4,
13
+ Xz = 5,
14
+ Lzma = 6
15
+ }
16
+ /** @internal */
17
+ export declare const enum Status {
18
+ Ok = 0,
19
+ InvalidArg = 1,
20
+ InvalidLevel = 2,
21
+ BufTooSmall = 3,
22
+ SizeUnknown = 4,
23
+ UnsupportedAlgo = 5,
24
+ Compression = 6,
25
+ Decompression = 7,
26
+ Truncated = 8,
27
+ SizeLimit = 9,
28
+ StreamFinished = 10,
29
+ StreamState = 11,
30
+ Oom = 12,
31
+ Internal = 13
32
+ }
33
+ /** Canonical lower-case algorithm names. */
34
+ export type AlgorithmName = "zstd" | "brotli" | "zlib" | "bz2" | "lz4" | "xz";
35
+ /** Thrown for any non-Ok status. Carries the raw status code and algo name. */
36
+ export declare class CompressError extends Error {
37
+ /** Underlying C status code. Stable across versions; see compress_utils.h. */
38
+ readonly code: number;
39
+ readonly algorithm: AlgorithmName;
40
+ constructor(code: number, algorithm: AlgorithmName, message: string);
41
+ }
42
+ export interface CompressOptions {
43
+ /** 1..10. 1 = fastest, 10 = smallest. Default 5. */
44
+ level?: number;
45
+ }
46
+ export interface DecompressOptions {
47
+ /**
48
+ * Decompressed size in bytes if known by the caller. Skips the
49
+ * size-hint probe and any internal streaming fallback — a small
50
+ * win for hot paths where the size is tracked out-of-band.
51
+ */
52
+ expectedSize?: number;
53
+ }
54
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gBAAgB;AAChB,0BAAkB,SAAS;IACvB,IAAI,IAAI;IACR,MAAM,IAAI;IACV,IAAI,IAAI;IACR,GAAG,IAAI;IACP,GAAG,IAAI;IACP,EAAE,IAAI;IACN,IAAI,IAAI;CACX;AAED,gBAAgB;AAChB,0BAAkB,MAAM;IACpB,EAAE,IAAI;IACN,UAAU,IAAI;IACd,YAAY,IAAI;IAChB,WAAW,IAAI;IACf,WAAW,IAAI;IACf,eAAe,IAAI;IACnB,WAAW,IAAI;IACf,aAAa,IAAI;IACjB,SAAS,IAAI;IACb,SAAS,IAAI;IACb,cAAc,KAAK;IACnB,WAAW,KAAK;IAChB,GAAG,KAAK;IACR,QAAQ,KAAK;CAChB;AAED,4CAA4C;AAC5C,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC;AAE9E,+EAA+E;AAC/E,qBAAa,aAAc,SAAQ,KAAK;IACpC,8EAA8E;IAC9E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;gBAEtB,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM;CAMtE;AAED,MAAM,WAAW,eAAe;IAC5B,oDAAoD;IACpD,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAC9B;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Public types. The Algorithm enum is internal — users see string names
3
+ * via CompressError.algorithm. Each subpath knows its own algorithm,
4
+ * so users never need to pass one.
5
+ */
6
+ /** @internal */
7
+ export var Algorithm;
8
+ (function (Algorithm) {
9
+ Algorithm[Algorithm["Zstd"] = 0] = "Zstd";
10
+ Algorithm[Algorithm["Brotli"] = 1] = "Brotli";
11
+ Algorithm[Algorithm["Zlib"] = 2] = "Zlib";
12
+ Algorithm[Algorithm["Bz2"] = 3] = "Bz2";
13
+ Algorithm[Algorithm["Lz4"] = 4] = "Lz4";
14
+ Algorithm[Algorithm["Xz"] = 5] = "Xz";
15
+ Algorithm[Algorithm["Lzma"] = 6] = "Lzma";
16
+ })(Algorithm || (Algorithm = {}));
17
+ /** @internal */
18
+ export var Status;
19
+ (function (Status) {
20
+ Status[Status["Ok"] = 0] = "Ok";
21
+ Status[Status["InvalidArg"] = 1] = "InvalidArg";
22
+ Status[Status["InvalidLevel"] = 2] = "InvalidLevel";
23
+ Status[Status["BufTooSmall"] = 3] = "BufTooSmall";
24
+ Status[Status["SizeUnknown"] = 4] = "SizeUnknown";
25
+ Status[Status["UnsupportedAlgo"] = 5] = "UnsupportedAlgo";
26
+ Status[Status["Compression"] = 6] = "Compression";
27
+ Status[Status["Decompression"] = 7] = "Decompression";
28
+ Status[Status["Truncated"] = 8] = "Truncated";
29
+ Status[Status["SizeLimit"] = 9] = "SizeLimit";
30
+ Status[Status["StreamFinished"] = 10] = "StreamFinished";
31
+ Status[Status["StreamState"] = 11] = "StreamState";
32
+ Status[Status["Oom"] = 12] = "Oom";
33
+ Status[Status["Internal"] = 13] = "Internal";
34
+ })(Status || (Status = {}));
35
+ /** Thrown for any non-Ok status. Carries the raw status code and algo name. */
36
+ export class CompressError extends Error {
37
+ /** Underlying C status code. Stable across versions; see compress_utils.h. */
38
+ code;
39
+ algorithm;
40
+ constructor(code, algorithm, message) {
41
+ super(message);
42
+ this.name = "CompressError";
43
+ this.code = code;
44
+ this.algorithm = algorithm;
45
+ }
46
+ }
47
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,gBAAgB;AAChB,MAAM,CAAN,IAAkB,SAQjB;AARD,WAAkB,SAAS;IACvB,yCAAQ,CAAA;IACR,6CAAU,CAAA;IACV,yCAAQ,CAAA;IACR,uCAAO,CAAA;IACP,uCAAO,CAAA;IACP,qCAAM,CAAA;IACN,yCAAQ,CAAA;AACZ,CAAC,EARiB,SAAS,KAAT,SAAS,QAQ1B;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAkB,MAejB;AAfD,WAAkB,MAAM;IACpB,+BAAM,CAAA;IACN,+CAAc,CAAA;IACd,mDAAgB,CAAA;IAChB,iDAAe,CAAA;IACf,iDAAe,CAAA;IACf,yDAAmB,CAAA;IACnB,iDAAe,CAAA;IACf,qDAAiB,CAAA;IACjB,6CAAa,CAAA;IACb,6CAAa,CAAA;IACb,wDAAmB,CAAA;IACnB,kDAAgB,CAAA;IAChB,kCAAQ,CAAA;IACR,4CAAa,CAAA;AACjB,CAAC,EAfiB,MAAM,KAAN,MAAM,QAevB;AAKD,+EAA+E;AAC/E,MAAM,OAAO,aAAc,SAAQ,KAAK;IACpC,8EAA8E;IACrE,IAAI,CAAS;IACb,SAAS,CAAgB;IAElC,YAAY,IAAY,EAAE,SAAwB,EAAE,OAAe;QAC/D,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;CACJ"}
package/package.json ADDED
@@ -0,0 +1,84 @@
1
+ {
2
+ "name": "compress-utils",
3
+ "version": "0.7.0",
4
+ "description": "WASM compression bindings for zstd, brotli, zlib, bz2, lz4, xz — tree-shakeable per-algorithm imports.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/dupontcyborg/compress-utils.git",
10
+ "directory": "bindings/wasm"
11
+ },
12
+ "homepage": "https://github.com/dupontcyborg/compress-utils#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/dupontcyborg/compress-utils/issues"
15
+ },
16
+ "author": "Nicolas Dupont <nico@dupont.live> (https://nico.codes)",
17
+ "license": "MIT",
18
+ "keywords": [
19
+ "compression",
20
+ "decompression",
21
+ "wasm",
22
+ "webassembly",
23
+ "zstd",
24
+ "brotli",
25
+ "zlib",
26
+ "gzip",
27
+ "bzip2",
28
+ "lz4",
29
+ "xz",
30
+ "lzma"
31
+ ],
32
+ "publishConfig": {
33
+ "access": "public",
34
+ "provenance": true
35
+ },
36
+ "exports": {
37
+ "./zstd": "./dist/algorithms/zstd/index.js",
38
+ "./brotli": "./dist/algorithms/brotli/index.js",
39
+ "./zlib": "./dist/algorithms/zlib/index.js",
40
+ "./bz2": "./dist/algorithms/bz2/index.js",
41
+ "./lz4": "./dist/algorithms/lz4/index.js",
42
+ "./xz": "./dist/algorithms/xz/index.js"
43
+ },
44
+ "imports": {
45
+ "#resolver": {
46
+ "types": "./src/core/resolve-default.ts",
47
+ "browser": "./dist/core/resolve-browser.js",
48
+ "deno": "./dist/core/resolve-browser.js",
49
+ "bun": "./dist/core/resolve-browser.js",
50
+ "node": "./dist/core/resolve-node.js",
51
+ "default": "./dist/core/resolve-default.js"
52
+ }
53
+ },
54
+ "files": [
55
+ "dist/",
56
+ "README.md",
57
+ "LICENSE"
58
+ ],
59
+ "scripts": {
60
+ "build:wasm": "cmake -S ../.. -B ../../build-wasm -DBUILD_WASM_BINDINGS=ON -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_CPP_BINDINGS=OFF -DENABLE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release && cmake --build ../../build-wasm --target compress_utils_wasm -j",
61
+ "build:ts": "tsc -p tsconfig.json",
62
+ "build": "npm run build:wasm && npm run build:ts",
63
+ "test": "vitest run",
64
+ "test:watch": "vitest",
65
+ "test:browser": "playwright test",
66
+ "test:deno": "deno run --allow-read --allow-env tests-runtime/deno-smoke.ts",
67
+ "test:bun": "bun test --bun tests/",
68
+ "lint": "biome lint .",
69
+ "lint:fix": "biome lint --write .",
70
+ "format": "biome format --write .",
71
+ "check": "biome check ."
72
+ },
73
+ "devDependencies": {
74
+ "@biomejs/biome": "2.4.15",
75
+ "@playwright/test": "^1.60.0",
76
+ "@types/node": "^25.8.0",
77
+ "esbuild": "^0.28.0",
78
+ "typescript": "^5.5.0",
79
+ "vitest": "^4.1.6"
80
+ },
81
+ "engines": {
82
+ "node": ">=18"
83
+ }
84
+ }