@gjsify/compression-streams 0.3.13 → 0.3.15
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 +79 -85
- package/lib/esm/register.js +7 -3
- package/package.json +4 -4
package/lib/esm/index.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { TransformStream } from "@gjsify/web-streams";
|
|
2
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
52
|
-
|
|
51
|
+
CompressionStreamImpl = globalThis.CompressionStream;
|
|
52
|
+
DecompressionStreamImpl = globalThis.DecompressionStream;
|
|
53
53
|
} else {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
|
101
|
-
|
|
102
|
-
|
|
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 };
|
package/lib/esm/register.js
CHANGED
|
@@ -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
|
-
|
|
5
|
+
globalThis.CompressionStream = CompressionStreamImpl;
|
|
4
6
|
}
|
|
5
7
|
if (typeof globalThis.DecompressionStream === "undefined") {
|
|
6
|
-
|
|
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.
|
|
3
|
+
"version": "0.3.15",
|
|
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.
|
|
45
|
-
"@gjsify/unit": "^0.3.
|
|
44
|
+
"@gjsify/cli": "^0.3.15",
|
|
45
|
+
"@gjsify/unit": "^0.3.15",
|
|
46
46
|
"@types/node": "^25.6.0",
|
|
47
47
|
"typescript": "^6.0.3"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@gjsify/web-streams": "^0.3.
|
|
50
|
+
"@gjsify/web-streams": "^0.3.15"
|
|
51
51
|
}
|
|
52
52
|
}
|