@gjsify/zlib 0.25.1 → 0.26.1

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.
@@ -0,0 +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 i=new e.ZlibCompressor({format:getGioFormat(r)}),a=new e.ConverterOutputStream({base_stream:e.MemoryOutputStream.new_resizable(),converter:i});a.write_bytes(new t.Bytes(n),null),a.close(null);let o=a.get_base_stream().steal_as_bytes();return new Uint8Array(o.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,r as STREAM_READ_CHUNK,compressWithGio,decompressStreamWithGio,findGzipMemberEnd,getGioFormat,gunzipWithGio};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{BrotliCompress as e,BrotliDecompress as t,Deflate as n,DeflateRaw as r,Gunzip as i,Gzip as a,Inflate as o,InflateRaw as s,Unzip as c,ZlibBase as l,ZstdCompress as u,ZstdDecompress as d,createBrotliCompress as f,createBrotliDecompress as p,createDeflate as m,createDeflateRaw as h,createGunzip as g,createGzip as _,createInflate as v,createInflateRaw as y,createUnzip as b,createZstdCompress as x,createZstdDecompress as S}from"./transform-streams.js";import C from"@girs/gio-2.0";import w from"@girs/glib-2.0";const T=globalThis.CompressionStream!==void 0;function getGioFormat(e){switch(e){case`gzip`:return C.ZlibCompressorFormat.GZIP;case`deflate`:return C.ZlibCompressorFormat.ZLIB;case`deflate-raw`:return C.ZlibCompressorFormat.RAW}}function compressWithGio(e,t){let n=new C.ZlibCompressor({format:getGioFormat(t)}),r=new C.ConverterOutputStream({base_stream:C.MemoryOutputStream.new_resizable(),converter:n});r.write_bytes(new w.Bytes(e),null),r.close(null);let i=r.get_base_stream().steal_as_bytes();return new Uint8Array(i.get_data()??[])}function decompressStreamWithGio(e,t){let n=new C.ZlibDecompressor({format:getGioFormat(t)}),r=C.MemoryInputStream.new_from_bytes(new w.Bytes(e)),i=new C.ConverterInputStream({base_stream:r,converter:n}),a=[];for(;;){let e=i.read_bytes(4096,null);if(e.get_size()===0)break;a.push(new Uint8Array(e.get_data()))}i.close(null);let o=a.reduce((e,t)=>e+t.length,0),s=new Uint8Array(o),c=0;for(let e of a)s.set(e,c),c+=e.length;return s}function findGzipMemberEnd(e){let t=new C.ZlibDecompressor({format:C.ZlibCompressorFormat.GZIP}),n=new Uint8Array(65536),r=0,i=!1;for(;!i;){let a=e.subarray(r);try{let[e,o]=t.convert(a,n,C.ConverterFlags.NONE);r+=o,e===C.ConverterResult.FINISHED&&(i=!0)}catch{i=!0}}return r}function decompressWithGio(e,t){if(t!==`gzip`)return decompressStreamWithGio(e,t);let n=[],r=0;for(;r<e.length&&!(e.length-r<2||e[r]!==31||e[r+1]!==139);){let t=e.subarray(r),i=findGzipMemberEnd(t);if(i<=0)break;let a=decompressStreamWithGio(t.subarray(0,i),`gzip`);n.push(a),r+=i}if(n.length===0)return decompressStreamWithGio(e,`gzip`);let i=n.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of n)a.set(e,o),o+=e.length;return a}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))}async function compress(e,t){return T?compressWithWeb(e,t):compressWithGio(e,t)}async function decompress(e,t){return T?decompressWithWeb(e,t):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;compress(toUint8Array(e),`gzip`).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;compress(toUint8Array(e),`deflate`).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;compress(toUint8Array(e),`deflate-raw`).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,t){return compressWithGio(toUint8Array(e),`gzip`)}function gunzipSync(e,t){return decompressWithGio(toUint8Array(e),`gzip`)}function deflateSync(e,t){return compressWithGio(toUint8Array(e),`deflate`)}function inflateSync(e,t){return decompressWithGio(toUint8Array(e),`deflate`)}function deflateRawSync(e,t){return compressWithGio(toUint8Array(e),`deflate-raw`)}function inflateRawSync(e,t){return decompressWithGio(toUint8Array(e),`deflate-raw`)}const E=new Uint8Array;function brotliCompress(e,t,n){(typeof t==`function`?t:n)(Error(`brotliCompress: Brotli is not supported in this environment`),E)}function brotliDecompress(e,t,n){(typeof t==`function`?t:n)(Error(`brotliDecompress: Brotli is not supported in this environment`),E)}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,E)}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,E)}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 D={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 O={gzip,gunzip,deflate,inflate,deflateRaw,inflateRaw,gzipSync,gunzipSync,deflateSync,inflateSync,deflateRawSync,inflateRawSync,brotliCompress,brotliDecompress,brotliCompressSync,brotliDecompressSync,zstdCompress,zstdDecompress,zstdCompressSync,zstdDecompressSync,Gzip:a,Gunzip:i,Deflate:n,Inflate:o,DeflateRaw:r,InflateRaw:s,Unzip:c,BrotliCompress:e,BrotliDecompress:t,ZstdCompress:u,ZstdDecompress:d,createGzip:_,createGunzip:g,createDeflate:m,createInflate:v,createDeflateRaw:h,createInflateRaw:y,createUnzip:b,createBrotliCompress:f,createBrotliDecompress:p,createZstdCompress:x,createZstdDecompress:S,constants:D};export{e as BrotliCompress,t as BrotliDecompress,n as Deflate,r as DeflateRaw,i as Gunzip,a as Gzip,o as Inflate,s as InflateRaw,c as Unzip,l as ZlibTransform,u as ZstdCompress,d as ZstdDecompress,brotliCompress,brotliCompressSync,brotliDecompress,brotliDecompressSync,D as constants,f as createBrotliCompress,p as createBrotliDecompress,m as createDeflate,h as createDeflateRaw,g as createGunzip,_ as createGzip,v as createInflate,y as createInflateRaw,b as createUnzip,x as createZstdCompress,S as createZstdDecompress,O as default,deflate,deflateRaw,deflateRawSync,deflateSync,gunzip,gunzipSync,gzip,gzipSync,inflate,inflateRaw,inflateRawSync,inflateSync,zstdCompress,zstdCompressSync,zstdDecompress,zstdDecompressSync};
1
+ import"./_virtual/_rolldown/runtime.js";import{compressWithGio as e,decompressStreamWithGio as t,gunzipWithGio as n}from"./gio-codec.js";import{BrotliCompress as r,BrotliDecompress as i,Deflate as a,DeflateRaw as o,Gunzip as s,Gzip as c,Inflate as l,InflateRaw as u,Unzip as d,ZlibBase as f,ZstdCompress as p,ZstdDecompress as m,createBrotliCompress as h,createBrotliDecompress as g,createDeflate as _,createDeflateRaw as v,createGunzip as y,createGzip as b,createInflate as x,createInflateRaw as S,createUnzip as C,createZstdCompress as w,createZstdDecompress as T}from"./transform-streams.js";const E=globalThis.CompressionStream!==void 0;function decompressWithGio(e,r){return r===`gzip`?n(e):t(e,r)}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))}async function compress(t,n){return E?compressWithWeb(t,n):e(t,n)}async function decompress(e,t){return E?decompressWithWeb(e,t):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;compress(toUint8Array(e),`gzip`).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;compress(toUint8Array(e),`deflate`).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;compress(toUint8Array(e),`deflate-raw`).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(t,n){return e(toUint8Array(t),`gzip`)}function gunzipSync(e,t){return decompressWithGio(toUint8Array(e),`gzip`)}function deflateSync(t,n){return e(toUint8Array(t),`deflate`)}function inflateSync(e,t){return decompressWithGio(toUint8Array(e),`deflate`)}function deflateRawSync(t,n){return e(toUint8Array(t),`deflate-raw`)}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:c,Gunzip:s,Deflate:a,Inflate:l,DeflateRaw:o,InflateRaw:u,Unzip:d,BrotliCompress:r,BrotliDecompress:i,ZstdCompress:p,ZstdDecompress:m,createGzip:b,createGunzip:y,createDeflate:_,createInflate:x,createDeflateRaw:v,createInflateRaw:S,createUnzip:C,createBrotliCompress:h,createBrotliDecompress:g,createZstdCompress:w,createZstdDecompress:T,constants:O};export{r as BrotliCompress,i as BrotliDecompress,a as Deflate,o as DeflateRaw,s as Gunzip,c as Gzip,l as Inflate,u as InflateRaw,d as Unzip,f as ZlibTransform,p as ZstdCompress,m as ZstdDecompress,brotliCompress,brotliCompressSync,brotliDecompress,brotliDecompressSync,O as constants,h as createBrotliCompress,g as createBrotliDecompress,_ as createDeflate,v as createDeflateRaw,y as createGunzip,b as createGzip,x as createInflate,S as createInflateRaw,C as createUnzip,w as createZstdCompress,T as createZstdDecompress,k as default,deflate,deflateRaw,deflateRawSync,deflateSync,gunzip,gunzipSync,gzip,gzipSync,inflate,inflateRaw,inflateRawSync,inflateSync,zstdCompress,zstdCompressSync,zstdDecompress,zstdDecompressSync};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import e from"@girs/gio-2.0";import t from"@girs/glib-2.0";import{Transform as n}from"node:stream";function getGioCompressorFormat(t){switch(t){case`gzip`:return e.ZlibCompressorFormat.GZIP;case`deflate`:return e.ZlibCompressorFormat.ZLIB;case`deflate-raw`:return e.ZlibCompressorFormat.RAW}}function toUint8Array(e){return typeof e==`string`?new TextEncoder().encode(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}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 i=new e.ZlibCompressor({format:getGioCompressorFormat(r)}),a=new e.ConverterOutputStream({base_stream:e.MemoryOutputStream.new_resizable(),converter:i});a.write_bytes(new t.Bytes(n),null),a.close(null);let o=a.get_base_stream().steal_as_bytes();return new Uint8Array(o.get_data()??[])}function decompressMemberWithGio(n,r){let i=new e.ZlibDecompressor({format:getGioCompressorFormat(r)}),a=e.MemoryInputStream.new_from_bytes(new t.Bytes(n)),o=new e.ConverterInputStream({base_stream:a,converter:i}),s=[];for(;;){let e=o.read_bytes(4096,null);if(e.get_size()===0)break;s.push(new Uint8Array(e.get_data()))}return o.close(null),concat(s)}function findGzipMemberEnd(t){let n=new e.ZlibDecompressor({format:e.ZlibCompressorFormat.GZIP}),r=new Uint8Array(65536),i=0,a=!1;for(;!a;){let o=t.subarray(i);try{let[t,s]=n.convert(o,r,e.ConverterFlags.NONE);i+=s,t===e.ConverterResult.FINISHED&&(a=!0)}catch{a=!0}}return i}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(decompressMemberWithGio(r.subarray(0,i),`gzip`)),n+=i}return t.length===0?decompressMemberWithGio(e,`gzip`):concat(t)}var ZlibBase=class extends n{_mode;_chunks=[];constructor(e,t){super(t),this._mode=e}_transform(e,t,n){this._chunks.push(toUint8Array(e)),n()}_flush(e){let t=concat(this._chunks);this._chunks=[];try{this.push(Buffer.from(this._run(t))),e()}catch(t){e(t instanceof Error?t:Error(String(t)))}}_run(e){let t=this._mode;switch(t.kind){case`compress`:return compressWithGio(e,t.format);case`decompress`:return decompressMemberWithGio(e,t.format);case`gunzip`:return gunzipWithGio(e);case`unzip`:return e.length>=2&&e[0]===31&&e[1]===139?gunzipWithGio(e):decompressMemberWithGio(e,`deflate`)}}},Gzip=class extends ZlibBase{constructor(e){super({kind:`compress`,format:`gzip`},e)}},Gunzip=class extends ZlibBase{constructor(e){super({kind:`gunzip`},e)}},Deflate=class extends ZlibBase{constructor(e){super({kind:`compress`,format:`deflate`},e)}},Inflate=class extends ZlibBase{constructor(e){super({kind:`decompress`,format:`deflate`},e)}},DeflateRaw=class extends ZlibBase{constructor(e){super({kind:`compress`,format:`deflate-raw`},e)}},InflateRaw=class extends ZlibBase{constructor(e){super({kind:`decompress`,format:`deflate-raw`},e)}},Unzip=class extends ZlibBase{constructor(e){super({kind:`unzip`},e)}},BrotliCompress=class extends n{constructor(){throw super(),Error(`BrotliCompress is not supported on GJS (no Brotli in GLib)`)}},BrotliDecompress=class extends n{constructor(){throw super(),Error(`BrotliDecompress is not supported on GJS (no Brotli in GLib)`)}},ZstdCompress=class extends n{constructor(){super();let e=Error(`ZstdCompress is not supported on GJS (no Zstd in GLib)`);throw e.code=`ERR_UNSUPPORTED_OPERATION`,e}},ZstdDecompress=class extends n{constructor(){super();let e=Error(`ZstdDecompress is not supported on GJS (no Zstd in GLib)`);throw e.code=`ERR_UNSUPPORTED_OPERATION`,e}};function createGzip(e){return new Gzip(e)}function createGunzip(e){return new Gunzip(e)}function createDeflate(e){return new Deflate(e)}function createInflate(e){return new Inflate(e)}function createDeflateRaw(e){return new DeflateRaw(e)}function createInflateRaw(e){return new InflateRaw(e)}function createUnzip(e){return new Unzip(e)}function createBrotliCompress(e){throw Error(`createBrotliCompress is not supported on GJS (no Brotli in GLib)`)}function createBrotliDecompress(e){throw Error(`createBrotliDecompress is not supported on GJS (no Brotli in GLib)`)}function createZstdCompress(e){let t=Error(`createZstdCompress is not supported on GJS (no Zstd in GLib)`);throw t.code=`ERR_UNSUPPORTED_OPERATION`,t}function createZstdDecompress(e){let t=Error(`createZstdDecompress is not supported on GJS (no Zstd in GLib)`);throw t.code=`ERR_UNSUPPORTED_OPERATION`,t}export{BrotliCompress,BrotliDecompress,Deflate,DeflateRaw,Gunzip,Gzip,Inflate,InflateRaw,Unzip,ZlibBase,ZlibBase as ZlibTransform,ZstdCompress,ZstdDecompress,createBrotliCompress,createBrotliDecompress,createDeflate,createDeflateRaw,createGunzip,createGzip,createInflate,createInflateRaw,createUnzip,createZstdCompress,createZstdDecompress};
1
+ import"./_virtual/_rolldown/runtime.js";import{compressWithGio as e,decompressStreamWithGio as t,gunzipWithGio as n}from"./gio-codec.js";import{Transform as r}from"node:stream";function toUint8Array(e){return typeof e==`string`?new TextEncoder().encode(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}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}var ZlibBase=class extends r{_mode;_chunks=[];constructor(e,t){super(t),this._mode=e}_transform(e,t,n){this._chunks.push(toUint8Array(e)),n()}_flush(e){let t=concat(this._chunks);this._chunks=[];try{this.push(Buffer.from(this._run(t))),e()}catch(t){e(t instanceof Error?t:Error(String(t)))}}_run(r){let i=this._mode;switch(i.kind){case`compress`:return e(r,i.format);case`decompress`:return t(r,i.format);case`gunzip`:return n(r);case`unzip`:return r.length>=2&&r[0]===31&&r[1]===139?n(r):t(r,`deflate`)}}},Gzip=class extends ZlibBase{constructor(e){super({kind:`compress`,format:`gzip`},e)}},Gunzip=class extends ZlibBase{constructor(e){super({kind:`gunzip`},e)}},Deflate=class extends ZlibBase{constructor(e){super({kind:`compress`,format:`deflate`},e)}},Inflate=class extends ZlibBase{constructor(e){super({kind:`decompress`,format:`deflate`},e)}},DeflateRaw=class extends ZlibBase{constructor(e){super({kind:`compress`,format:`deflate-raw`},e)}},InflateRaw=class extends ZlibBase{constructor(e){super({kind:`decompress`,format:`deflate-raw`},e)}},Unzip=class extends ZlibBase{constructor(e){super({kind:`unzip`},e)}},BrotliCompress=class extends r{constructor(){throw super(),Error(`BrotliCompress is not supported on GJS (no Brotli in GLib)`)}},BrotliDecompress=class extends r{constructor(){throw super(),Error(`BrotliDecompress is not supported on GJS (no Brotli in GLib)`)}},ZstdCompress=class extends r{constructor(){super();let e=Error(`ZstdCompress is not supported on GJS (no Zstd in GLib)`);throw e.code=`ERR_UNSUPPORTED_OPERATION`,e}},ZstdDecompress=class extends r{constructor(){super();let e=Error(`ZstdDecompress is not supported on GJS (no Zstd in GLib)`);throw e.code=`ERR_UNSUPPORTED_OPERATION`,e}};function createGzip(e){return new Gzip(e)}function createGunzip(e){return new Gunzip(e)}function createDeflate(e){return new Deflate(e)}function createInflate(e){return new Inflate(e)}function createDeflateRaw(e){return new DeflateRaw(e)}function createInflateRaw(e){return new InflateRaw(e)}function createUnzip(e){return new Unzip(e)}function createBrotliCompress(e){throw Error(`createBrotliCompress is not supported on GJS (no Brotli in GLib)`)}function createBrotliDecompress(e){throw Error(`createBrotliDecompress is not supported on GJS (no Brotli in GLib)`)}function createZstdCompress(e){let t=Error(`createZstdCompress is not supported on GJS (no Zstd in GLib)`);throw t.code=`ERR_UNSUPPORTED_OPERATION`,t}function createZstdDecompress(e){let t=Error(`createZstdDecompress is not supported on GJS (no Zstd in GLib)`);throw t.code=`ERR_UNSUPPORTED_OPERATION`,t}export{BrotliCompress,BrotliDecompress,Deflate,DeflateRaw,Gunzip,Gzip,Inflate,InflateRaw,Unzip,ZlibBase,ZlibBase as ZlibTransform,ZstdCompress,ZstdDecompress,createBrotliCompress,createBrotliDecompress,createDeflate,createDeflateRaw,createGunzip,createGzip,createInflate,createInflateRaw,createUnzip,createZstdCompress,createZstdDecompress};
@@ -0,0 +1,48 @@
1
+ import Gio from '@girs/gio-2.0';
2
+ export type GioFormat = 'gzip' | 'deflate' | 'deflate-raw';
3
+ /**
4
+ * Upper bound for the input slice handed to a single `Gio.Converter.convert()`
5
+ * call. See the performance contract above — this bound is what keeps the
6
+ * gzip member scan linear instead of quadratic.
7
+ */
8
+ export declare const CONVERT_INPUT_SLICE: number;
9
+ /**
10
+ * Read chunk for `ConverterInputStream`-driven decompression. 1 MiB measured
11
+ * 522 MB/s vs 246 MB/s at the previous 4096 bytes (see contract above).
12
+ */
13
+ export declare const STREAM_READ_CHUNK: number;
14
+ export declare function getGioFormat(format: GioFormat): Gio.ZlibCompressorFormat;
15
+ /** One-shot compression via `Gio.ZlibCompressor`. */
16
+ export declare function compressWithGio(data: Uint8Array, format: GioFormat): Uint8Array;
17
+ /**
18
+ * One-shot decompression of a single zlib/raw/gzip stream via
19
+ * `Gio.ConverterInputStream`. For gzip this decodes exactly ONE member —
20
+ * concatenated members need {@link gunzipWithGio}.
21
+ */
22
+ export declare function decompressStreamWithGio(data: Uint8Array, format: GioFormat): Uint8Array;
23
+ /**
24
+ * Determine how many input bytes the gzip member starting at `data[0]`
25
+ * consumes, using the low-level `convert()` API. The decoded output is
26
+ * discarded — GJS does not write the out-buffer back to JS (see the
27
+ * performance contract at the top of this file) — but `bytes_read` is
28
+ * accurate, which is exactly what slicing one member off a concatenated gzip
29
+ * stream needs.
30
+ *
31
+ * The input is fed in {@link CONVERT_INPUT_SLICE} slices, never as the full
32
+ * remaining tail: `convert()` copies its whole `inbuf` across the GI boundary
33
+ * per call, so unbounded slices made this scan quadratic in the member size.
34
+ * A slice that ends mid-stream is fine — zlib consumes partial input
35
+ * (including partial headers/trailers) and reports it via `bytes_read`.
36
+ *
37
+ * On malformed or truncated input the scan stops and reports the bytes
38
+ * consumed so far; the caller's real decompression of that slice surfaces the
39
+ * proper GLib error.
40
+ */
41
+ export declare function findGzipMemberEnd(data: Uint8Array): number;
42
+ /**
43
+ * Gzip decompression with Node's `gunzip` semantics: decode ALL concatenated
44
+ * gzip members (multi-member streams are legal gzip and produced by e.g.
45
+ * `gzip -c a b`, bgzip, and some HTTP servers), ignore trailing non-gzip
46
+ * bytes after the last complete member.
47
+ */
48
+ export declare function gunzipWithGio(data: Uint8Array): Uint8Array;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -1,6 +1,6 @@
1
1
  import { Transform } from 'node:stream';
2
2
  import type { ZlibOptions } from 'node:zlib';
3
- type GioFormat = 'gzip' | 'deflate' | 'deflate-raw';
3
+ import { type GioFormat } from './gio-codec.js';
4
4
  type ZlibMode = {
5
5
  kind: 'compress';
6
6
  format: GioFormat;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/zlib",
3
- "version": "0.25.1",
3
+ "version": "0.26.1",
4
4
  "description": "Node.js zlib module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -40,12 +40,12 @@
40
40
  "dependencies": {
41
41
  "@girs/gio-2.0": "^4.1.0",
42
42
  "@girs/glib-2.0": "^4.1.0",
43
- "@gjsify/stream": "^0.25.1"
43
+ "@gjsify/stream": "^0.26.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@gjsify/cli": "^0.25.1",
47
- "@gjsify/unit": "^0.25.1",
48
- "@gjsify/util": "^0.25.1",
46
+ "@gjsify/cli": "^0.26.1",
47
+ "@gjsify/unit": "^0.26.1",
48
+ "@gjsify/util": "^0.26.1",
49
49
  "@types/node": "^25.9.2",
50
50
  "typescript": "^6.0.3"
51
51
  },