@gjsify/compression-streams 0.3.13 → 0.3.14

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/lib/esm/index.js CHANGED
@@ -1,10 +1,16 @@
1
1
  import { TransformStream } from "@gjsify/web-streams";
2
- const VALID_FORMATS = /* @__PURE__ */ new Set(["gzip", "deflate", "deflate-raw"]);
2
+
3
+ //#region src/index.ts
4
+ const VALID_FORMATS = new Set([
5
+ "gzip",
6
+ "deflate",
7
+ "deflate-raw"
8
+ ]);
3
9
  function validateFormat(format) {
4
- if (!VALID_FORMATS.has(format)) {
5
- throw new TypeError(`Unsupported compression format: '${format}'. Supported formats: 'gzip', 'deflate', 'deflate-raw'.`);
6
- }
7
- return format;
10
+ if (!VALID_FORMATS.has(format)) {
11
+ throw new TypeError(`Unsupported compression format: '${format}'. Supported formats: 'gzip', 'deflate', 'deflate-raw'.`);
12
+ }
13
+ return format;
8
14
  }
9
15
  const hasNative = typeof globalThis.CompressionStream === "function" && typeof globalThis.DecompressionStream === "function";
10
16
  let _zlibLoaded = false;
@@ -15,94 +21,82 @@ let _inflateSync;
15
21
  let _deflateRawSync;
16
22
  let _inflateRawSync;
17
23
  async function loadZlib() {
18
- if (_zlibLoaded) return;
19
- const zlib = await import("zlib");
20
- _gzipSync = zlib.gzipSync;
21
- _gunzipSync = zlib.gunzipSync;
22
- _deflateSync = zlib.deflateSync;
23
- _inflateSync = zlib.inflateSync;
24
- _deflateRawSync = zlib.deflateRawSync;
25
- _inflateRawSync = zlib.inflateRawSync;
26
- _zlibLoaded = true;
24
+ if (_zlibLoaded) return;
25
+ const zlib = await import("zlib");
26
+ _gzipSync = zlib.gzipSync;
27
+ _gunzipSync = zlib.gunzipSync;
28
+ _deflateSync = zlib.deflateSync;
29
+ _inflateSync = zlib.inflateSync;
30
+ _deflateRawSync = zlib.deflateRawSync;
31
+ _inflateRawSync = zlib.inflateRawSync;
32
+ _zlibLoaded = true;
27
33
  }
28
34
  function getCompressFn(format) {
29
- switch (format) {
30
- case "gzip":
31
- return (c) => _gzipSync(c);
32
- case "deflate":
33
- return (c) => _deflateSync(c);
34
- case "deflate-raw":
35
- return (c) => _deflateRawSync(c);
36
- }
35
+ switch (format) {
36
+ case "gzip": return (c) => _gzipSync(c);
37
+ case "deflate": return (c) => _deflateSync(c);
38
+ case "deflate-raw": return (c) => _deflateRawSync(c);
39
+ }
37
40
  }
38
41
  function getDecompressFn(format) {
39
- switch (format) {
40
- case "gzip":
41
- return (c) => _gunzipSync(c);
42
- case "deflate":
43
- return (c) => _inflateSync(c);
44
- case "deflate-raw":
45
- return (c) => _inflateRawSync(c);
46
- }
42
+ switch (format) {
43
+ case "gzip": return (c) => _gunzipSync(c);
44
+ case "deflate": return (c) => _inflateSync(c);
45
+ case "deflate-raw": return (c) => _inflateRawSync(c);
46
+ }
47
47
  }
48
48
  let CompressionStreamImpl;
49
49
  let DecompressionStreamImpl;
