@gjsify/zlib 0.60.0 → 0.61.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.
@@ -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}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};
1
+ import"./_virtual/_rolldown/runtime.js";import{MAX_OUTPUT_LENGTH_DEFAULT as e,bufferTooLargeError as t,remainingReadBudget as n}from"./max-output-length.js";import r from"@girs/gio-2.0";import i from"@girs/glib-2.0";const a=256*1024,o=1024*1024;function getGioFormat(e){switch(e){case`gzip`:return r.ZlibCompressorFormat.GZIP;case`deflate`:return r.ZlibCompressorFormat.ZLIB;case`deflate-raw`:return r.ZlibCompressorFormat.RAW}}function hasGzipMagic(e,t=0){return e.length-t>=2&&e[t]===31&&e[t+1]===139}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 s=-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(e,t,n=-1){assertLevel(n);let a=new r.ZlibCompressor({format:getGioFormat(t),level:Math.trunc(n)}),o=new r.ConverterOutputStream({base_stream:r.MemoryOutputStream.new_resizable(),converter:a});o.write_bytes(new i.Bytes(e),null),o.close(null);let s=o.get_base_stream().steal_as_bytes();return new Uint8Array(s.get_data()??[])}function decompressStreamWithGio(a,s,c=e,l=0){let u=new r.ZlibDecompressor({format:getGioFormat(s)}),d=r.MemoryInputStream.new_from_bytes(new i.Bytes(a)),f=new r.ConverterInputStream({base_stream:d,converter:u}),p=[],m=l;try{for(;;){let e=Math.min(o,n(c,m)),r=f.read_bytes(e,null),i=r.get_size();if(i===0)break;if(m+=i,m>c)throw t(c);p.push(new Uint8Array(r.get_data()))}}finally{f.close(null)}return concat(p)}function findGzipMemberEnd(e,t=1/0){let n=new r.ZlibDecompressor({format:r.ZlibCompressorFormat.GZIP}),i=new Uint8Array(262144),o=0,s=0;for(;;){let c=e.subarray(o,o+a);try{let[e,a,l]=n.convert(c,i,r.ConverterFlags.NONE);if(o+=a,s+=l,e===r.ConverterResult.FINISHED||s>t||a===0&&l===0)return o}catch{return o}}}function gunzipWithGio(t,n=e){let r=[],i=0,a=0;for(;hasGzipMagic(t,i);){let e=t.subarray(i),o=findGzipMemberEnd(e,n-a);if(o<=0)break;let s=decompressStreamWithGio(e.subarray(0,o),`gzip`,n,a);r.push(s),a+=s.length,i+=o}return r.length===0?decompressStreamWithGio(t,`gzip`,n):concat(r)}export{a as CONVERT_INPUT_SLICE,s as DEFAULT_LEVEL,o as STREAM_READ_CHUNK,assertLevel,compressWithGio,decompressStreamWithGio,findGzipMemberEnd,getGioFormat,gunzipWithGio,hasGzipMagic};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
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};
1
+ import"./_virtual/_rolldown/runtime.js";import{MAX_OUTPUT_LENGTH_DEFAULT as e,bufferTooLargeError as t,isBufferTooLargeError as n,resolveMaxOutputLength as r}from"./max-output-length.js";import{assertLevel as i,compressWithGio as a,decompressStreamWithGio as o,gunzipWithGio as s,hasGzipMagic as c}from"./gio-codec.js";import{BrotliCompress as l,BrotliDecompress as u,Deflate as d,DeflateRaw as f,Gunzip as p,Gzip as m,Inflate as h,InflateRaw as g,Unzip as _,ZlibBase as v,ZstdCompress as y,ZstdDecompress as b,createBrotliCompress as x,createBrotliDecompress as S,createDeflate as C,createDeflateRaw as w,createGunzip as T,createGzip as E,createInflate as D,createInflateRaw as O,createUnzip as k,createZstdCompress as A,createZstdDecompress as j}from"./transform-streams.js";const hasWebCompression=()=>globalThis.CompressionStream!==void 0;function decompressWithGio(e,t,n){return t===`gzip`?s(e,n):o(e,t,n)}function unzipFormat(e){return c(e)?`gzip`:`deflate`}function assertWithinLimit(e,n){if(e.length>n)throw t(n);return e}async function runWebTransform(e,n,r=1/0){let i=new ReadableStream({start(t){t.enqueue(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),t.close()}}),a=[],o=0,s=i.pipeThrough(n).getReader();for(;;){let{done:e,value:n}=await s.read();if(e)break;if(o+=n.length,o>r)throw await s.cancel(),t(r);a.push(n)}let c=a.reduce((e,t)=>e+t.length,0),l=new Uint8Array(c),u=0;for(let e of a)l.set(e,u),u+=e.length;return l}async function compressWithWeb(e,t){return runWebTransform(e,new CompressionStream(t))}async function decompressWithWeb(e,t,n){return runWebTransform(e,new DecompressionStream(t),n)}function requestedLevel(e){let t=e?.level;if(!(t===void 0||t===-1))return i(t),t}async function compress(e,t,n,r){return n===void 0&&hasWebCompression()?assertWithinLimit(await compressWithWeb(e,t),r):assertWithinLimit(a(e,t,n),r)}async function decompress(t,r,i){if(hasWebCompression()&&i>=e)try{return await decompressWithWeb(t,r,i)}catch(e){if(r!==`gzip`||n(e))throw e;return decompressWithGio(t,r,i)}return decompressWithGio(t,r,i)}function toUint8Array(e){return typeof e==`string`?new TextEncoder().encode(e):e instanceof ArrayBuffer?new Uint8Array(e):e}function runAsync(e,t,n,i){let a=typeof t==`function`?t:n,o=typeof t==`function`?void 0:t,s=r(o);i(toUint8Array(e),o,s).then(e=>a(null,e),e=>a(e instanceof Error?e:Error(String(e)),new Uint8Array))}function compressAsync(e){return(t,n,r)=>compress(t,e,requestedLevel(n),r)}function decompressAsync(e){return(t,n,r)=>decompress(t,e,r)}function gzip(e,t,n){runAsync(e,t,n,compressAsync(`gzip`))}function gunzip(e,t,n){runAsync(e,t,n,decompressAsync(`gzip`))}function deflate(e,t,n){runAsync(e,t,n,compressAsync(`deflate`))}function inflate(e,t,n){runAsync(e,t,n,decompressAsync(`deflate`))}function deflateRaw(e,t,n){runAsync(e,t,n,compressAsync(`deflate-raw`))}function inflateRaw(e,t,n){runAsync(e,t,n,decompressAsync(`deflate-raw`))}function unzip(e,t,n){runAsync(e,t,n,(e,t,n)=>decompress(e,unzipFormat(e),n))}function compressSync(e,t,n){let i=r(n);return assertWithinLimit(a(toUint8Array(e),t,n?.level??-1),i)}function gzipSync(e,t){return compressSync(e,`gzip`,t)}function gunzipSync(e,t){return decompressWithGio(toUint8Array(e),`gzip`,r(t))}function deflateSync(e,t){return compressSync(e,`deflate`,t)}function inflateSync(e,t){return decompressWithGio(toUint8Array(e),`deflate`,r(t))}function deflateRawSync(e,t){return compressSync(e,`deflate-raw`,t)}function inflateRawSync(e,t){return decompressWithGio(toUint8Array(e),`deflate-raw`,r(t))}function unzipSync(e,t){let n=toUint8Array(e);return decompressWithGio(n,unzipFormat(n),r(t))}const M=new Uint8Array;function brotliCompress(e,t,n){(typeof t==`function`?t:n)(Error(`brotliCompress: Brotli is not supported in this environment`),M)}function brotliDecompress(e,t,n){(typeof t==`function`?t:n)(Error(`brotliDecompress: Brotli is not supported in this environment`),M)}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,M)}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,M)}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 N={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 P={gzip,gunzip,deflate,inflate,deflateRaw,inflateRaw,unzip,gzipSync,gunzipSync,deflateSync,inflateSync,deflateRawSync,inflateRawSync,unzipSync,brotliCompress,brotliDecompress,brotliCompressSync,brotliDecompressSync,zstdCompress,zstdDecompress,zstdCompressSync,zstdDecompressSync,Gzip:m,Gunzip:p,Deflate:d,Inflate:h,DeflateRaw:f,InflateRaw:g,Unzip:_,BrotliCompress:l,BrotliDecompress:u,ZstdCompress:y,ZstdDecompress:b,createGzip:E,createGunzip:T,createDeflate:C,createInflate:D,createDeflateRaw:w,createInflateRaw:O,createUnzip:k,createBrotliCompress:x,createBrotliDecompress:S,createZstdCompress:A,createZstdDecompress:j,constants:N};export{l as BrotliCompress,u as BrotliDecompress,d as Deflate,f as DeflateRaw,p as Gunzip,m as Gzip,h as Inflate,g as InflateRaw,_ as Unzip,v as ZlibTransform,y as ZstdCompress,b as ZstdDecompress,brotliCompress,brotliCompressSync,brotliDecompress,brotliDecompressSync,N as constants,x as createBrotliCompress,S as createBrotliDecompress,C as createDeflate,w as createDeflateRaw,T as createGunzip,E as createGzip,D as createInflate,O as createInflateRaw,k as createUnzip,A as createZstdCompress,j as createZstdDecompress,P as default,deflate,deflateRaw,deflateRawSync,deflateSync,gunzip,gunzipSync,gzip,gzipSync,inflate,inflateRaw,inflateRawSync,inflateSync,unzip,unzipSync,zstdCompress,zstdCompressSync,zstdDecompress,zstdDecompressSync};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";const e=2**53-1,t=`options.maxOutputLength`;function withCode(e,t){return Object.assign(e,{code:t})}function addNumericalSeparator(e){let t=``,n=e.length,r=+(e[0]===`-`);for(;n>=r+4;n-=3)t=`_${e.slice(n-3,n)}${t}`;return`${e.slice(0,n)}${t}`}function formatReceivedNumber(e){return Number.isInteger(e)&&Math.abs(e)>2**32?addNumericalSeparator(String(e)):Object.is(e,-0)?`-0`:String(e)}function describeType(e){if(e===null)return`null`;switch(typeof e){case`bigint`:return`type bigint (${e}n)`;case`boolean`:return`type boolean (${e})`;case`symbol`:return`type symbol (${String(e)})`;case`function`:return`function ${e.name}`;case`string`:{let t=e.length>28?`${e.slice(0,25)}...`:e;return t.includes(`'`)?`type string (${JSON.stringify(t)})`:`type string ('${t}')`}default:{let t=e.constructor;return t?.name?`an instance of ${t.name}`:`type ${typeof e}`}}}function outOfRange(e,n){return withCode(RangeError(`The value of "${t}" is out of range. It must be ${e}. Received ${formatReceivedNumber(n)}`),`ERR_OUT_OF_RANGE`)}function resolveMaxOutputLength(n){let r=n?.maxOutputLength;if(r===void 0)return e;if(typeof r!=`number`)throw withCode(TypeError(`The "${t}" property must be of type number. Received ${describeType(r)}`),`ERR_INVALID_ARG_TYPE`);if(Number.isNaN(r))return e;if(!Number.isFinite(r))throw outOfRange(`a finite number`,r);if(r<1||r>e)throw outOfRange(`>= 1 and <= ${e}`,r);return r}function bufferTooLargeError(e){return withCode(RangeError(`Cannot create a Buffer larger than ${e} bytes`),`ERR_BUFFER_TOO_LARGE`)}function isBufferTooLargeError(e){return e instanceof RangeError&&e.code===`ERR_BUFFER_TOO_LARGE`}function remainingReadBudget(e,t){return Math.floor(e-t)+1}export{e as MAX_OUTPUT_LENGTH_DEFAULT,bufferTooLargeError,isBufferTooLargeError,remainingReadBudget,resolveMaxOutputLength};
@@ -1 +1 @@
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};
1
+ import"./_virtual/_rolldown/runtime.js";import{resolveMaxOutputLength as e}from"./max-output-length.js";import{compressWithGio as t,decompressStreamWithGio as n,gunzipWithGio as r,hasGzipMagic as i}from"./gio-codec.js";import{Transform as a}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 a{_mode;_chunks=[];constructor(t,n){e(n),super(n),this._mode=t}_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 a=this._mode;switch(a.kind){case`compress`:return t(e,a.format);case`decompress`:return n(e,a.format);case`gunzip`:return r(e);case`unzip`:return i(e)?r(e):n(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 a{constructor(){throw super(),Error(`BrotliCompress is not supported on GJS (no Brotli in GLib)`)}},BrotliDecompress=class extends a{constructor(){throw super(),Error(`BrotliDecompress is not supported on GJS (no Brotli in GLib)`)}},ZstdCompress=class extends a{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 a{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};
@@ -12,6 +12,8 @@ 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
+ /** RFC 1952 §2.3.1: a gzip member starts with the magic bytes 1f 8b. */
16
+ export declare function hasGzipMagic(data: Uint8Array, offset?: number): boolean;
15
17
  /** `Gio.ZlibCompressor:level`'s own "pick the zlib default" value. */
16
18
  export declare const DEFAULT_LEVEL = -1;
17
19
  /**
@@ -63,8 +65,13 @@ export declare function compressWithGio(data: Uint8Array, format: GioFormat, lev
63
65
  * One-shot decompression of a single zlib/raw/gzip stream via
64
66
  * `Gio.ConverterInputStream`. For gzip this decodes exactly ONE member —
65
67
  * concatenated members need {@link gunzipWithGio}.
68
+ *
69
+ * `maxOutputLength` is Node's zip-bomb guard, counted from `produced` (the
70
+ * output earlier gzip members already used). Each read asks for no more than
71
+ * the remaining budget plus one byte, so decoding stops at the first byte past
72
+ * the limit and never holds more than the limit plus one read in memory.
66
73
  */
67
- export declare function decompressStreamWithGio(data: Uint8Array, format: GioFormat): Uint8Array;
74
+ export declare function decompressStreamWithGio(data: Uint8Array, format: GioFormat, maxOutputLength?: number, produced?: number): Uint8Array;
68
75
  /**
69
76
  * Determine how many input bytes the gzip member starting at `data[0]`
70
77
  * consumes, using the low-level `convert()` API. The decoded output is
@@ -82,12 +89,18 @@ export declare function decompressStreamWithGio(data: Uint8Array, format: GioFor
82
89
  * On malformed or truncated input the scan stops and reports the bytes
83
90
  * consumed so far; the caller's real decompression of that slice surfaces the
84
91
  * proper GLib error.
92
+ *
93
+ * The scan inflates too, so it honours `outputLimit` as well: a zip-bomb member
94
+ * would otherwise be inflated in full here before the bounded decode ever ran.
95
+ * Once more than `outputLimit` bytes came out it stops, and the caller's decode
96
+ * of the consumed prefix, which yields at least as much, raises
97
+ * `ERR_BUFFER_TOO_LARGE`.
85
98
  */
86
- export declare function findGzipMemberEnd(data: Uint8Array): number;
99
+ export declare function findGzipMemberEnd(data: Uint8Array, outputLimit?: number): number;
87
100
  /**
88
101
  * Gzip decompression with Node's `gunzip` semantics: decode ALL concatenated
89
102
  * gzip members (multi-member streams are legal gzip and produced by e.g.
90
103
  * `gzip -c a b`, bgzip, and some HTTP servers), ignore trailing non-gzip
91
104
  * bytes after the last complete member.
92
105
  */
93
- export declare function gunzipWithGio(data: Uint8Array): Uint8Array;
106
+ export declare function gunzipWithGio(data: Uint8Array, maxOutputLength?: number): Uint8Array;
@@ -1,24 +1,28 @@
1
1
  export { ZlibTransform, Gzip, Gunzip, Deflate, Inflate, DeflateRaw, InflateRaw, Unzip, BrotliCompress, BrotliDecompress, ZstdCompress, ZstdDecompress, createGzip, createGunzip, createDeflate, createInflate, createDeflateRaw, createInflateRaw, createUnzip, createBrotliCompress, createBrotliDecompress, } from './transform-streams.js';
2
2
  import type { ZlibOptions } from 'node:zlib';
3
3
  type ZlibCallback = (error: Error | null, result: Uint8Array) => void;
4
- export declare function gzip(data: string | Uint8Array | ArrayBuffer, callback: ZlibCallback): void;
5
- export declare function gzip(data: string | Uint8Array | ArrayBuffer, options: ZlibOptions, callback: ZlibCallback): void;
6
- export declare function gunzip(data: string | Uint8Array | ArrayBuffer, callback: ZlibCallback): void;
7
- export declare function gunzip(data: string | Uint8Array | ArrayBuffer, options: ZlibOptions, callback: ZlibCallback): void;
8
- export declare function deflate(data: string | Uint8Array | ArrayBuffer, callback: ZlibCallback): void;
9
- export declare function deflate(data: string | Uint8Array | ArrayBuffer, options: ZlibOptions, callback: ZlibCallback): void;
10
- export declare function inflate(data: string | Uint8Array | ArrayBuffer, callback: ZlibCallback): void;
11
- export declare function inflate(data: string | Uint8Array | ArrayBuffer, options: ZlibOptions, callback: ZlibCallback): void;
12
- export declare function deflateRaw(data: string | Uint8Array | ArrayBuffer, callback: ZlibCallback): void;
13
- export declare function deflateRaw(data: string | Uint8Array | ArrayBuffer, options: ZlibOptions, callback: ZlibCallback): void;
14
- export declare function inflateRaw(data: string | Uint8Array | ArrayBuffer, callback: ZlibCallback): void;
15
- export declare function inflateRaw(data: string | Uint8Array | ArrayBuffer, options: ZlibOptions, callback: ZlibCallback): void;
16
- export declare function gzipSync(data: string | Uint8Array | ArrayBuffer, options?: ZlibOptions): Uint8Array;
17
- export declare function gunzipSync(data: string | Uint8Array | ArrayBuffer, _options?: ZlibOptions): Uint8Array;
18
- export declare function deflateSync(data: string | Uint8Array | ArrayBuffer, options?: ZlibOptions): Uint8Array;
19
- export declare function inflateSync(data: string | Uint8Array | ArrayBuffer, _options?: ZlibOptions): Uint8Array;
20
- export declare function deflateRawSync(data: string | Uint8Array | ArrayBuffer, options?: ZlibOptions): Uint8Array;
21
- export declare function inflateRawSync(data: string | Uint8Array | ArrayBuffer, _options?: ZlibOptions): Uint8Array;
4
+ type ZlibInput = string | Uint8Array | ArrayBuffer;
5
+ export declare function gzip(data: ZlibInput, callback: ZlibCallback): void;
6
+ export declare function gzip(data: ZlibInput, options: ZlibOptions, callback: ZlibCallback): void;
7
+ export declare function gunzip(data: ZlibInput, callback: ZlibCallback): void;
8
+ export declare function gunzip(data: ZlibInput, options: ZlibOptions, callback: ZlibCallback): void;
9
+ export declare function deflate(data: ZlibInput, callback: ZlibCallback): void;
10
+ export declare function deflate(data: ZlibInput, options: ZlibOptions, callback: ZlibCallback): void;
11
+ export declare function inflate(data: ZlibInput, callback: ZlibCallback): void;
12
+ export declare function inflate(data: ZlibInput, options: ZlibOptions, callback: ZlibCallback): void;
13
+ export declare function deflateRaw(data: ZlibInput, callback: ZlibCallback): void;
14
+ export declare function deflateRaw(data: ZlibInput, options: ZlibOptions, callback: ZlibCallback): void;
15
+ export declare function inflateRaw(data: ZlibInput, callback: ZlibCallback): void;
16
+ export declare function inflateRaw(data: ZlibInput, options: ZlibOptions, callback: ZlibCallback): void;
17
+ export declare function unzip(data: ZlibInput, callback: ZlibCallback): void;
18
+ export declare function unzip(data: ZlibInput, options: ZlibOptions, callback: ZlibCallback): void;
19
+ export declare function gzipSync(data: ZlibInput, options?: ZlibOptions): Uint8Array;
20
+ export declare function gunzipSync(data: ZlibInput, options?: ZlibOptions): Uint8Array;
21
+ export declare function deflateSync(data: ZlibInput, options?: ZlibOptions): Uint8Array;
22
+ export declare function inflateSync(data: ZlibInput, options?: ZlibOptions): Uint8Array;
23
+ export declare function deflateRawSync(data: ZlibInput, options?: ZlibOptions): Uint8Array;
24
+ export declare function inflateRawSync(data: ZlibInput, options?: ZlibOptions): Uint8Array;
25
+ export declare function unzipSync(data: ZlibInput, options?: ZlibOptions): Uint8Array;
22
26
  export declare function brotliCompress(data: string | Uint8Array | ArrayBuffer, optionsOrCallback: ZlibOptions | ZlibCallback, callback?: ZlibCallback): void;
23
27
  export declare function brotliDecompress(data: string | Uint8Array | ArrayBuffer, optionsOrCallback: ZlibOptions | ZlibCallback, callback?: ZlibCallback): void;
24
28
  export declare function brotliCompressSync(_data: string | Uint8Array | ArrayBuffer, _options?: ZlibOptions): Uint8Array;
@@ -64,12 +68,14 @@ declare const _default: {
64
68
  inflate: typeof inflate;
65
69
  deflateRaw: typeof deflateRaw;
66
70
  inflateRaw: typeof inflateRaw;
71
+ unzip: typeof unzip;
67
72
  gzipSync: typeof gzipSync;
68
73
  gunzipSync: typeof gunzipSync;
69
74
  deflateSync: typeof deflateSync;
70
75
  inflateSync: typeof inflateSync;
71
76
  deflateRawSync: typeof deflateRawSync;
72
77
  inflateRawSync: typeof inflateRawSync;
78
+ unzipSync: typeof unzipSync;
73
79
  brotliCompress: typeof brotliCompress;
74
80
  brotliDecompress: typeof brotliDecompress;
75
81
  brotliCompressSync: typeof brotliCompressSync;
@@ -0,0 +1,28 @@
1
+ import type { ZlibOptions } from 'node:zlib';
2
+ /**
3
+ * Node's default and upper bound: `buffer.kMaxLength`, which is
4
+ * `Number.MAX_SAFE_INTEGER` since Node 22. The bound is what the
5
+ * `ERR_OUT_OF_RANGE` message prints, so it is spelled as Node spells it rather
6
+ * than as the largest buffer this host could actually allocate.
7
+ */
8
+ export declare const MAX_OUTPUT_LENGTH_DEFAULT: number;
9
+ type CodedError<E extends Error> = E & {
10
+ code: string;
11
+ };
12
+ /**
13
+ * Validate `options.maxOutputLength` exactly as Node's `checkRangesOrGetDefault`
14
+ * does. Measured on Node 24: `undefined` and `NaN` fall back to the default,
15
+ * `±Infinity` is "not a finite number", anything below 1 (including `-0`) or
16
+ * above the default is out of range, a non-number is `ERR_INVALID_ARG_TYPE`, and
17
+ * a fractional limit such as 1.5 is accepted as given.
18
+ */
19
+ export declare function resolveMaxOutputLength(options?: ZlibOptions): number;
20
+ export declare function bufferTooLargeError(maxOutputLength: number): CodedError<RangeError>;
21
+ export declare function isBufferTooLargeError(err: unknown): boolean;
22
+ /**
23
+ * How many more bytes a decoder may request before it has provably crossed the
24
+ * limit: everything still allowed plus the one byte that proves the excess. A
25
+ * fractional limit (Node accepts 1.5) allows its integer part.
26
+ */
27
+ export declare function remainingReadBudget(maxOutputLength: number, produced: number): number;
28
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/zlib",
3
- "version": "0.60.0",
3
+ "version": "0.61.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",
@@ -40,12 +40,12 @@
40
40
  "dependencies": {
41
41
  "@girs/gio-2.0": "5.4.0",
42
42
  "@girs/glib-2.0": "5.4.0",
43
- "@gjsify/stream": "^0.60.0"
43
+ "@gjsify/stream": "^0.61.0"
44
44
  },
45
45
  "devDependencies": {
46
- "@gjsify/cli": "^0.60.0",
47
- "@gjsify/unit": "^0.60.0",
48
- "@gjsify/util": "^0.60.0",
46
+ "@gjsify/cli": "^0.61.0",
47
+ "@gjsify/unit": "^0.61.0",
48
+ "@gjsify/util": "^0.61.0",
49
49
  "@types/node": "^25.9.2",
50
50
  "typescript": "^6.0.3"
51
51
  },