@gjsify/zlib 0.49.0 → 0.51.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/lib/esm/gio-codec.js +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/types/gio-codec.d.ts +47 -2
- package/lib/types/index.d.ts +3 -3
- package/package.json +7 -7
package/lib/esm/gio-codec.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import e from"@girs/gio-2.0";import t from"@girs/glib-2.0";const n=256*1024,r=1024*1024;function getGioFormat(t){switch(t){case`gzip`:return e.ZlibCompressorFormat.GZIP;case`deflate`:return e.ZlibCompressorFormat.ZLIB;case`deflate-raw`:return e.ZlibCompressorFormat.RAW}}function concat(e){let t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}function compressWithGio(n,r){let
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"@girs/gio-2.0";import t from"@girs/glib-2.0";const n=256*1024,r=1024*1024;function getGioFormat(t){switch(t){case`gzip`:return e.ZlibCompressorFormat.GZIP;case`deflate`:return e.ZlibCompressorFormat.ZLIB;case`deflate-raw`:return e.ZlibCompressorFormat.RAW}}function concat(e){let t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}const i=-1;function assertLevel(e){if(!(e>=-1&&e<=9))throw RangeError(`The value of "level" is out of range. It must be >= -1 and <= 9. Received ${e}`)}function compressWithGio(n,r,i=-1){assertLevel(i);let a=new e.ZlibCompressor({format:getGioFormat(r),level:Math.trunc(i)}),o=new e.ConverterOutputStream({base_stream:e.MemoryOutputStream.new_resizable(),converter:a});o.write_bytes(new t.Bytes(n),null),o.close(null);let s=o.get_base_stream().steal_as_bytes();return new Uint8Array(s.get_data()??[])}function decompressStreamWithGio(n,i){let a=new e.ZlibDecompressor({format:getGioFormat(i)}),o=e.MemoryInputStream.new_from_bytes(new t.Bytes(n)),s=new e.ConverterInputStream({base_stream:o,converter:a}),c=[];for(;;){let e=s.read_bytes(r,null);if(e.get_size()===0)break;c.push(new Uint8Array(e.get_data()))}return s.close(null),concat(c)}function findGzipMemberEnd(t){let r=new e.ZlibDecompressor({format:e.ZlibCompressorFormat.GZIP}),i=new Uint8Array(262144),a=0;for(;;){let o=t.subarray(a,a+n);try{let[t,n,s]=r.convert(o,i,e.ConverterFlags.NONE);if(a+=n,t===e.ConverterResult.FINISHED||n===0&&s===0)return a}catch{return a}}}function gunzipWithGio(e){let t=[],n=0;for(;n<e.length&&!(e.length-n<2||e[n]!==31||e[n+1]!==139);){let r=e.subarray(n),i=findGzipMemberEnd(r);if(i<=0)break;t.push(decompressStreamWithGio(r.subarray(0,i),`gzip`)),n+=i}return t.length===0?decompressStreamWithGio(e,`gzip`):concat(t)}export{n as CONVERT_INPUT_SLICE,i as DEFAULT_LEVEL,r as STREAM_READ_CHUNK,assertLevel,compressWithGio,decompressStreamWithGio,findGzipMemberEnd,getGioFormat,gunzipWithGio};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{assertLevel as e,compressWithGio as t,decompressStreamWithGio as n,gunzipWithGio as r}from"./gio-codec.js";import{BrotliCompress as i,BrotliDecompress as a,Deflate as o,DeflateRaw as s,Gunzip as c,Gzip as l,Inflate as u,InflateRaw as d,Unzip as f,ZlibBase as p,ZstdCompress as m,ZstdDecompress as h,createBrotliCompress as g,createBrotliDecompress as _,createDeflate as v,createDeflateRaw as y,createGunzip as b,createGzip as x,createInflate as S,createInflateRaw as C,createUnzip as w,createZstdCompress as T,createZstdDecompress as E}from"./transform-streams.js";const hasWebCompression=()=>globalThis.CompressionStream!==void 0;function decompressWithGio(e,t){return t===`gzip`?r(e):n(e,t)}async function runWebTransform(e,t){let n=new ReadableStream({start(t){t.enqueue(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),t.close()}}),r=[],i=n.pipeThrough(t).getReader();for(;;){let{done:e,value:t}=await i.read();if(e)break;r.push(t)}let a=r.reduce((e,t)=>e+t.length,0),o=new Uint8Array(a),s=0;for(let e of r)o.set(e,s),s+=e.length;return o}async function compressWithWeb(e,t){return runWebTransform(e,new CompressionStream(t))}async function decompressWithWeb(e,t){return runWebTransform(e,new DecompressionStream(t))}function requestedLevel(t){let n=t?.level;if(!(n===void 0||n===-1))return e(n),n}async function compress(e,n,r){return r===void 0&&hasWebCompression()?compressWithWeb(e,n):t(e,n,r)}async function decompress(e,t){if(hasWebCompression())try{return await decompressWithWeb(e,t)}catch(n){if(t!==`gzip`)throw n;return decompressWithGio(e,t)}return decompressWithGio(e,t)}function toUint8Array(e){return typeof e==`string`?new TextEncoder().encode(e):e instanceof ArrayBuffer?new Uint8Array(e):e}function gzip(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;compress(toUint8Array(e),`gzip`,requestedLevel(i)).then(e=>r(null,e),e=>r(e instanceof Error?e:Error(String(e)),new Uint8Array))}function gunzip(e,t,n){let r=typeof t==`function`?t:n;decompress(toUint8Array(e),`gzip`).then(e=>r(null,e),e=>r(e instanceof Error?e:Error(String(e)),new Uint8Array))}function deflate(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;compress(toUint8Array(e),`deflate`,requestedLevel(i)).then(e=>r(null,e),e=>r(e instanceof Error?e:Error(String(e)),new Uint8Array))}function inflate(e,t,n){let r=typeof t==`function`?t:n;decompress(toUint8Array(e),`deflate`).then(e=>r(null,e),e=>r(e instanceof Error?e:Error(String(e)),new Uint8Array))}function deflateRaw(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;compress(toUint8Array(e),`deflate-raw`,requestedLevel(i)).then(e=>r(null,e),e=>r(e instanceof Error?e:Error(String(e)),new Uint8Array))}function inflateRaw(e,t,n){let r=typeof t==`function`?t:n;decompress(toUint8Array(e),`deflate-raw`).then(e=>r(null,e),e=>r(e instanceof Error?e:Error(String(e)),new Uint8Array))}function gzipSync(e,n){return t(toUint8Array(e),`gzip`,n?.level??-1)}function gunzipSync(e,t){return decompressWithGio(toUint8Array(e),`gzip`)}function deflateSync(e,n){return t(toUint8Array(e),`deflate`,n?.level??-1)}function inflateSync(e,t){return decompressWithGio(toUint8Array(e),`deflate`)}function deflateRawSync(e,n){return t(toUint8Array(e),`deflate-raw`,n?.level??-1)}function inflateRawSync(e,t){return decompressWithGio(toUint8Array(e),`deflate-raw`)}const D=new Uint8Array;function brotliCompress(e,t,n){(typeof t==`function`?t:n)(Error(`brotliCompress: Brotli is not supported in this environment`),D)}function brotliDecompress(e,t,n){(typeof t==`function`?t:n)(Error(`brotliDecompress: Brotli is not supported in this environment`),D)}function brotliCompressSync(e,t){throw Error(`brotliCompressSync: Brotli is not supported in this environment`)}function brotliDecompressSync(e,t){throw Error(`brotliDecompressSync: Brotli is not supported in this environment`)}function zstdCompress(e,t,n){let r=typeof t==`function`?t:n,i=Error(`zstdCompress: Zstd is not supported in this environment`);i.code=`ERR_UNSUPPORTED_OPERATION`,r(i,D)}function zstdDecompress(e,t,n){let r=typeof t==`function`?t:n,i=Error(`zstdDecompress: Zstd is not supported in this environment`);i.code=`ERR_UNSUPPORTED_OPERATION`,r(i,D)}function zstdCompressSync(e,t){let n=Error(`zstdCompressSync: Zstd is not supported in this environment`);throw n.code=`ERR_UNSUPPORTED_OPERATION`,n}function zstdDecompressSync(e,t){let n=Error(`zstdDecompressSync: Zstd is not supported in this environment`);throw n.code=`ERR_UNSUPPORTED_OPERATION`,n}const O={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_DEFLATED:8};var k={gzip,gunzip,deflate,inflate,deflateRaw,inflateRaw,gzipSync,gunzipSync,deflateSync,inflateSync,deflateRawSync,inflateRawSync,brotliCompress,brotliDecompress,brotliCompressSync,brotliDecompressSync,zstdCompress,zstdDecompress,zstdCompressSync,zstdDecompressSync,Gzip:l,Gunzip:c,Deflate:o,Inflate:u,DeflateRaw:s,InflateRaw:d,Unzip:f,BrotliCompress:i,BrotliDecompress:a,ZstdCompress:m,ZstdDecompress:h,createGzip:x,createGunzip:b,createDeflate:v,createInflate:S,createDeflateRaw:y,createInflateRaw:C,createUnzip:w,createBrotliCompress:g,createBrotliDecompress:_,createZstdCompress:T,createZstdDecompress:E,constants:O};export{i as BrotliCompress,a as BrotliDecompress,o as Deflate,s as DeflateRaw,c as Gunzip,l as Gzip,u as Inflate,d as InflateRaw,f as Unzip,p as ZlibTransform,m as ZstdCompress,h as ZstdDecompress,brotliCompress,brotliCompressSync,brotliDecompress,brotliDecompressSync,O as constants,g as createBrotliCompress,_ as createBrotliDecompress,v as createDeflate,y as createDeflateRaw,b as createGunzip,x as createGzip,S as createInflate,C as createInflateRaw,w as createUnzip,T as createZstdCompress,E as createZstdDecompress,k as default,deflate,deflateRaw,deflateRawSync,deflateSync,gunzip,gunzipSync,gzip,gzipSync,inflate,inflateRaw,inflateRawSync,inflateSync,zstdCompress,zstdCompressSync,zstdDecompress,zstdDecompressSync};
|
package/lib/types/gio-codec.d.ts
CHANGED
|
@@ -12,8 +12,53 @@ export declare const CONVERT_INPUT_SLICE: number;
|
|
|
12
12
|
*/
|
|
13
13
|
export declare const STREAM_READ_CHUNK: number;
|
|
14
14
|
export declare function getGioFormat(format: GioFormat): Gio.ZlibCompressorFormat;
|
|
15
|
-
/**
|
|
16
|
-
export declare
|
|
15
|
+
/** `Gio.ZlibCompressor:level`'s own "pick the zlib default" value. */
|
|
16
|
+
export declare const DEFAULT_LEVEL = -1;
|
|
17
|
+
/**
|
|
18
|
+
* Reject a level `Gio.ZlibCompressor` would take differently than zlib does.
|
|
19
|
+
*
|
|
20
|
+
* MEASURED on gjs 1.86 / GLib 2.86, because the guess was wrong in the direction
|
|
21
|
+
* that matters. An out-of-range construct value is not clamped to the paramspec's
|
|
22
|
+
* bounds — GObject DISCARDS it, logs `GLib-GObject-CRITICAL: value "42" … is
|
|
23
|
+
* invalid or out of range for property 'level'`, and leaves the property at 0.
|
|
24
|
+
* Level 0 is zlib's STORE mode, so `level: 42` asks for maximum compression and
|
|
25
|
+
* gets a stream that is compressed not at all, while a CRITICAL is a log line and
|
|
26
|
+
* not an exception — the process carries on at exit 0. Node throws
|
|
27
|
+
* `ERR_OUT_OF_RANGE` here, and throwing is the only answer that cannot be missed.
|
|
28
|
+
*
|
|
29
|
+
* RANGE ONLY, and not `Number.isInteger`, because the reference implementation is
|
|
30
|
+
* the reference: measured on Node 24, `gzipSync(data, {level: 2.5})` is ACCEPTED
|
|
31
|
+
* (C casts it) while 42 and -7 throw. A first version of this guard rejected 2.5
|
|
32
|
+
* as well and the Node leg of the spec failed it — which is what that leg is for
|
|
33
|
+
* (tests/AGENTS.md rule 3: the Node run proves the TEST, the GJS run proves our
|
|
34
|
+
* implementation). The truncation that keeps GI happy is {@link compressWithGio}'s.
|
|
35
|
+
* Node's boundary is the RAW float against the bound, not its integer part, so the
|
|
36
|
+
* asymmetry is real and this expression reproduces it: 2.5 passes, 9.9 throws.
|
|
37
|
+
*
|
|
38
|
+
* Written as `!(level >= -1 && level <= 9)` rather than `level < -1 || level > 9`
|
|
39
|
+
* so `NaN` — which compares false against everything — is refused rather than
|
|
40
|
+
* passed through to a `gint` marshaller, where `Math.trunc(NaN)` would earn the
|
|
41
|
+
* same CRITICAL as 42 above and the same silent STORE. THIS IS THE ONE PLACE THE
|
|
42
|
+
* GUARD IS DELIBERATELY STRICTER THAN NODE, and the number is written down so the
|
|
43
|
+
* next reader does not "restore parity" into that bug: measured on Node 24,
|
|
44
|
+
* `{level: NaN}` is ACCEPTED and yields default-level output (35 bytes, XFL 0, byte
|
|
45
|
+
* for byte what an omitted level produces) because `NaN < -1` and `NaN > 9` are
|
|
46
|
+
* both false. Matching that would mean mapping NaN to {@link DEFAULT_LEVEL}, which
|
|
47
|
+
* is a fine change to make deliberately and a bad one to make by deleting a `!`.
|
|
48
|
+
* The divergence reaches no Node consumer: `gjsify.runtimes.node` is `none`, so on
|
|
49
|
+
* the node target `node:zlib` is Node's own.
|
|
50
|
+
*/
|
|
51
|
+
export declare function assertLevel(level: number): void;
|
|
52
|
+
/**
|
|
53
|
+
* One-shot compression via `Gio.ZlibCompressor`.
|
|
54
|
+
*
|
|
55
|
+
* @param level 0 (store) to 9 (most), or {@link DEFAULT_LEVEL} for zlib's own choice.
|
|
56
|
+
* The level is not cosmetic: it is the only way to set the gzip header's XFL byte,
|
|
57
|
+
* which is how `lintian` and `file` read back a claim of maximum compression.
|
|
58
|
+
* TRUNCATED before it reaches the `gint` property, which is what Node's C cast
|
|
59
|
+
* does with the fractional level it also accepts.
|
|
60
|
+
*/
|
|
61
|
+
export declare function compressWithGio(data: Uint8Array, format: GioFormat, level?: number): Uint8Array;
|
|
17
62
|
/**
|
|
18
63
|
* One-shot decompression of a single zlib/raw/gzip stream via
|
|
19
64
|
* `Gio.ConverterInputStream`. For gzip this decodes exactly ONE member —
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,11 +13,11 @@ export declare function deflateRaw(data: string | Uint8Array | ArrayBuffer, call
|
|
|
13
13
|
export declare function deflateRaw(data: string | Uint8Array | ArrayBuffer, options: ZlibOptions, callback: ZlibCallback): void;
|
|
14
14
|
export declare function inflateRaw(data: string | Uint8Array | ArrayBuffer, callback: ZlibCallback): void;
|
|
15
15
|
export declare function inflateRaw(data: string | Uint8Array | ArrayBuffer, options: ZlibOptions, callback: ZlibCallback): void;
|
|
16
|
-
export declare function gzipSync(data: string | Uint8Array | ArrayBuffer,
|
|
16
|
+
export declare function gzipSync(data: string | Uint8Array | ArrayBuffer, options?: ZlibOptions): Uint8Array;
|
|
17
17
|
export declare function gunzipSync(data: string | Uint8Array | ArrayBuffer, _options?: ZlibOptions): Uint8Array;
|
|
18
|
-
export declare function deflateSync(data: string | Uint8Array | ArrayBuffer,
|
|
18
|
+
export declare function deflateSync(data: string | Uint8Array | ArrayBuffer, options?: ZlibOptions): Uint8Array;
|
|
19
19
|
export declare function inflateSync(data: string | Uint8Array | ArrayBuffer, _options?: ZlibOptions): Uint8Array;
|
|
20
|
-
export declare function deflateRawSync(data: string | Uint8Array | ArrayBuffer,
|
|
20
|
+
export declare function deflateRawSync(data: string | Uint8Array | ArrayBuffer, options?: ZlibOptions): Uint8Array;
|
|
21
21
|
export declare function inflateRawSync(data: string | Uint8Array | ArrayBuffer, _options?: ZlibOptions): Uint8Array;
|
|
22
22
|
export declare function brotliCompress(data: string | Uint8Array | ArrayBuffer, optionsOrCallback: ZlibOptions | ZlibCallback, callback?: ZlibCallback): void;
|
|
23
23
|
export declare function brotliDecompress(data: string | Uint8Array | ArrayBuffer, optionsOrCallback: ZlibOptions | ZlibCallback, callback?: ZlibCallback): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/zlib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Node.js zlib module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
"zlib"
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@girs/gio-2.0": "
|
|
42
|
-
"@girs/glib-2.0": "
|
|
43
|
-
"@gjsify/stream": "^0.
|
|
41
|
+
"@girs/gio-2.0": "5.0.0",
|
|
42
|
+
"@girs/glib-2.0": "5.0.0",
|
|
43
|
+
"@gjsify/stream": "^0.51.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@gjsify/cli": "^0.
|
|
47
|
-
"@gjsify/unit": "^0.
|
|
48
|
-
"@gjsify/util": "^0.
|
|
46
|
+
"@gjsify/cli": "^0.51.0",
|
|
47
|
+
"@gjsify/unit": "^0.51.0",
|
|
48
|
+
"@gjsify/util": "^0.51.0",
|
|
49
49
|
"@types/node": "^25.9.2",
|
|
50
50
|
"typescript": "^6.0.3"
|
|
51
51
|
},
|