50
50
  if (hasNative) {
51
- CompressionStreamImpl = globalThis.CompressionStream;
52
- DecompressionStreamImpl = globalThis.DecompressionStream;
51
+ CompressionStreamImpl = globalThis.CompressionStream;
52
+ DecompressionStreamImpl = globalThis.DecompressionStream;
53
53
  } else {
54
- const zlibReady = loadZlib();
55
- CompressionStreamImpl = class CompressionStream {
56
- readable;
57
- writable;
58
- constructor(format) {
59
- const validFormat = validateFormat(format);
60
- if (!_zlibLoaded) {
61
- throw new Error("zlib not yet loaded. Ensure module initialization is complete.");
62
- }
63
- const processFn = getCompressFn(validFormat);
64
- const ts = new TransformStream({
65
- transform(chunk, controller) {
66
- try {
67
- controller.enqueue(processFn(chunk));
68
- } catch (err) {
69
- controller.error(err);
70
- }
71
- }
72
- });
73
- this.readable = ts.readable;
74
- this.writable = ts.writable;
75
- }
76
- };
77
- DecompressionStreamImpl = class DecompressionStream {
78
- readable;
79
- writable;
80
- constructor(format) {
81
- const validFormat = validateFormat(format);
82
- if (!_zlibLoaded) {
83
- throw new Error("zlib not yet loaded. Ensure module initialization is complete.");
84
- }
85
- const processFn = getDecompressFn(validFormat);
86
- const ts = new TransformStream({
87
- transform(chunk, controller) {
88
- try {
89
- controller.enqueue(processFn(chunk));
90
- } catch (err) {
91
- controller.error(err);
92
- }
93
- }
94
- });
95
- this.readable = ts.readable;
96
- this.writable = ts.writable;
97
- }
98
- };
54
+ const zlibReady = loadZlib();
55
+ CompressionStreamImpl = class CompressionStream {
56
+ readable;
57
+ writable;
58
+ constructor(format) {
59
+ const validFormat = validateFormat(format);
60
+ if (!_zlibLoaded) {
61
+ throw new Error("zlib not yet loaded. Ensure module initialization is complete.");
62
+ }
63
+ const processFn = getCompressFn(validFormat);
64
+ const ts = new TransformStream({ transform(chunk, controller) {
65
+ try {
66
+ controller.enqueue(processFn(chunk));
67
+ } catch (err) {
68
+ controller.error(err);
69
+ }
70
+ } });
71
+ this.readable = ts.readable;
72
+ this.writable = ts.writable;
73
+ }
74
+ };
75
+ DecompressionStreamImpl = class DecompressionStream {
76
+ readable;
77
+ writable;
78
+ constructor(format) {
79
+ const validFormat = validateFormat(format);
80
+ if (!_zlibLoaded) {
81
+ throw new Error("zlib not yet loaded. Ensure module initialization is complete.");
82
+ }
83
+ const processFn = getDecompressFn(validFormat);
84
+ const ts = new TransformStream({ transform(chunk, controller) {
85
+ try {
86
+ controller.enqueue(processFn(chunk));
87
+ } catch (err) {
88
+ controller.error(err);
89
+ }
90
+ } });
91
+ this.readable = ts.readable;
92
+ this.writable = ts.writable;
93
+ }
94
+ };
99
95
  }
100
- var index_default = {
101
- CompressionStream: CompressionStreamImpl,
102
- DecompressionStream: DecompressionStreamImpl
103
- };
104
- export {
105
- CompressionStreamImpl as CompressionStream,
106
- DecompressionStreamImpl as DecompressionStream,
107
- index_default as default
96
+ var src_default = {
97
+ CompressionStream: CompressionStreamImpl,
98
+ DecompressionStream: DecompressionStreamImpl
108
99
  };
100
+
101
+ //#endregion
102
+ export { CompressionStreamImpl as CompressionStream, DecompressionStreamImpl as DecompressionStream, src_default as default };
@@ -1,7 +1,11 @@
1
- import { CompressionStream, DecompressionStream } from "./index.js";
1
+ import { CompressionStream as CompressionStreamImpl, DecompressionStream as DecompressionStreamImpl } from "./index.js";
2
+
3
+ //#region src/register.ts
2
4
  if (typeof globalThis.CompressionStream === "undefined") {
3
- globalThis.CompressionStream = CompressionStream;
5
+ globalThis.CompressionStream = CompressionStreamImpl;
4
6
  }
5
7
  if (typeof globalThis.DecompressionStream === "undefined") {
6
- globalThis.DecompressionStream = DecompressionStream;
8
+ globalThis.DecompressionStream = DecompressionStreamImpl;
7
9
  }
10
+
11
+ //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/compression-streams",
3
- "version": "0.3.13",
3
+ "version": "0.3.14",
4
4
  "description": "W3C Compression Streams API for GJS",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
@@ -41,12 +41,12 @@
41
41
  "streams"
42
42
  ],
43
43
  "devDependencies": {
44
- "@gjsify/cli": "^0.3.13",
45
- "@gjsify/unit": "^0.3.13",
44
+ "@gjsify/cli": "^0.3.14",
45
+ "@gjsify/unit": "^0.3.14",
46
46
  "@types/node": "^25.6.0",
47
47
  "typescript": "^6.0.3"
48
48
  },
49
49
  "dependencies": {
50
- "@gjsify/web-streams": "^0.3.13"
50
+ "@gjsify/web-streams": "^0.3.14"
51
51
  }
52
52
  }