@gjsify/zlib 0.4.23 → 0.4.25

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.
Files changed (2) hide show
  1. package/lib/esm/index.js +1 -1
  2. package/package.json +3 -3
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{ZlibTransform as e,createBrotliCompress as t,createBrotliDecompress as n,createDeflate as r,createDeflateRaw as i,createGunzip as a,createGzip as o,createInflate as s,createInflateRaw as c,createUnzip as l}from"./transform-streams.js";import u from"@girs/gio-2.0";import d from"@girs/glib-2.0";const f=globalThis.CompressionStream!==void 0;function getGioFormat(e){switch(e){case`gzip`:return u.ZlibCompressorFormat.GZIP;case`deflate`:return u.ZlibCompressorFormat.ZLIB;case`deflate-raw`:return u.ZlibCompressorFormat.RAW}}function compressWithGio(e,t){let n=new u.ZlibCompressor({format:getGioFormat(t)}),r=new u.ConverterOutputStream({base_stream:u.MemoryOutputStream.new_resizable(),converter:n});r.write_bytes(new d.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 u.ZlibDecompressor({format:getGioFormat(t)}),r=u.MemoryInputStream.new_from_bytes(new d.Bytes(e)),i=new u.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 u.ZlibDecompressor({format:u.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,u.ConverterFlags.NONE);r+=o,e===u.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 compressWithWeb(e,t){let n=new CompressionStream(t),r=n.writable.getWriter();r.write(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),r.close();let i=[],a=n.readable.getReader();for(;;){let{done:e,value:t}=await a.read();if(e)break;i.push(t)}let o=i.reduce((e,t)=>e+t.length,0),s=new Uint8Array(o),c=0;for(let e of i)s.set(e,c),c+=e.length;return s}async function decompressWithWeb(e,t){let n=new DecompressionStream(t),r=n.writable.getWriter();r.write(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),r.close();let i=[],a=n.readable.getReader();for(;;){let{done:e,value:t}=await a.read();if(e)break;i.push(t)}let o=i.reduce((e,t)=>e+t.length,0),s=new Uint8Array(o),c=0;for(let e of i)s.set(e,c),c+=e.length;return s}async function compress(e,t){return f?compressWithWeb(e,t):compressWithGio(e,t)}async function decompress(e,t){return f?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`)}function brotliCompress(e,t,n){(typeof t==`function`?t:n)(Error(`brotliCompress: Brotli is not supported in this environment`),null)}function brotliDecompress(e,t,n){(typeof t==`function`?t:n)(Error(`brotliDecompress: Brotli is not supported in this environment`),null)}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`)}const p={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 m={gzip,gunzip,deflate,inflate,deflateRaw,inflateRaw,gzipSync,gunzipSync,deflateSync,inflateSync,deflateRawSync,inflateRawSync,brotliCompress,brotliDecompress,brotliCompressSync,brotliDecompressSync,createGzip:o,createGunzip:a,createDeflate:r,createInflate:s,createDeflateRaw:i,createInflateRaw:c,createUnzip:l,createBrotliCompress:t,createBrotliDecompress:n,constants:p};export{e as ZlibTransform,brotliCompress,brotliCompressSync,brotliDecompress,brotliDecompressSync,p as constants,t as createBrotliCompress,n as createBrotliDecompress,r as createDeflate,i as createDeflateRaw,a as createGunzip,o as createGzip,s as createInflate,c as createInflateRaw,l as createUnzip,m as default,deflate,deflateRaw,deflateRawSync,deflateSync,gunzip,gunzipSync,gzip,gzipSync,inflate,inflateRaw,inflateRawSync,inflateSync};
1
+ import"./_virtual/_rolldown/runtime.js";import{ZlibTransform as e,createBrotliCompress as t,createBrotliDecompress as n,createDeflate as r,createDeflateRaw as i,createGunzip as a,createGzip as o,createInflate as s,createInflateRaw as c,createUnzip as l}from"./transform-streams.js";import u from"@girs/gio-2.0";import d from"@girs/glib-2.0";const f=globalThis.CompressionStream!==void 0;function getGioFormat(e){switch(e){case`gzip`:return u.ZlibCompressorFormat.GZIP;case`deflate`:return u.ZlibCompressorFormat.ZLIB;case`deflate-raw`:return u.ZlibCompressorFormat.RAW}}function compressWithGio(e,t){let n=new u.ZlibCompressor({format:getGioFormat(t)}),r=new u.ConverterOutputStream({base_stream:u.MemoryOutputStream.new_resizable(),converter:n});r.write_bytes(new d.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 u.ZlibDecompressor({format:getGioFormat(t)}),r=u.MemoryInputStream.new_from_bytes(new d.Bytes(e)),i=new u.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 u.ZlibDecompressor({format:u.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,u.ConverterFlags.NONE);r+=o,e===u.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 compressWithWeb(e,t){let n=new CompressionStream(t),r=n.writable.getWriter();r.write(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),r.close();let i=[],a=n.readable.getReader();for(;;){let{done:e,value:t}=await a.read();if(e)break;i.push(t)}let o=i.reduce((e,t)=>e+t.length,0),s=new Uint8Array(o),c=0;for(let e of i)s.set(e,c),c+=e.length;return s}async function decompressWithWeb(e,t){let n=new DecompressionStream(t),r=n.writable.getWriter();r.write(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),r.close();let i=[],a=n.readable.getReader();for(;;){let{done:e,value:t}=await a.read();if(e)break;i.push(t)}let o=i.reduce((e,t)=>e+t.length,0),s=new Uint8Array(o),c=0;for(let e of i)s.set(e,c),c+=e.length;return s}async function compress(e,t){return f?compressWithWeb(e,t):compressWithGio(e,t)}async function decompress(e,t){return f?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 p=new Uint8Array;function brotliCompress(e,t,n){(typeof t==`function`?t:n)(Error(`brotliCompress: Brotli is not supported in this environment`),p)}function brotliDecompress(e,t,n){(typeof t==`function`?t:n)(Error(`brotliDecompress: Brotli is not supported in this environment`),p)}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`)}const m={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 h={gzip,gunzip,deflate,inflate,deflateRaw,inflateRaw,gzipSync,gunzipSync,deflateSync,inflateSync,deflateRawSync,inflateRawSync,brotliCompress,brotliDecompress,brotliCompressSync,brotliDecompressSync,createGzip:o,createGunzip:a,createDeflate:r,createInflate:s,createDeflateRaw:i,createInflateRaw:c,createUnzip:l,createBrotliCompress:t,createBrotliDecompress:n,constants:m};export{e as ZlibTransform,brotliCompress,brotliCompressSync,brotliDecompress,brotliDecompressSync,m as constants,t as createBrotliCompress,n as createBrotliDecompress,r as createDeflate,i as createDeflateRaw,a as createGunzip,o as createGzip,s as createInflate,c as createInflateRaw,l as createUnzip,h as default,deflate,deflateRaw,deflateRawSync,deflateSync,gunzip,gunzipSync,gzip,gzipSync,inflate,inflateRaw,inflateRawSync,inflateSync};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/zlib",
3
- "version": "0.4.23",
3
+ "version": "0.4.25",
4
4
  "description": "Node.js zlib module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -37,8 +37,8 @@
37
37
  "@girs/glib-2.0": "2.88.0-4.0.1"
38
38
  },
39
39
  "devDependencies": {
40
- "@gjsify/cli": "^0.4.23",
41
- "@gjsify/unit": "^0.4.23",
40
+ "@gjsify/cli": "^0.4.25",
41
+ "@gjsify/unit": "^0.4.25",
42
42
  "@types/node": "^25.9.1",
43
43
  "typescript": "^6.0.3"
44
44
  }