@php-wasm/stream-compression
Advanced tools
+1
-1
@@ -1,2 +0,2 @@ | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("@php-wasm/node-polyfills");const F=require("@php-wasm/util");function U(...e){const r=new Uint8Array(e.reduce((n,a)=>n+a.length,0));let t=0;for(const n of e)r.set(n,t),t+=n.length;return r}function S(e){if(e===void 0){let r=new Uint8Array;return new TransformStream({transform(t){r=U(r,t)},flush(t){t.enqueue(r)}})}else{const r=new ArrayBuffer(e||0);let t=0;return new TransformStream({transform(n){new Uint8Array(r).set(n,t),t+=n.byteLength},flush(n){n.enqueue(new Uint8Array(r))}})}}function A(e,r){if(r===0)return new ReadableStream({start(a){a.close()}});const t=e.getReader({mode:"byob"});let n=0;return new ReadableStream({async pull(a){const{value:i,done:s}=await t.read(new Uint8Array(r-n));if(s){t.releaseLock(),a.close();return}n+=i.length,a.enqueue(i),n>=r&&(t.releaseLock(),a.close())},cancel(){t.cancel()}})}async function c(e,r){return r!==void 0&&(e=A(e,r)),await e.pipeThrough(S(r)).getReader().read().then(({value:t})=>t)}async function _(e,r){return new File([await c(r)],e)}function E(e){if(e instanceof ReadableStream)return e;let r;return Symbol.asyncIterator in e?r=e[Symbol.asyncIterator]():Symbol.iterator in e?r=e[Symbol.iterator]():r=e,new ReadableStream({async pull(t){const{done:n,value:a}=await r.next();if(n){t.close();return}t.enqueue(a)}})}class q extends File{constructor(r,t,n){super([],t,{type:n==null?void 0:n.type}),this.readableStream=r,this.filesize=n==null?void 0:n.filesize}slice(){throw new Error("slice() is not possible on a StreamedFile")}stream(){return this.readableStream}async text(){return new TextDecoder().decode(await this.arrayBuffer())}async arrayBuffer(){return await c(this.stream())}}ReadableStream.prototype[Symbol.asyncIterator]||(ReadableStream.prototype[Symbol.asyncIterator]=async function*(){const e=this.getReader();try{for(;;){const{done:r,value:t}=await e.read();if(r)return;yield t}}finally{e.releaseLock()}},ReadableStream.prototype.iterate=ReadableStream.prototype[Symbol.asyncIterator]);const N=32,h=67324752,y=33639248,g=101010256,M=0,T=8;function b(e){return new TransformStream({transform(r,t){e(r)&&t.enqueue(r)}})}function k(e){let r=!1;return new TransformStream({async transform(t,n){r||(r=!0,n.enqueue(e)),n.enqueue(t)}})}function x(e){return new TransformStream({async transform(r,t){t.enqueue(r)},async flush(r){r.enqueue(e)}})}function w(e,r){return O(e,r).pipeThrough(new TransformStream({async transform(t,n){const a=new File([t.bytes],new TextDecoder().decode(t.path),{type:t.isDirectory?"directory":void 0});n.enqueue(a)}}))}const v=()=>!0;function O(e,r=v){return new ReadableStream({async pull(n){const a=await P(e);if(!a){n.close();return}n.enqueue(a)}}).pipeThrough(b(({signature:n})=>n===h)).pipeThrough(b(r))}async function P(e){const t=new DataView((await c(e,4)).buffer).getUint32(0,!0);return t===h?await L(e,!0):t===y?await R(e,!0):t===g?await I(e,!0):null}async function L(e,r=!1){if(!r&&new DataView((await c(e,4)).buffer).getUint32(0,!0)!==h)return null;const t=new DataView((await c(e,26)).buffer),n=t.getUint16(22,!0),a=t.getUint16(24,!0),i={signature:h,version:t.getUint32(0,!0),generalPurpose:t.getUint16(2,!0),compressionMethod:t.getUint16(4,!0),lastModifiedTime:t.getUint16(6,!0),lastModifiedDate:t.getUint16(8,!0),crc:t.getUint32(10,!0),compressedSize:t.getUint32(14,!0),uncompressedSize:t.getUint32(18,!0)};i.path=await c(e,n),i.isDirectory=C(i.path),i.extra=await c(e,a);let s=A(e,i.compressedSize);if(i.compressionMethod===T){const o=new Uint8Array(10);o.set([31,139,8]);const f=new Uint8Array(8),u=new DataView(f.buffer);u.setUint32(0,i.crc,!0),u.setUint32(4,i.uncompressedSize%2**32,!0),s=s.pipeThrough(k(o)).pipeThrough(x(f)).pipeThrough(new DecompressionStream("gzip"))}return i.bytes=await s.pipeThrough(S(i.uncompressedSize)).getReader().read().then(({value:o})=>o),i}async function R(e,r=!1){if(!r&&new DataView((await c(e,4)).buffer).getUint32(0,!0)!==y)return null;const t=new DataView((await c(e,42)).buffer),n=t.getUint16(24,!0),a=t.getUint16(26,!0),i=t.getUint16(28,!0),s={signature:y,versionCreated:t.getUint16(0,!0),versionNeeded:t.getUint16(2,!0),generalPurpose:t.getUint16(4,!0),compressionMethod:t.getUint16(6,!0),lastModifiedTime:t.getUint16(8,!0),lastModifiedDate:t.getUint16(10,!0),crc:t.getUint32(12,!0),compressedSize:t.getUint32(16,!0),uncompressedSize:t.getUint32(20,!0),diskNumber:t.getUint16(30,!0),internalAttributes:t.getUint16(32,!0),externalAttributes:t.getUint32(34,!0),firstByteAt:t.getUint32(38,!0)};return s.lastByteAt=s.firstByteAt+N+n+i+a+s.compressedSize-1,s.path=await c(e,n),s.isDirectory=C(s.path),s.extra=await c(e,a),s.fileComment=await c(e,i),s}function C(e){return e[e.byteLength-1]==47}async function I(e,r=!1){if(!r&&new DataView((await c(e,4)).buffer).getUint32(0,!0)!==g)return null;const t=new DataView((await c(e,18)).buffer),n={signature:g,numberOfDisks:t.getUint16(0,!0),centralDirectoryStartDisk:t.getUint16(2,!0),numberCentralDirectoryRecordsOnThisDisk:t.getUint16(4,!0),numberCentralDirectoryRecords:t.getUint16(6,!0),centralDirectorySize:t.getUint32(8,!0),centralDirectoryOffset:t.getUint32(12,!0)},a=t.getUint16(16,!0);return n.comment=await c(e,a),n}const z=110*1024,V=10*1024,H=1024*1024*1,Z=new F.Semaphore({concurrency:10}),D=()=>!0;async function G(e,r=D){if(r===D){const d=await fetch(e);return w(d.body)}const t=await B(e);if(t<=H){const d=await fetch(e);return w(d.body)}const n=await fetch(e,{headers:{Range:"bytes=0-0","Accept-Encoding":"none"}}),[a,i]=n.body.tee(),s=a.getReader(),{value:o}=await s.read(),{done:f}=await s.read();if(s.releaseLock(),a.cancel(),!((o==null?void 0:o.length)===1&&f))return w(i);i.cancel();const l=await J(e,t);return W(l).pipeThrough(b(r)).pipeThrough($()).pipeThrough(j(l))}function W(e){let r;return new ReadableStream({async start(){r=await Y(e)},async pull(t){const n=await R(r);if(!n){t.close();return}t.enqueue(n)}})}async function Y(e){const r=z;let t=new Uint8Array,n=e.length;do{n=Math.max(0,n-r);const a=Math.min(n+r-1,e.length-1),i=await c(await e.streamBytes(n,a));t=U(i,t);const s=new DataView(i.buffer);for(let o=s.byteLength-4;o>=0;o--){if(s.getUint32(o,!0)!==g)continue;const u=o+12+4;if(t.byteLength<u+4)throw new Error("Central directory not found");const l=s.getUint32(u,!0);if(l<n){const d=await c(await e.streamBytes(l,n-1));t=U(d,t)}else l>n&&(t=t.slice(l-n));return new Blob([t]).stream()}}while(n>=0);throw new Error("Central directory not found")}function $(){let e=0,r=[];return new TransformStream({transform(t,n){t.firstByteAt>e+V&&(n.enqueue(r),r=[]),e=t.lastByteAt,r.push(t)},flush(t){t.enqueue(r)}})}function j(e){let r=!1,t=0,n;const a=[],i=new WritableStream({write(o,f){o.length&&(++t,K(e,o).then(u=>{a.push([o,u])}).catch(u=>{f.error(u)}).finally(()=>{--t}))},abort(){r=!0,n.close()},async close(){r=!0}});return{readable:new ReadableStream({start(o){n=o},async pull(o){for(;;){if(r&&!a.length&&t===0){o.close();return}if(!a.length){await new Promise(p=>setTimeout(p,50));continue}const[l,d]=a[0],m=await L(d);if(!m){a.shift();continue}if(l.find(p=>p.path===m.path)){o.enqueue(m);break}}}}),writable:i}}async function K(e,r){const t=await Z.acquire();try{const n=r[r.length-1];return await e.streamBytes(r[0].firstByteAt,n.lastByteAt)}finally{t()}}async function B(e){return await fetch(e,{method:"HEAD"}).then(r=>r.headers.get("Content-Length")).then(r=>{if(!r)throw new Error("Content-Length header is missing");const t=parseInt(r,10);if(isNaN(t)||t<0)throw new Error("Content-Length header is invalid");return t})}async function J(e,r){return r===void 0&&(r=await B(e)),{length:r,streamBytes:async(t,n)=>await fetch(e,{headers:{Range:`bytes=${t}-${n-1}`,"Accept-Encoding":"none"}}).then(a=>a.body)}}function Q(e){return E(e).pipeThrough(X())}function X(){const e=new Map;let r=0;return new TransformStream({async transform(t,n){const a=new Uint8Array(await t.arrayBuffer());let i=await c(new Blob([a]).stream().pipeThrough(new CompressionStream("gzip")));const s=new DataView(i.buffer).getUint32(i.byteLength-8,!0);i=i.slice(10,i.byteLength-8);const o=new TextEncoder().encode(t.name),f={signature:h,version:2,generalPurpose:0,compressionMethod:t.type==="directory"||i.byteLength===0?M:T,lastModifiedTime:0,lastModifiedDate:0,crc:s,compressedSize:i.byteLength,uncompressedSize:a.byteLength,path:o,extra:new Uint8Array(0)};e.set(r,f);const u=ee(f);n.enqueue(u),r+=u.byteLength,n.enqueue(i),r+=i.byteLength},flush(t){const n=r;let a=0;for(const[o,f]of e.entries()){const u={...f,signature:y,fileComment:new Uint8Array(0),diskNumber:1,internalAttributes:0,externalAttributes:0},l=te(u,o);t.enqueue(l),a+=l.byteLength}const i={signature:g,numberOfDisks:1,centralDirectoryOffset:n,centralDirectorySize:a,centralDirectoryStartDisk:1,numberCentralDirectoryRecordsOnThisDisk:e.size,numberCentralDirectoryRecords:e.size,comment:new Uint8Array(0)},s=ne(i);t.enqueue(s),e.clear()}})}function ee(e){const r=new ArrayBuffer(30+e.path.byteLength+e.extra.byteLength),t=new DataView(r);t.setUint32(0,e.signature,!0),t.setUint16(4,e.version,!0),t.setUint16(6,e.generalPurpose,!0),t.setUint16(8,e.compressionMethod,!0),t.setUint16(10,e.lastModifiedDate,!0),t.setUint16(12,e.lastModifiedTime,!0),t.setUint32(14,e.crc,!0),t.setUint32(18,e.compressedSize,!0),t.setUint32(22,e.uncompressedSize,!0),t.setUint16(26,e.path.byteLength,!0),t.setUint16(28,e.extra.byteLength,!0);const n=new Uint8Array(r);return n.set(e.path,30),n.set(e.extra,30+e.path.byteLength),n}function te(e,r){const t=new ArrayBuffer(46+e.path.byteLength+e.extra.byteLength),n=new DataView(t);n.setUint32(0,e.signature,!0),n.setUint16(4,e.versionCreated,!0),n.setUint16(6,e.versionNeeded,!0),n.setUint16(8,e.generalPurpose,!0),n.setUint16(10,e.compressionMethod,!0),n.setUint16(12,e.lastModifiedDate,!0),n.setUint16(14,e.lastModifiedTime,!0),n.setUint32(16,e.crc,!0),n.setUint32(20,e.compressedSize,!0),n.setUint32(24,e.uncompressedSize,!0),n.setUint16(28,e.path.byteLength,!0),n.setUint16(30,e.extra.byteLength,!0),n.setUint16(32,e.fileComment.byteLength,!0),n.setUint16(34,e.diskNumber,!0),n.setUint16(36,e.internalAttributes,!0),n.setUint32(38,e.externalAttributes,!0),n.setUint32(42,r,!0);const a=new Uint8Array(t);return a.set(e.path,46),a.set(e.extra,46+e.path.byteLength),a}function ne(e){const r=new ArrayBuffer(22+e.comment.byteLength),t=new DataView(r);t.setUint32(0,e.signature,!0),t.setUint16(4,e.numberOfDisks,!0),t.setUint16(6,e.centralDirectoryStartDisk,!0),t.setUint16(8,e.numberCentralDirectoryRecordsOnThisDisk,!0),t.setUint16(10,e.numberCentralDirectoryRecords,!0),t.setUint32(12,e.centralDirectorySize,!0),t.setUint32(16,e.centralDirectoryOffset,!0),t.setUint16(20,e.comment.byteLength,!0);const n=new Uint8Array(r);return n.set(e.comment,22),n}exports.StreamedFile=q;exports.collectBytes=c;exports.collectFile=_;exports.decodeRemoteZip=G;exports.decodeZip=w;exports.encodeZip=Q;exports.iteratorToStream=E; | ||
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("@php-wasm/node-polyfills");const F=require("@php-wasm/util");function U(...e){const r=new Uint8Array(e.reduce((n,a)=>n+a.length,0));let t=0;for(const n of e)r.set(n,t),t+=n.length;return r}function A(e){if(e===void 0){let r=new Uint8Array;return new TransformStream({transform(t){r=U(r,t)},flush(t){t.enqueue(r)}})}else{const r=new ArrayBuffer(e||0);let t=0;return new TransformStream({transform(n){new Uint8Array(r).set(n,t),t+=n.byteLength},flush(n){n.enqueue(new Uint8Array(r))}})}}function E(e,r){if(r===0)return new ReadableStream({start(a){a.close()}});const t=e.getReader({mode:"byob"});let n=0;return new ReadableStream({async pull(a){const{value:i,done:s}=await t.read(new Uint8Array(r-n));if(s){t.releaseLock(),a.close();return}n+=i.length,a.enqueue(i),n>=r&&(t.releaseLock(),a.close())},cancel(){t.cancel()}})}async function c(e,r){return r!==void 0&&(e=E(e,r)),await e.pipeThrough(A(r)).getReader().read().then(({value:t})=>t)}async function _(e,r){return new File([await c(r)],e)}function T(e){if(e instanceof ReadableStream)return e;let r;return Symbol.asyncIterator in e?r=e[Symbol.asyncIterator]():Symbol.iterator in e?r=e[Symbol.iterator]():r=e,new ReadableStream({async pull(t){const{done:n,value:a}=await r.next();if(n){t.close();return}t.enqueue(a)}})}class D extends File{static fromArrayBuffer(r,t,n){return new D(new ReadableStream({start(a){a.enqueue(new Uint8Array(r)),a.close()}}),t,n)}constructor(r,t,n){super([],t,{type:n==null?void 0:n.type}),this.readableStream=r,this.filesize=n==null?void 0:n.filesize}slice(){throw new Error("slice() is not possible on a StreamedFile")}stream(){return this.readableStream}async text(){return new TextDecoder().decode(await this.arrayBuffer())}async arrayBuffer(){return await c(this.stream())}}ReadableStream.prototype[Symbol.asyncIterator]||(ReadableStream.prototype[Symbol.asyncIterator]=async function*(){const e=this.getReader();try{for(;;){const{done:r,value:t}=await e.read();if(r)return;yield t}}finally{e.releaseLock()}},ReadableStream.prototype.iterate=ReadableStream.prototype[Symbol.asyncIterator]);const N=32,h=67324752,y=33639248,g=101010256,M=0,R=8;function b(e){return new TransformStream({transform(r,t){e(r)&&t.enqueue(r)}})}function k(e){let r=!1;return new TransformStream({async transform(t,n){r||(r=!0,n.enqueue(e)),n.enqueue(t)}})}function x(e){return new TransformStream({async transform(r,t){t.enqueue(r)},async flush(r){r.enqueue(e)}})}function w(e,r){return O(e,r).pipeThrough(new TransformStream({async transform(t,n){const a=new File([t.bytes],new TextDecoder().decode(t.path),{type:t.isDirectory?"directory":void 0});n.enqueue(a)}}))}const v=()=>!0;function O(e,r=v){return new ReadableStream({async pull(n){const a=await P(e);if(!a){n.close();return}n.enqueue(a)}}).pipeThrough(b(({signature:n})=>n===h)).pipeThrough(b(r))}async function P(e){const t=new DataView((await c(e,4)).buffer).getUint32(0,!0);return t===h?await L(e,!0):t===y?await C(e,!0):t===g?await I(e,!0):null}async function L(e,r=!1){if(!r&&new DataView((await c(e,4)).buffer).getUint32(0,!0)!==h)return null;const t=new DataView((await c(e,26)).buffer),n=t.getUint16(22,!0),a=t.getUint16(24,!0),i={signature:h,version:t.getUint32(0,!0),generalPurpose:t.getUint16(2,!0),compressionMethod:t.getUint16(4,!0),lastModifiedTime:t.getUint16(6,!0),lastModifiedDate:t.getUint16(8,!0),crc:t.getUint32(10,!0),compressedSize:t.getUint32(14,!0),uncompressedSize:t.getUint32(18,!0)};i.path=await c(e,n),i.isDirectory=B(i.path),i.extra=await c(e,a);let s=E(e,i.compressedSize);if(i.compressionMethod===R){const o=new Uint8Array(10);o.set([31,139,8]);const f=new Uint8Array(8),u=new DataView(f.buffer);u.setUint32(0,i.crc,!0),u.setUint32(4,i.uncompressedSize%2**32,!0),s=s.pipeThrough(k(o)).pipeThrough(x(f)).pipeThrough(new DecompressionStream("gzip"))}return i.bytes=await s.pipeThrough(A(i.uncompressedSize)).getReader().read().then(({value:o})=>o),i}async function C(e,r=!1){if(!r&&new DataView((await c(e,4)).buffer).getUint32(0,!0)!==y)return null;const t=new DataView((await c(e,42)).buffer),n=t.getUint16(24,!0),a=t.getUint16(26,!0),i=t.getUint16(28,!0),s={signature:y,versionCreated:t.getUint16(0,!0),versionNeeded:t.getUint16(2,!0),generalPurpose:t.getUint16(4,!0),compressionMethod:t.getUint16(6,!0),lastModifiedTime:t.getUint16(8,!0),lastModifiedDate:t.getUint16(10,!0),crc:t.getUint32(12,!0),compressedSize:t.getUint32(16,!0),uncompressedSize:t.getUint32(20,!0),diskNumber:t.getUint16(30,!0),internalAttributes:t.getUint16(32,!0),externalAttributes:t.getUint32(34,!0),firstByteAt:t.getUint32(38,!0)};return s.lastByteAt=s.firstByteAt+N+n+i+a+s.compressedSize-1,s.path=await c(e,n),s.isDirectory=B(s.path),s.extra=await c(e,a),s.fileComment=await c(e,i),s}function B(e){return e[e.byteLength-1]==47}async function I(e,r=!1){if(!r&&new DataView((await c(e,4)).buffer).getUint32(0,!0)!==g)return null;const t=new DataView((await c(e,18)).buffer),n={signature:g,numberOfDisks:t.getUint16(0,!0),centralDirectoryStartDisk:t.getUint16(2,!0),numberCentralDirectoryRecordsOnThisDisk:t.getUint16(4,!0),numberCentralDirectoryRecords:t.getUint16(6,!0),centralDirectorySize:t.getUint32(8,!0),centralDirectoryOffset:t.getUint32(12,!0)},a=t.getUint16(16,!0);return n.comment=await c(e,a),n}const z=110*1024,V=10*1024,H=1024*1024*1,Z=new F.Semaphore({concurrency:10}),S=()=>!0;async function G(e,r=S){if(r===S){const d=await fetch(e);return w(d.body)}const t=await q(e);if(t<=H){const d=await fetch(e);return w(d.body)}const n=await fetch(e,{headers:{Range:"bytes=0-0","Accept-Encoding":"none"}}),[a,i]=n.body.tee(),s=a.getReader(),{value:o}=await s.read(),{done:f}=await s.read();if(s.releaseLock(),a.cancel(),!((o==null?void 0:o.length)===1&&f))return w(i);i.cancel();const l=await J(e,t);return W(l).pipeThrough(b(r)).pipeThrough($()).pipeThrough(j(l))}function W(e){let r;return new ReadableStream({async start(){r=await Y(e)},async pull(t){const n=await C(r);if(!n){t.close();return}t.enqueue(n)}})}async function Y(e){const r=z;let t=new Uint8Array,n=e.length;do{n=Math.max(0,n-r);const a=Math.min(n+r-1,e.length-1),i=await c(await e.streamBytes(n,a));t=U(i,t);const s=new DataView(i.buffer);for(let o=s.byteLength-4;o>=0;o--){if(s.getUint32(o,!0)!==g)continue;const u=o+12+4;if(t.byteLength<u+4)throw new Error("Central directory not found");const l=s.getUint32(u,!0);if(l<n){const d=await c(await e.streamBytes(l,n-1));t=U(d,t)}else l>n&&(t=t.slice(l-n));return new Blob([t]).stream()}}while(n>=0);throw new Error("Central directory not found")}function $(){let e=0,r=[];return new TransformStream({transform(t,n){t.firstByteAt>e+V&&(n.enqueue(r),r=[]),e=t.lastByteAt,r.push(t)},flush(t){t.enqueue(r)}})}function j(e){let r=!1,t=0,n;const a=[],i=new WritableStream({write(o,f){o.length&&(++t,K(e,o).then(u=>{a.push([o,u])}).catch(u=>{f.error(u)}).finally(()=>{--t}))},abort(){r=!0,n.close()},async close(){r=!0}});return{readable:new ReadableStream({start(o){n=o},async pull(o){for(;;){if(r&&!a.length&&t===0){o.close();return}if(!a.length){await new Promise(p=>setTimeout(p,50));continue}const[l,d]=a[0],m=await L(d);if(!m){a.shift();continue}if(l.find(p=>p.path===m.path)){o.enqueue(m);break}}}}),writable:i}}async function K(e,r){const t=await Z.acquire();try{const n=r[r.length-1];return await e.streamBytes(r[0].firstByteAt,n.lastByteAt)}finally{t()}}async function q(e){return await fetch(e,{method:"HEAD"}).then(r=>r.headers.get("Content-Length")).then(r=>{if(!r)throw new Error("Content-Length header is missing");const t=parseInt(r,10);if(isNaN(t)||t<0)throw new Error("Content-Length header is invalid");return t})}async function J(e,r){return r===void 0&&(r=await q(e)),{length:r,streamBytes:async(t,n)=>await fetch(e,{headers:{Range:`bytes=${t}-${n-1}`,"Accept-Encoding":"none"}}).then(a=>a.body)}}function Q(e){return T(e).pipeThrough(X())}function X(){const e=new Map;let r=0;return new TransformStream({async transform(t,n){const a=new Uint8Array(await t.arrayBuffer());let i=await c(new Blob([a]).stream().pipeThrough(new CompressionStream("gzip")));const s=new DataView(i.buffer).getUint32(i.byteLength-8,!0);i=i.slice(10,i.byteLength-8);const o=new TextEncoder().encode(t.name),f={signature:h,version:2,generalPurpose:0,compressionMethod:t.type==="directory"||i.byteLength===0?M:R,lastModifiedTime:0,lastModifiedDate:0,crc:s,compressedSize:i.byteLength,uncompressedSize:a.byteLength,path:o,extra:new Uint8Array(0)};e.set(r,f);const u=ee(f);n.enqueue(u),r+=u.byteLength,n.enqueue(i),r+=i.byteLength},flush(t){const n=r;let a=0;for(const[o,f]of e.entries()){const u={...f,signature:y,fileComment:new Uint8Array(0),diskNumber:0,internalAttributes:0,externalAttributes:0},l=te(u,o);t.enqueue(l),a+=l.byteLength}const i={signature:g,numberOfDisks:0,centralDirectoryOffset:n,centralDirectorySize:a,centralDirectoryStartDisk:0,numberCentralDirectoryRecordsOnThisDisk:e.size,numberCentralDirectoryRecords:e.size,comment:new Uint8Array(0)},s=ne(i);t.enqueue(s),e.clear()}})}function ee(e){const r=new ArrayBuffer(30+e.path.byteLength+e.extra.byteLength),t=new DataView(r);t.setUint32(0,e.signature,!0),t.setUint16(4,e.version,!0),t.setUint16(6,e.generalPurpose,!0),t.setUint16(8,e.compressionMethod,!0),t.setUint16(10,e.lastModifiedDate,!0),t.setUint16(12,e.lastModifiedTime,!0),t.setUint32(14,e.crc,!0),t.setUint32(18,e.compressedSize,!0),t.setUint32(22,e.uncompressedSize,!0),t.setUint16(26,e.path.byteLength,!0),t.setUint16(28,e.extra.byteLength,!0);const n=new Uint8Array(r);return n.set(e.path,30),n.set(e.extra,30+e.path.byteLength),n}function te(e,r){const t=new ArrayBuffer(46+e.path.byteLength+e.extra.byteLength),n=new DataView(t);n.setUint32(0,e.signature,!0),n.setUint16(4,e.versionCreated,!0),n.setUint16(6,e.versionNeeded,!0),n.setUint16(8,e.generalPurpose,!0),n.setUint16(10,e.compressionMethod,!0),n.setUint16(12,e.lastModifiedDate,!0),n.setUint16(14,e.lastModifiedTime,!0),n.setUint32(16,e.crc,!0),n.setUint32(20,e.compressedSize,!0),n.setUint32(24,e.uncompressedSize,!0),n.setUint16(28,e.path.byteLength,!0),n.setUint16(30,e.extra.byteLength,!0),n.setUint16(32,e.fileComment.byteLength,!0),n.setUint16(34,e.diskNumber,!0),n.setUint16(36,e.internalAttributes,!0),n.setUint32(38,e.externalAttributes,!0),n.setUint32(42,r,!0);const a=new Uint8Array(t);return a.set(e.path,46),a.set(e.extra,46+e.path.byteLength),a}function ne(e){const r=new ArrayBuffer(22+e.comment.byteLength),t=new DataView(r);t.setUint32(0,e.signature,!0),t.setUint16(4,e.numberOfDisks,!0),t.setUint16(6,e.centralDirectoryStartDisk,!0),t.setUint16(8,e.numberCentralDirectoryRecordsOnThisDisk,!0),t.setUint16(10,e.numberCentralDirectoryRecords,!0),t.setUint32(12,e.centralDirectorySize,!0),t.setUint32(16,e.centralDirectoryOffset,!0),t.setUint16(20,e.comment.byteLength,!0);const n=new Uint8Array(r);return n.set(e.comment,22),n}exports.StreamedFile=D;exports.collectBytes=c;exports.collectFile=_;exports.decodeRemoteZip=G;exports.decodeZip=w;exports.encodeZip=Q;exports.iteratorToStream=T; | ||
| //# sourceMappingURL=index.cjs.map |
+66
-55
| import "@php-wasm/node-polyfills"; | ||
| import { Semaphore as B } from "@php-wasm/util"; | ||
| import { Semaphore as _ } from "@php-wasm/util"; | ||
| function U(...e) { | ||
@@ -64,6 +64,6 @@ const r = new Uint8Array( | ||
| } | ||
| async function re(e, r) { | ||
| async function ae(e, r) { | ||
| return new File([await c(r)], e); | ||
| } | ||
| function _(e) { | ||
| function q(e) { | ||
| if (e instanceof ReadableStream) | ||
@@ -83,3 +83,14 @@ return e; | ||
| } | ||
| class ae extends File { | ||
| class E extends File { | ||
| static fromArrayBuffer(r, t, n) { | ||
| return new E( | ||
| new ReadableStream({ | ||
| start(a) { | ||
| a.enqueue(new Uint8Array(r)), a.close(); | ||
| } | ||
| }), | ||
| t, | ||
| n | ||
| ); | ||
| } | ||
| /** | ||
@@ -142,3 +153,3 @@ * Creates a new StreamedFile instance. | ||
| ReadableStream.prototype[Symbol.asyncIterator]); | ||
| const F = 32, h = 67324752, w = 33639248, g = 101010256, N = 0, E = 8; | ||
| const N = 32, h = 67324752, w = 33639248, g = 101010256, x = 0, L = 8; | ||
| function b(e) { | ||
@@ -151,3 +162,3 @@ return new TransformStream({ | ||
| } | ||
| function q(e) { | ||
| function F(e) { | ||
| let r = !1; | ||
@@ -160,3 +171,3 @@ return new TransformStream({ | ||
| } | ||
| function x(e) { | ||
| function k(e) { | ||
| return new TransformStream({ | ||
@@ -172,3 +183,3 @@ async transform(r, t) { | ||
| function p(e, r) { | ||
| return M(e, r).pipeThrough( | ||
| return v(e, r).pipeThrough( | ||
| new TransformStream({ | ||
@@ -188,7 +199,7 @@ async transform(t, n) { | ||
| } | ||
| const k = () => !0; | ||
| function M(e, r = k) { | ||
| const M = () => !0; | ||
| function v(e, r = M) { | ||
| return new ReadableStream({ | ||
| async pull(n) { | ||
| const a = await v(e); | ||
| const a = await O(e); | ||
| if (!a) { | ||
@@ -206,7 +217,7 @@ n.close(); | ||
| } | ||
| async function v(e) { | ||
| async function O(e) { | ||
| const t = new DataView((await c(e, 4)).buffer).getUint32(0, !0); | ||
| return t === h ? await L(e, !0) : t === w ? await T(e, !0) : t === g ? await O(e, !0) : null; | ||
| return t === h ? await R(e, !0) : t === w ? await T(e, !0) : t === g ? await P(e, !0) : null; | ||
| } | ||
| async function L(e, r = !1) { | ||
| async function R(e, r = !1) { | ||
| if (!r && new DataView((await c(e, 4)).buffer).getUint32(0, !0) !== h) | ||
@@ -225,9 +236,9 @@ return null; | ||
| }; | ||
| i.path = await c(e, n), i.isDirectory = R(i.path), i.extra = await c(e, a); | ||
| i.path = await c(e, n), i.isDirectory = C(i.path), i.extra = await c(e, a); | ||
| let s = A(e, i.compressedSize); | ||
| if (i.compressionMethod === E) { | ||
| if (i.compressionMethod === L) { | ||
| const o = new Uint8Array(10); | ||
| o.set([31, 139, 8]); | ||
| const f = new Uint8Array(8), u = new DataView(f.buffer); | ||
| u.setUint32(0, i.crc, !0), u.setUint32(4, i.uncompressedSize % 2 ** 32, !0), s = s.pipeThrough(q(o)).pipeThrough(x(f)).pipeThrough(new DecompressionStream("gzip")); | ||
| u.setUint32(0, i.crc, !0), u.setUint32(4, i.uncompressedSize % 2 ** 32, !0), s = s.pipeThrough(F(o)).pipeThrough(k(f)).pipeThrough(new DecompressionStream("gzip")); | ||
| } | ||
@@ -255,3 +266,3 @@ return i.bytes = await s.pipeThrough(S(i.uncompressedSize)).getReader().read().then(({ value: o }) => o), i; | ||
| }; | ||
| return s.lastByteAt = s.firstByteAt + F + n + i + a + s.compressedSize - 1, s.path = await c(e, n), s.isDirectory = R(s.path), s.extra = await c(e, a), s.fileComment = await c( | ||
| return s.lastByteAt = s.firstByteAt + N + n + i + a + s.compressedSize - 1, s.path = await c(e, n), s.isDirectory = C(s.path), s.extra = await c(e, a), s.fileComment = await c( | ||
| e, | ||
@@ -261,6 +272,6 @@ i | ||
| } | ||
| function R(e) { | ||
| function C(e) { | ||
| return e[e.byteLength - 1] == 47; | ||
| } | ||
| async function O(e, r = !1) { | ||
| async function P(e, r = !1) { | ||
| if (!r && new DataView((await c(e, 4)).buffer).getUint32(0, !0) !== g) | ||
@@ -279,3 +290,3 @@ return null; | ||
| } | ||
| const P = 110 * 1024, I = 10 * 1024, z = 1024 * 1024 * 1, V = new B({ concurrency: 10 }), D = () => !0; | ||
| const I = 110 * 1024, z = 10 * 1024, V = 1024 * 1024 * 1, H = new _({ concurrency: 10 }), D = () => !0; | ||
| async function ie(e, r = D) { | ||
@@ -286,4 +297,4 @@ if (r === D) { | ||
| } | ||
| const t = await C(e); | ||
| if (t <= z) { | ||
| const t = await B(e); | ||
| if (t <= V) { | ||
| const d = await fetch(e); | ||
@@ -304,12 +315,12 @@ return p(d.body); | ||
| i.cancel(); | ||
| const l = await $(e, t); | ||
| return H(l).pipeThrough(b(r)).pipeThrough(G()).pipeThrough( | ||
| W(l) | ||
| const l = await K(e, t); | ||
| return Z(l).pipeThrough(b(r)).pipeThrough(W()).pipeThrough( | ||
| Y(l) | ||
| ); | ||
| } | ||
| function H(e) { | ||
| function Z(e) { | ||
| let r; | ||
| return new ReadableStream({ | ||
| async start() { | ||
| r = await Z(e); | ||
| r = await G(e); | ||
| }, | ||
@@ -328,4 +339,4 @@ async pull(t) { | ||
| } | ||
| async function Z(e) { | ||
| const r = P; | ||
| async function G(e) { | ||
| const r = I; | ||
| let t = new Uint8Array(), n = e.length; | ||
@@ -365,7 +376,7 @@ do { | ||
| } | ||
| function G() { | ||
| function W() { | ||
| let e = 0, r = []; | ||
| return new TransformStream({ | ||
| transform(t, n) { | ||
| t.firstByteAt > e + I && (n.enqueue(r), r = []), e = t.lastByteAt, r.push(t); | ||
| t.firstByteAt > e + z && (n.enqueue(r), r = []), e = t.lastByteAt, r.push(t); | ||
| }, | ||
@@ -377,7 +388,7 @@ flush(t) { | ||
| } | ||
| function W(e) { | ||
| function Y(e) { | ||
| let r = !1, t = 0, n; | ||
| const a = [], i = new WritableStream({ | ||
| write(o, f) { | ||
| o.length && (++t, Y(e, o).then((u) => { | ||
| o.length && (++t, $(e, o).then((u) => { | ||
| a.push([o, u]); | ||
@@ -412,3 +423,3 @@ }).catch((u) => { | ||
| } | ||
| const [l, d] = a[0], y = await L(d); | ||
| const [l, d] = a[0], y = await R(d); | ||
| if (!y) { | ||
@@ -430,4 +441,4 @@ a.shift(); | ||
| } | ||
| async function Y(e, r) { | ||
| const t = await V.acquire(); | ||
| async function $(e, r) { | ||
| const t = await H.acquire(); | ||
| try { | ||
@@ -443,3 +454,3 @@ const n = r[r.length - 1]; | ||
| } | ||
| async function C(e) { | ||
| async function B(e) { | ||
| return await fetch(e, { method: "HEAD" }).then((r) => r.headers.get("Content-Length")).then((r) => { | ||
@@ -454,4 +465,4 @@ if (!r) | ||
| } | ||
| async function $(e, r) { | ||
| return r === void 0 && (r = await C(e)), { | ||
| async function K(e, r) { | ||
| return r === void 0 && (r = await B(e)), { | ||
| length: r, | ||
@@ -468,5 +479,5 @@ streamBytes: async (t, n) => await fetch(e, { | ||
| function se(e) { | ||
| return _(e).pipeThrough(K()); | ||
| return q(e).pipeThrough(j()); | ||
| } | ||
| function K() { | ||
| function j() { | ||
| const e = /* @__PURE__ */ new Map(); | ||
@@ -489,3 +500,3 @@ let r = 0; | ||
| generalPurpose: 0, | ||
| compressionMethod: t.type === "directory" || i.byteLength === 0 ? N : E, | ||
| compressionMethod: t.type === "directory" || i.byteLength === 0 ? x : L, | ||
| lastModifiedTime: 0, | ||
@@ -500,3 +511,3 @@ lastModifiedDate: 0, | ||
| e.set(r, f); | ||
| const u = j(f); | ||
| const u = J(f); | ||
| n.enqueue(u), r += u.byteLength, n.enqueue(i), r += i.byteLength; | ||
@@ -515,6 +526,6 @@ }, | ||
| fileComment: new Uint8Array(0), | ||
| diskNumber: 1, | ||
| diskNumber: 0, | ||
| internalAttributes: 0, | ||
| externalAttributes: 0 | ||
| }, l = J( | ||
| }, l = Q( | ||
| u, | ||
@@ -527,10 +538,10 @@ o | ||
| signature: g, | ||
| numberOfDisks: 1, | ||
| numberOfDisks: 0, | ||
| centralDirectoryOffset: n, | ||
| centralDirectorySize: a, | ||
| centralDirectoryStartDisk: 1, | ||
| centralDirectoryStartDisk: 0, | ||
| numberCentralDirectoryRecordsOnThisDisk: e.size, | ||
| numberCentralDirectoryRecords: e.size, | ||
| comment: new Uint8Array(0) | ||
| }, s = Q(i); | ||
| }, s = X(i); | ||
| t.enqueue(s), e.clear(); | ||
@@ -540,3 +551,3 @@ } | ||
| } | ||
| function j(e) { | ||
| function J(e) { | ||
| const r = new ArrayBuffer( | ||
@@ -549,3 +560,3 @@ 30 + e.path.byteLength + e.extra.byteLength | ||
| } | ||
| function J(e, r) { | ||
| function Q(e, r) { | ||
| const t = new ArrayBuffer( | ||
@@ -558,3 +569,3 @@ 46 + e.path.byteLength + e.extra.byteLength | ||
| } | ||
| function Q(e) { | ||
| function X(e) { | ||
| const r = new ArrayBuffer(22 + e.comment.byteLength), t = new DataView(r); | ||
@@ -566,10 +577,10 @@ t.setUint32(0, e.signature, !0), t.setUint16(4, e.numberOfDisks, !0), t.setUint16(6, e.centralDirectoryStartDisk, !0), t.setUint16(8, e.numberCentralDirectoryRecordsOnThisDisk, !0), t.setUint16(10, e.numberCentralDirectoryRecords, !0), t.setUint32(12, e.centralDirectorySize, !0), t.setUint32(16, e.centralDirectoryOffset, !0), t.setUint16(20, e.comment.byteLength, !0); | ||
| export { | ||
| ae as StreamedFile, | ||
| E as StreamedFile, | ||
| c as collectBytes, | ||
| re as collectFile, | ||
| ae as collectFile, | ||
| ie as decodeRemoteZip, | ||
| p as decodeZip, | ||
| se as encodeZip, | ||
| _ as iteratorToStream | ||
| q as iteratorToStream | ||
| }; | ||
| //# sourceMappingURL=index.js.map |
+6
-6
| { | ||
| "name": "@php-wasm/stream-compression", | ||
| "version": "3.0.22", | ||
| "version": "3.0.30", | ||
| "description": "Stream-based compression bindings.", | ||
@@ -32,3 +32,3 @@ "repository": { | ||
| "type": "module", | ||
| "gitHead": "a624d1a97dc639e152d335e6a801b2fad7f6b594", | ||
| "gitHead": "13a2c22a01669fcfecf6e72a7d131282cec9b251", | ||
| "packageManager": "npm@10.9.2", | ||
@@ -40,4 +40,4 @@ "overrides": { | ||
| "typescript": "5.4.5", | ||
| "@playwright/test": "1.47.1", | ||
| "ws": "^8.18.0", | ||
| "@playwright/test": "1.55.1", | ||
| "ws": "8.18.3", | ||
| "tmp": "0.2.5", | ||
@@ -47,4 +47,4 @@ "form-data": "^4.0.4" | ||
| "dependencies": { | ||
| "@php-wasm/node-polyfills": "3.0.22", | ||
| "@php-wasm/util": "3.0.22" | ||
| "@php-wasm/node-polyfills": "3.0.30", | ||
| "@php-wasm/util": "3.0.30" | ||
| }, | ||
@@ -51,0 +51,0 @@ "optionalDependencies": { |
@@ -8,2 +8,6 @@ /** | ||
| private readableStream; | ||
| static fromArrayBuffer(arrayBuffer: Uint8Array, name: string, options?: { | ||
| type?: string; | ||
| filesize?: number; | ||
| }): StreamedFile; | ||
| /** | ||
@@ -43,3 +47,3 @@ * Creates a new StreamedFile instance. | ||
| */ | ||
| arrayBuffer(): Promise<Uint8Array>; | ||
| arrayBuffer(): Promise<ArrayBuffer>; | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
192715
0.91%931
1.64%+ Added
- Removed
- Removed
Updated