@gjsify/zlib 0.4.44 → 0.5.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.
package/lib/esm/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{Transform as e}from"@gjsify/stream/browser";const t={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,ZLIB_VERNUM:4784,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,ZSTD_COMPRESS:10,ZSTD_DECOMPRESS:11,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_PARAM_MODE:0,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_PARAM_LGWIN:2,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_PARAM_LGBLOCK:3,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8};function toUint8(e){return typeof e==`string`?new TextEncoder().encode(e):e instanceof Uint8Array?e:new Uint8Array(e)}function notSupportedError(e,t){return Object.assign(Error(`zlib.${e} is not supported in the browser (${t})`),{code:`ENOTSUP`,syscall:e})}async function runStream(e,t,n){let r=t===`compress`?globalThis.CompressionStream:globalThis.DecompressionStream;if(!r)throw Error(`zlib browser polyfill requires ${t===`compress`?`CompressionStream`:`DecompressionStream`} (not available in this browser)`);let i=new r(e),a=i.writable.getWriter(),o=i.readable.getReader();a.write(n),a.close();let s=[],c=0;for(;;){let{done:e,value:t}=await o.read();if(e)break;let n=t;s.push(n),c+=n.length}let l=new Uint8Array(c),u=0;for(let e of s)l.set(e,u),u+=e.length;return l}function asyncOp(e,t){return(n,r,i)=>{let a=typeof r==`function`?r:i;if(typeof a!=`function`)throw TypeError(`callback is required`);runStream(e,t,toUint8(n)).then(e=>a(null,e),e=>a(e))}}function syncOp(e,t,n){return(e,t)=>{throw notSupportedError(n,`CompressionStream is async-only — use the callback form`)}}function unsupportedAsyncOp(e,t){return(n,r,i)=>{let a=typeof r==`function`?r:i;if(typeof a!=`function`)throw TypeError(`callback is required`);let o=notSupportedError(e,`${t} is not in the WHATWG Compression Streams spec`);queueMicrotask(()=>a(o))}}function unsupportedSyncOp(e,t){return(n,r)=>{throw notSupportedError(e,`${t} is not in the WHATWG Compression Streams spec`)}}const n=asyncOp(`gzip`,`compress`),r=asyncOp(`gzip`,`decompress`),i=asyncOp(`deflate`,`compress`),a=asyncOp(`deflate`,`decompress`),o=asyncOp(`deflate-raw`,`compress`),s=asyncOp(`deflate-raw`,`decompress`),c=unsupportedAsyncOp(`brotliCompress`,`brotli`),l=unsupportedAsyncOp(`brotliDecompress`,`brotli`),u=unsupportedAsyncOp(`zstdCompress`,`zstd`),d=unsupportedAsyncOp(`zstdDecompress`,`zstd`),f=syncOp(`gzip`,`compress`,`gzipSync`),p=syncOp(`gzip`,`decompress`,`gunzipSync`),m=syncOp(`deflate`,`compress`,`deflateSync`),h=syncOp(`deflate`,`decompress`,`inflateSync`),g=syncOp(`deflate-raw`,`compress`,`deflateRawSync`),_=syncOp(`deflate-raw`,`decompress`,`inflateRawSync`),v=unsupportedSyncOp(`brotliCompressSync`,`brotli`),y=unsupportedSyncOp(`brotliDecompressSync`,`brotli`),b=unsupportedSyncOp(`zstdCompressSync`,`zstd`),x=unsupportedSyncOp(`zstdDecompressSync`,`zstd`);var ZlibTransform=class extends e{_format;_direction;_chunks=[];constructor(e,t){super(),this._format=e,this._direction=t}_transform(e,t,n){this._chunks.push(toUint8(e)),n(null)}_flush(e){let t=this._chunks.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t),r=0;for(let e of this._chunks)n.set(e,r),r+=e.length;runStream(this._format,this._direction,n).then(t=>{this.push(t),e()},t=>e(t))}},Gzip=class extends ZlibTransform{constructor(){super(`gzip`,`compress`)}},Gunzip=class extends ZlibTransform{constructor(){super(`gzip`,`decompress`)}},Deflate=class extends ZlibTransform{constructor(){super(`deflate`,`compress`)}},Inflate=class extends ZlibTransform{constructor(){super(`deflate`,`decompress`)}},DeflateRaw=class extends ZlibTransform{constructor(){super(`deflate-raw`,`compress`)}},InflateRaw=class extends ZlibTransform{constructor(){super(`deflate-raw`,`decompress`)}},BrotliCompress=class extends e{constructor(){throw super(),notSupportedError(`BrotliCompress`,`brotli is not in the WHATWG Compression Streams spec`)}},BrotliDecompress=class extends e{constructor(){throw super(),notSupportedError(`BrotliDecompress`,`brotli is not in the WHATWG Compression Streams spec`)}};const createGzip=e=>new Gzip,createGunzip=e=>new Gunzip,createDeflate=e=>new Deflate,createInflate=e=>new Inflate,createDeflateRaw=e=>new DeflateRaw,createInflateRaw=e=>new InflateRaw,createBrotliCompress=e=>new BrotliCompress,createBrotliDecompress=e=>new BrotliDecompress,createUnzip=e=>new Gunzip,S={constants:t,gzip:n,gunzip:r,deflate:i,inflate:a,deflateRaw:o,inflateRaw:s,brotliCompress:c,brotliDecompress:l,zstdCompress:u,zstdDecompress:d,gzipSync:f,gunzipSync:p,deflateSync:m,inflateSync:h,deflateRawSync:g,inflateRawSync:_,brotliCompressSync:v,brotliDecompressSync:y,zstdCompressSync:b,zstdDecompressSync:x,Gzip,Gunzip,Deflate,Inflate,DeflateRaw,InflateRaw,BrotliCompress,BrotliDecompress,createGzip,createGunzip,createDeflate,createInflate,createDeflateRaw,createInflateRaw,createBrotliCompress,createBrotliDecompress,createUnzip};export{BrotliCompress,BrotliDecompress,Deflate,DeflateRaw,Gunzip,Gzip,Inflate,InflateRaw,c as brotliCompress,v as brotliCompressSync,l as brotliDecompress,y as brotliDecompressSync,t as constants,createBrotliCompress,createBrotliDecompress,createDeflate,createDeflateRaw,createGunzip,createGzip,createInflate,createInflateRaw,createUnzip,S as default,i as deflate,o as deflateRaw,g as deflateRawSync,m as deflateSync,r as gunzip,p as gunzipSync,n as gzip,f as gzipSync,a as inflate,s as inflateRaw,_ as inflateRawSync,h as inflateSync,u as zstdCompress,b as zstdCompressSync,d as zstdDecompress,x as zstdDecompressSync};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Transform as e}from"@gjsify/stream/browser";const t={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,ZLIB_VERNUM:4784,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,ZSTD_COMPRESS:10,ZSTD_DECOMPRESS:11,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_PARAM_MODE:0,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_PARAM_LGWIN:2,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_PARAM_LGBLOCK:3,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8};function toUint8(e){return typeof e==`string`?new TextEncoder().encode(e):e instanceof Uint8Array?e:new Uint8Array(e)}function notSupportedError(e,t){return Object.assign(Error(`zlib.${e} is not supported in the browser (${t})`),{code:`ENOTSUP`,syscall:e})}async function runStream(e,t,n){let r=t===`compress`?globalThis.CompressionStream:globalThis.DecompressionStream;if(!r)throw Error(`zlib browser polyfill requires ${t===`compress`?`CompressionStream`:`DecompressionStream`} (not available in this browser)`);let i=new r(e),a=i.writable.getWriter(),o=i.readable.getReader();a.write(n).catch(()=>{}),a.close().catch(()=>{});let s=[],c=0;for(;;){let{done:e,value:t}=await o.read();if(e)break;let n=t;s.push(n),c+=n.length}let l=new Uint8Array(c),u=0;for(let e of s)l.set(e,u),u+=e.length;return l}function asyncOp(e,t){return(n,r,i)=>{let a=typeof r==`function`?r:i;if(typeof a!=`function`)throw TypeError(`callback is required`);runStream(e,t,toUint8(n)).then(e=>a(null,e),e=>a(e))}}function syncOp(e,t,n){return(e,t)=>{throw notSupportedError(n,`CompressionStream is async-only — use the callback form`)}}function unsupportedAsyncOp(e,t){return(n,r,i)=>{let a=typeof r==`function`?r:i;if(typeof a!=`function`)throw TypeError(`callback is required`);let o=notSupportedError(e,`${t} is not in the WHATWG Compression Streams spec`);queueMicrotask(()=>a(o))}}function unsupportedSyncOp(e,t){return(n,r)=>{throw notSupportedError(e,`${t} is not in the WHATWG Compression Streams spec`)}}const n=asyncOp(`gzip`,`compress`),r=asyncOp(`gzip`,`decompress`),i=asyncOp(`deflate`,`compress`),a=asyncOp(`deflate`,`decompress`),o=asyncOp(`deflate-raw`,`compress`),s=asyncOp(`deflate-raw`,`decompress`),c=unsupportedAsyncOp(`brotliCompress`,`brotli`),l=unsupportedAsyncOp(`brotliDecompress`,`brotli`),u=unsupportedAsyncOp(`zstdCompress`,`zstd`),d=unsupportedAsyncOp(`zstdDecompress`,`zstd`),f=syncOp(`gzip`,`compress`,`gzipSync`),p=syncOp(`gzip`,`decompress`,`gunzipSync`),m=syncOp(`deflate`,`compress`,`deflateSync`),h=syncOp(`deflate`,`decompress`,`inflateSync`),g=syncOp(`deflate-raw`,`compress`,`deflateRawSync`),_=syncOp(`deflate-raw`,`decompress`,`inflateRawSync`),v=unsupportedSyncOp(`brotliCompressSync`,`brotli`),y=unsupportedSyncOp(`brotliDecompressSync`,`brotli`),b=unsupportedSyncOp(`zstdCompressSync`,`zstd`),x=unsupportedSyncOp(`zstdDecompressSync`,`zstd`);var ZlibTransform=class extends e{_format;_direction;_chunks=[];constructor(e,t){super(),this._format=e,this._direction=t}_transform(e,t,n){this._chunks.push(toUint8(e)),n(null)}_flush(e){let t=this._chunks.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t),r=0;for(let e of this._chunks)n.set(e,r),r+=e.length;runStream(this._format,this._direction,n).then(t=>{this.push(t),e()},t=>e(t))}},Gzip=class extends ZlibTransform{constructor(){super(`gzip`,`compress`)}},Gunzip=class extends ZlibTransform{constructor(){super(`gzip`,`decompress`)}},Deflate=class extends ZlibTransform{constructor(){super(`deflate`,`compress`)}},Inflate=class extends ZlibTransform{constructor(){super(`deflate`,`decompress`)}},DeflateRaw=class extends ZlibTransform{constructor(){super(`deflate-raw`,`compress`)}},InflateRaw=class extends ZlibTransform{constructor(){super(`deflate-raw`,`decompress`)}},BrotliCompress=class extends e{constructor(){throw super(),notSupportedError(`BrotliCompress`,`brotli is not in the WHATWG Compression Streams spec`)}},BrotliDecompress=class extends e{constructor(){throw super(),notSupportedError(`BrotliDecompress`,`brotli is not in the WHATWG Compression Streams spec`)}};const createGzip=e=>new Gzip,createGunzip=e=>new Gunzip,createDeflate=e=>new Deflate,createInflate=e=>new Inflate,createDeflateRaw=e=>new DeflateRaw,createInflateRaw=e=>new InflateRaw,createBrotliCompress=e=>new BrotliCompress,createBrotliDecompress=e=>new BrotliDecompress,createUnzip=e=>new Gunzip,S={constants:t,gzip:n,gunzip:r,deflate:i,inflate:a,deflateRaw:o,inflateRaw:s,brotliCompress:c,brotliDecompress:l,zstdCompress:u,zstdDecompress:d,gzipSync:f,gunzipSync:p,deflateSync:m,inflateSync:h,deflateRawSync:g,inflateRawSync:_,brotliCompressSync:v,brotliDecompressSync:y,zstdCompressSync:b,zstdDecompressSync:x,Gzip,Gunzip,Deflate,Inflate,DeflateRaw,InflateRaw,BrotliCompress,BrotliDecompress,createGzip,createGunzip,createDeflate,createInflate,createDeflateRaw,createInflateRaw,createBrotliCompress,createBrotliDecompress,createUnzip};export{BrotliCompress,BrotliDecompress,Deflate,DeflateRaw,Gunzip,Gzip,Inflate,InflateRaw,c as brotliCompress,v as brotliCompressSync,l as brotliDecompress,y as brotliDecompressSync,t as constants,createBrotliCompress,createBrotliDecompress,createDeflate,createDeflateRaw,createGunzip,createGzip,createInflate,createInflateRaw,createUnzip,S as default,i as deflate,o as deflateRaw,g as deflateRawSync,m as deflateSync,r as gunzip,p as gunzipSync,n as gzip,f as gzipSync,a as inflate,s as inflateRaw,_ as inflateRawSync,h as inflateSync,u as zstdCompress,b as zstdCompressSync,d as zstdDecompress,x as zstdDecompressSync};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{
|
|
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 +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)}
|
|
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};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { ZlibTransform, createGzip, createGunzip, createDeflate, createInflate, createDeflateRaw, createInflateRaw, createUnzip, createBrotliCompress, createBrotliDecompress, } from './transform-streams.js';
|
|
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
4
|
export declare function gzip(data: string | Uint8Array | ArrayBuffer, callback: ZlibCallback): void;
|
|
@@ -55,7 +55,7 @@ export declare const constants: {
|
|
|
55
55
|
Z_DEFAULT_STRATEGY: number;
|
|
56
56
|
Z_DEFLATED: number;
|
|
57
57
|
};
|
|
58
|
-
import { createGzip, createGunzip, createDeflate, createInflate, createDeflateRaw, createInflateRaw, createUnzip, createBrotliCompress, createBrotliDecompress, createZstdCompress, createZstdDecompress } from './transform-streams.js';
|
|
58
|
+
import { Gzip, Gunzip, Deflate, Inflate, DeflateRaw, InflateRaw, Unzip, BrotliCompress, BrotliDecompress, ZstdCompress, ZstdDecompress, createGzip, createGunzip, createDeflate, createInflate, createDeflateRaw, createInflateRaw, createUnzip, createBrotliCompress, createBrotliDecompress, createZstdCompress, createZstdDecompress } from './transform-streams.js';
|
|
59
59
|
export { createZstdCompress, createZstdDecompress } from './transform-streams.js';
|
|
60
60
|
declare const _default: {
|
|
61
61
|
gzip: typeof gzip;
|
|
@@ -78,6 +78,17 @@ declare const _default: {
|
|
|
78
78
|
zstdDecompress: typeof zstdDecompress;
|
|
79
79
|
zstdCompressSync: typeof zstdCompressSync;
|
|
80
80
|
zstdDecompressSync: typeof zstdDecompressSync;
|
|
81
|
+
Gzip: typeof Gzip;
|
|
82
|
+
Gunzip: typeof Gunzip;
|
|
83
|
+
Deflate: typeof Deflate;
|
|
84
|
+
Inflate: typeof Inflate;
|
|
85
|
+
DeflateRaw: typeof DeflateRaw;
|
|
86
|
+
InflateRaw: typeof InflateRaw;
|
|
87
|
+
Unzip: typeof Unzip;
|
|
88
|
+
BrotliCompress: typeof BrotliCompress;
|
|
89
|
+
BrotliDecompress: typeof BrotliDecompress;
|
|
90
|
+
ZstdCompress: typeof ZstdCompress;
|
|
91
|
+
ZstdDecompress: typeof ZstdDecompress;
|
|
81
92
|
createGzip: typeof createGzip;
|
|
82
93
|
createGunzip: typeof createGunzip;
|
|
83
94
|
createDeflate: typeof createDeflate;
|
|
@@ -1,25 +1,78 @@
|
|
|
1
1
|
import { Transform } from 'node:stream';
|
|
2
2
|
import type { ZlibOptions } from 'node:zlib';
|
|
3
3
|
type GioFormat = 'gzip' | 'deflate' | 'deflate-raw';
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type ZlibMode = {
|
|
5
|
+
kind: 'compress';
|
|
6
|
+
format: GioFormat;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'decompress';
|
|
9
|
+
format: GioFormat;
|
|
10
|
+
} | {
|
|
11
|
+
kind: 'gunzip';
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'unzip';
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Shared base for the zlib streaming classes. Buffers written chunks and runs
|
|
17
|
+
* the codec once on flush. Concrete classes pick a {@link ZlibMode}; they are
|
|
18
|
+
* thin `super(mode)` constructors so the public class identity (`Gzip`,
|
|
19
|
+
* `Inflate`, …) is preserved for `instanceof` / `inherits()`.
|
|
20
|
+
*/
|
|
21
|
+
export declare class ZlibBase extends Transform {
|
|
6
22
|
private _mode;
|
|
7
23
|
private _chunks;
|
|
8
|
-
constructor(
|
|
24
|
+
constructor(mode: ZlibMode, options?: ZlibOptions);
|
|
9
25
|
_transform(chunk: unknown, _encoding: string, callback: (err?: Error) => void): void;
|
|
10
26
|
_flush(callback: (err?: Error) => void): void;
|
|
11
|
-
private
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export
|
|
19
|
-
export declare
|
|
20
|
-
|
|
27
|
+
private _run;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Backwards-compatible alias for the historical export name. New code should
|
|
31
|
+
* use the concrete classes (`Gzip`, `Inflate`, …); this keeps the prior
|
|
32
|
+
* generic base reachable for any external importer.
|
|
33
|
+
*/
|
|
34
|
+
export { ZlibBase as ZlibTransform };
|
|
35
|
+
export declare class Gzip extends ZlibBase {
|
|
36
|
+
constructor(options?: ZlibOptions);
|
|
37
|
+
}
|
|
38
|
+
export declare class Gunzip extends ZlibBase {
|
|
39
|
+
constructor(options?: ZlibOptions);
|
|
40
|
+
}
|
|
41
|
+
export declare class Deflate extends ZlibBase {
|
|
42
|
+
constructor(options?: ZlibOptions);
|
|
43
|
+
}
|
|
44
|
+
export declare class Inflate extends ZlibBase {
|
|
45
|
+
constructor(options?: ZlibOptions);
|
|
46
|
+
}
|
|
47
|
+
export declare class DeflateRaw extends ZlibBase {
|
|
48
|
+
constructor(options?: ZlibOptions);
|
|
49
|
+
}
|
|
50
|
+
export declare class InflateRaw extends ZlibBase {
|
|
51
|
+
constructor(options?: ZlibOptions);
|
|
52
|
+
}
|
|
53
|
+
export declare class Unzip extends ZlibBase {
|
|
54
|
+
constructor(options?: ZlibOptions);
|
|
55
|
+
}
|
|
56
|
+
export declare class BrotliCompress extends Transform {
|
|
57
|
+
constructor();
|
|
58
|
+
}
|
|
59
|
+
export declare class BrotliDecompress extends Transform {
|
|
60
|
+
constructor();
|
|
61
|
+
}
|
|
62
|
+
export declare class ZstdCompress extends Transform {
|
|
63
|
+
constructor();
|
|
64
|
+
}
|
|
65
|
+
export declare class ZstdDecompress extends Transform {
|
|
66
|
+
constructor();
|
|
67
|
+
}
|
|
68
|
+
export declare function createGzip(options?: ZlibOptions): Gzip;
|
|
69
|
+
export declare function createGunzip(options?: ZlibOptions): Gunzip;
|
|
70
|
+
export declare function createDeflate(options?: ZlibOptions): Deflate;
|
|
71
|
+
export declare function createInflate(options?: ZlibOptions): Inflate;
|
|
72
|
+
export declare function createDeflateRaw(options?: ZlibOptions): DeflateRaw;
|
|
73
|
+
export declare function createInflateRaw(options?: ZlibOptions): InflateRaw;
|
|
74
|
+
export declare function createUnzip(options?: ZlibOptions): Unzip;
|
|
21
75
|
export declare function createBrotliCompress(_options?: ZlibOptions): never;
|
|
22
76
|
export declare function createBrotliDecompress(_options?: ZlibOptions): never;
|
|
23
77
|
export declare function createZstdCompress(_options?: ZlibOptions): never;
|
|
24
78
|
export declare function createZstdDecompress(_options?: ZlibOptions): never;
|
|
25
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/zlib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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",
|
|
@@ -39,13 +39,14 @@
|
|
|
39
39
|
],
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@girs/gio-2.0": "2.88.0-4.0.4",
|
|
42
|
-
"@girs/glib-2.0": "2.88.0-4.0.4"
|
|
42
|
+
"@girs/glib-2.0": "2.88.0-4.0.4",
|
|
43
|
+
"@gjsify/stream": "^0.5.1"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@gjsify/cli": "^0.
|
|
46
|
-
"@gjsify/
|
|
47
|
-
"@gjsify/
|
|
48
|
-
"@types/node": "^25.9.
|
|
46
|
+
"@gjsify/cli": "^0.5.1",
|
|
47
|
+
"@gjsify/unit": "^0.5.1",
|
|
48
|
+
"@gjsify/util": "^0.5.1",
|
|
49
|
+
"@types/node": "^25.9.2",
|
|
49
50
|
"typescript": "^6.0.3"
|
|
50
51
|
},
|
|
51
52
|
"gjsify": {
|