@karmaniverous/stan-core 0.5.1 → 0.6.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/README.md +29 -21
- package/dist/mjs/index-CERcUEt-.js +1 -0
- package/dist/mjs/index-DEnUXENF.js +1 -0
- package/dist/mjs/index-WrHikElU.js +1 -0
- package/dist/mjs/index.js +1 -1
- package/dist/mjs/typescript-CwUyYoqG.js +6 -0
- package/dist/stan.system.md +404 -437
- package/dist/types/index.d.ts +722 -74
- package/package.json +30 -25
- package/dist/cjs/classifier-ClvtQeTy.js +0 -1
- package/dist/cjs/index-B7xvXIws.js +0 -1
- package/dist/cjs/index.js +0 -1
- package/dist/mjs/index-CQYvnMvw.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t,{EventEmitter as e}from"events";import i from"fs";import{EventEmitter as s}from"node:events";import r from"node:stream";import{StringDecoder as n}from"node:string_decoder";import h,{posix as o,basename as a,win32 as l,join as d}from"node:path";import c from"node:fs";import u,{parse as m,dirname as f}from"path";import p from"assert";import{Buffer as y}from"buffer";import*as b from"zlib";import w from"zlib";import g from"node:assert";import{randomBytes as E}from"node:crypto";import R from"node:fs/promises";const _="object"==typeof process&&process?process:{stdout:null,stderr:null},S=t=>!!t&&"object"==typeof t&&(t instanceof ot||t instanceof r||v(t)||O(t)),v=t=>!!t&&"object"==typeof t&&t instanceof s&&"function"==typeof t.pipe&&t.pipe!==r.Writable.prototype.pipe,O=t=>!!t&&"object"==typeof t&&t instanceof s&&"function"==typeof t.write&&"function"==typeof t.end,T=Symbol("EOF"),k=Symbol("maybeEmitEnd"),L=Symbol("emittedEnd"),D=Symbol("emittingEnd"),A=Symbol("emittedError"),x=Symbol("closed"),N=Symbol("read"),I=Symbol("flush"),F=Symbol("flushChunk"),B=Symbol("encoding"),C=Symbol("decoder"),M=Symbol("flowing"),P=Symbol("paused"),z=Symbol("resume"),U=Symbol("buffer"),j=Symbol("pipes"),Z=Symbol("bufferLength"),H=Symbol("bufferPush"),G=Symbol("bufferShift"),W=Symbol("objectMode"),Y=Symbol("destroyed"),$=Symbol("error"),V=Symbol("emitData"),q=Symbol("emitEnd"),K=Symbol("emitEnd2"),X=Symbol("async"),Q=Symbol("abort"),J=Symbol("aborted"),tt=Symbol("signal"),et=Symbol("dataListeners"),it=Symbol("discarded"),st=t=>Promise.resolve().then(t),rt=t=>t();class nt{src;dest;opts;ondrain;constructor(t,e,i){this.src=t,this.dest=e,this.opts=i,this.ondrain=()=>t[z](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(t){}end(){this.unpipe(),this.opts.end&&this.dest.end()}}class ht extends nt{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(t,e,i){super(t,e,i),this.proxyErrors=t=>e.emit("error",t),t.on("error",this.proxyErrors)}}class ot extends s{[M]=!1;[P]=!1;[j]=[];[U]=[];[W];[B];[X];[C];[T]=!1;[L]=!1;[D]=!1;[x]=!1;[A]=null;[Z]=0;[Y]=!1;[tt];[J]=!1;[et]=0;[it]=!1;writable=!0;readable=!0;constructor(...t){const e=t[0]||{};if(super(),e.objectMode&&"string"==typeof e.encoding)throw new TypeError("Encoding and objectMode may not be used together");e.objectMode?(this[W]=!0,this[B]=null):(t=>!t.objectMode&&!!t.encoding&&"buffer"!==t.encoding)(e)?(this[B]=e.encoding,this[W]=!1):(this[W]=!1,this[B]=null),this[X]=!!e.async,this[C]=this[B]?new n(this[B]):null,e&&!0===e.debugExposeBuffer&&Object.defineProperty(this,"buffer",{get:()=>this[U]}),e&&!0===e.debugExposePipes&&Object.defineProperty(this,"pipes",{get:()=>this[j]});const{signal:i}=e;i&&(this[tt]=i,i.aborted?this[Q]():i.addEventListener("abort",()=>this[Q]()))}get bufferLength(){return this[Z]}get encoding(){return this[B]}set encoding(t){throw new Error("Encoding must be set at instantiation time")}setEncoding(t){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[W]}set objectMode(t){throw new Error("objectMode must be set at instantiation time")}get async(){return this[X]}set async(t){this[X]=this[X]||!!t}[Q](){this[J]=!0,this.emit("abort",this[tt]?.reason),this.destroy(this[tt]?.reason)}get aborted(){return this[J]}set aborted(t){}write(t,e,i){if(this[J])return!1;if(this[T])throw new Error("write after end");if(this[Y])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;"function"==typeof e&&(i=e,e="utf8"),e||(e="utf8");const s=this[X]?st:rt;if(!this[W]&&!Buffer.isBuffer(t))if(r=t,!Buffer.isBuffer(r)&&ArrayBuffer.isView(r))t=Buffer.from(t.buffer,t.byteOffset,t.byteLength);else if((t=>t instanceof ArrayBuffer||!!t&&"object"==typeof t&&t.constructor&&"ArrayBuffer"===t.constructor.name&&t.byteLength>=0)(t))t=Buffer.from(t);else if("string"!=typeof t)throw new Error("Non-contiguous data written to non-objectMode stream");var r;return this[W]?(this[M]&&0!==this[Z]&&this[I](!0),this[M]?this.emit("data",t):this[H](t),0!==this[Z]&&this.emit("readable"),i&&s(i),this[M]):t.length?("string"!=typeof t||e===this[B]&&!this[C]?.lastNeed||(t=Buffer.from(t,e)),Buffer.isBuffer(t)&&this[B]&&(t=this[C].write(t)),this[M]&&0!==this[Z]&&this[I](!0),this[M]?this.emit("data",t):this[H](t),0!==this[Z]&&this.emit("readable"),i&&s(i),this[M]):(0!==this[Z]&&this.emit("readable"),i&&s(i),this[M])}read(t){if(this[Y])return null;if(this[it]=!1,0===this[Z]||0===t||t&&t>this[Z])return this[k](),null;this[W]&&(t=null),this[U].length>1&&!this[W]&&(this[U]=[this[B]?this[U].join(""):Buffer.concat(this[U],this[Z])]);const e=this[N](t||null,this[U][0]);return this[k](),e}[N](t,e){if(this[W])this[G]();else{const i=e;t===i.length||null===t?this[G]():"string"==typeof i?(this[U][0]=i.slice(t),e=i.slice(0,t),this[Z]-=t):(this[U][0]=i.subarray(t),e=i.subarray(0,t),this[Z]-=t)}return this.emit("data",e),this[U].length||this[T]||this.emit("drain"),e}end(t,e,i){return"function"==typeof t&&(i=t,t=void 0),"function"==typeof e&&(i=e,e="utf8"),void 0!==t&&this.write(t,e),i&&this.once("end",i),this[T]=!0,this.writable=!1,!this[M]&&this[P]||this[k](),this}[z](){this[Y]||(this[et]||this[j].length||(this[it]=!0),this[P]=!1,this[M]=!0,this.emit("resume"),this[U].length?this[I]():this[T]?this[k]():this.emit("drain"))}resume(){return this[z]()}pause(){this[M]=!1,this[P]=!0,this[it]=!1}get destroyed(){return this[Y]}get flowing(){return this[M]}get paused(){return this[P]}[H](t){this[W]?this[Z]+=1:this[Z]+=t.length,this[U].push(t)}[G](){return this[W]?this[Z]-=1:this[Z]-=this[U][0].length,this[U].shift()}[I](t=!1){do{}while(this[F](this[G]())&&this[U].length);t||this[U].length||this[T]||this.emit("drain")}[F](t){return this.emit("data",t),this[M]}pipe(t,e){if(this[Y])return t;this[it]=!1;const i=this[L];return e=e||{},t===_.stdout||t===_.stderr?e.end=!1:e.end=!1!==e.end,e.proxyErrors=!!e.proxyErrors,i?e.end&&t.end():(this[j].push(e.proxyErrors?new ht(this,t,e):new nt(this,t,e)),this[X]?st(()=>this[z]()):this[z]()),t}unpipe(t){const e=this[j].find(e=>e.dest===t);e&&(1===this[j].length?(this[M]&&0===this[et]&&(this[M]=!1),this[j]=[]):this[j].splice(this[j].indexOf(e),1),e.unpipe())}addListener(t,e){return this.on(t,e)}on(t,e){const i=super.on(t,e);if("data"===t)this[it]=!1,this[et]++,this[j].length||this[M]||this[z]();else if("readable"===t&&0!==this[Z])super.emit("readable");else if((t=>"end"===t||"finish"===t||"prefinish"===t)(t)&&this[L])super.emit(t),this.removeAllListeners(t);else if("error"===t&&this[A]){const t=e;this[X]?st(()=>t.call(this,this[A])):t.call(this,this[A])}return i}removeListener(t,e){return this.off(t,e)}off(t,e){const i=super.off(t,e);return"data"===t&&(this[et]=this.listeners("data").length,0!==this[et]||this[it]||this[j].length||(this[M]=!1)),i}removeAllListeners(t){const e=super.removeAllListeners(t);return"data"!==t&&void 0!==t||(this[et]=0,this[it]||this[j].length||(this[M]=!1)),e}get emittedEnd(){return this[L]}[k](){this[D]||this[L]||this[Y]||0!==this[U].length||!this[T]||(this[D]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[x]&&this.emit("close"),this[D]=!1)}emit(t,...e){const i=e[0];if("error"!==t&&"close"!==t&&t!==Y&&this[Y])return!1;if("data"===t)return!(!this[W]&&!i)&&(this[X]?(st(()=>this[V](i)),!0):this[V](i));if("end"===t)return this[q]();if("close"===t){if(this[x]=!0,!this[L]&&!this[Y])return!1;const t=super.emit("close");return this.removeAllListeners("close"),t}if("error"===t){this[A]=i,super.emit($,i);const t=!(this[tt]&&!this.listeners("error").length)&&super.emit("error",i);return this[k](),t}if("resume"===t){const t=super.emit("resume");return this[k](),t}if("finish"===t||"prefinish"===t){const e=super.emit(t);return this.removeAllListeners(t),e}const s=super.emit(t,...e);return this[k](),s}[V](t){for(const e of this[j])!1===e.dest.write(t)&&this.pause();const e=!this[it]&&super.emit("data",t);return this[k](),e}[q](){return!this[L]&&(this[L]=!0,this.readable=!1,this[X]?(st(()=>this[K]()),!0):this[K]())}[K](){if(this[C]){const t=this[C].end();if(t){for(const e of this[j])e.dest.write(t);this[it]||super.emit("data",t)}}for(const t of this[j])t.end();const t=super.emit("end");return this.removeAllListeners("end"),t}async collect(){const t=Object.assign([],{dataLength:0});this[W]||(t.dataLength=0);const e=this.promise();return this.on("data",e=>{t.push(e),this[W]||(t.dataLength+=e.length)}),await e,t}async concat(){if(this[W])throw new Error("cannot concat in objectMode");const t=await this.collect();return this[B]?t.join(""):Buffer.concat(t,t.dataLength)}async promise(){return new Promise((t,e)=>{this.on(Y,()=>e(new Error("stream destroyed"))),this.on("error",t=>e(t)),this.on("end",()=>t())})}[Symbol.asyncIterator](){this[it]=!1;let t=!1;const e=async()=>(this.pause(),t=!0,{value:void 0,done:!0});return{next:()=>{if(t)return e();const i=this.read();if(null!==i)return Promise.resolve({done:!1,value:i});if(this[T])return e();let s,r;const n=t=>{this.off("data",h),this.off("end",o),this.off(Y,a),e(),r(t)},h=t=>{this.off("error",n),this.off("end",o),this.off(Y,a),this.pause(),s({value:t,done:!!this[T]})},o=()=>{this.off("error",n),this.off("data",h),this.off(Y,a),e(),s({done:!0,value:void 0})},a=()=>n(new Error("stream destroyed"));return new Promise((t,e)=>{r=e,s=t,this.once(Y,a),this.once("error",n),this.once("end",o),this.once("data",h)})},throw:e,return:e,[Symbol.asyncIterator](){return this}}}[Symbol.iterator](){this[it]=!1;let t=!1;const e=()=>(this.pause(),this.off($,e),this.off(Y,e),this.off("end",e),t=!0,{done:!0,value:void 0});return this.once("end",e),this.once($,e),this.once(Y,e),{next:()=>{if(t)return e();const i=this.read();return null===i?e():{done:!1,value:i}},throw:e,return:e,[Symbol.iterator](){return this}}}destroy(t){if(this[Y])return t?this.emit("error",t):this.emit(Y),this;this[Y]=!0,this[it]=!0,this[U].length=0,this[Z]=0;return"function"!=typeof this.close||this[x]||this.close(),t?this.emit("error",t):this.emit(Y),this}static get isStream(){return S}}const at=i.writev,lt=Symbol("_autoClose"),dt=Symbol("_close"),ct=Symbol("_ended"),ut=Symbol("_fd"),mt=Symbol("_finished"),ft=Symbol("_flags"),pt=Symbol("_flush"),yt=Symbol("_handleChunk"),bt=Symbol("_makeBuf"),wt=Symbol("_mode"),gt=Symbol("_needDrain"),Et=Symbol("_onerror"),Rt=Symbol("_onopen"),_t=Symbol("_onread"),St=Symbol("_onwrite"),vt=Symbol("_open"),Ot=Symbol("_path"),Tt=Symbol("_pos"),kt=Symbol("_queue"),Lt=Symbol("_read"),Dt=Symbol("_readSize"),At=Symbol("_reading"),xt=Symbol("_remain"),Nt=Symbol("_size"),It=Symbol("_write"),Ft=Symbol("_writing"),Bt=Symbol("_defaultFlag"),Ct=Symbol("_errored");class Mt extends ot{[Ct]=!1;[ut];[Ot];[Dt];[At]=!1;[Nt];[xt];[lt];constructor(t,e){if(super(e=e||{}),this.readable=!0,this.writable=!1,"string"!=typeof t)throw new TypeError("path must be a string");this[Ct]=!1,this[ut]="number"==typeof e.fd?e.fd:void 0,this[Ot]=t,this[Dt]=e.readSize||16777216,this[At]=!1,this[Nt]="number"==typeof e.size?e.size:1/0,this[xt]=this[Nt],this[lt]="boolean"!=typeof e.autoClose||e.autoClose,"number"==typeof this[ut]?this[Lt]():this[vt]()}get fd(){return this[ut]}get path(){return this[Ot]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[vt](){i.open(this[Ot],"r",(t,e)=>this[Rt](t,e))}[Rt](t,e){t?this[Et](t):(this[ut]=e,this.emit("open",e),this[Lt]())}[bt](){return Buffer.allocUnsafe(Math.min(this[Dt],this[xt]))}[Lt](){if(!this[At]){this[At]=!0;const t=this[bt]();if(0===t.length)return process.nextTick(()=>this[_t](null,0,t));i.read(this[ut],t,0,t.length,null,(t,e,i)=>this[_t](t,e,i))}}[_t](t,e,i){this[At]=!1,t?this[Et](t):this[yt](e,i)&&this[Lt]()}[dt](){if(this[lt]&&"number"==typeof this[ut]){const t=this[ut];this[ut]=void 0,i.close(t,t=>t?this.emit("error",t):this.emit("close"))}}[Et](t){this[At]=!0,this[dt](),this.emit("error",t)}[yt](t,e){let i=!1;return this[xt]-=t,t>0&&(i=super.write(t<e.length?e.subarray(0,t):e)),(0===t||this[xt]<=0)&&(i=!1,this[dt](),super.end()),i}emit(t,...e){switch(t){case"prefinish":case"finish":return!1;case"drain":return"number"==typeof this[ut]&&this[Lt](),!1;case"error":return!this[Ct]&&(this[Ct]=!0,super.emit(t,...e));default:return super.emit(t,...e)}}}class Pt extends Mt{[vt](){let t=!0;try{this[Rt](null,i.openSync(this[Ot],"r")),t=!1}finally{t&&this[dt]()}}[Lt](){let t=!0;try{if(!this[At]){for(this[At]=!0;;){const t=this[bt](),e=0===t.length?0:i.readSync(this[ut],t,0,t.length,null);if(!this[yt](e,t))break}this[At]=!1}t=!1}finally{t&&this[dt]()}}[dt](){if(this[lt]&&"number"==typeof this[ut]){const t=this[ut];this[ut]=void 0,i.closeSync(t),this.emit("close")}}}class zt extends t{readable=!1;writable=!0;[Ct]=!1;[Ft]=!1;[ct]=!1;[kt]=[];[gt]=!1;[Ot];[wt];[lt];[ut];[Bt];[ft];[mt]=!1;[Tt];constructor(t,e){super(e=e||{}),this[Ot]=t,this[ut]="number"==typeof e.fd?e.fd:void 0,this[wt]=void 0===e.mode?438:e.mode,this[Tt]="number"==typeof e.start?e.start:void 0,this[lt]="boolean"!=typeof e.autoClose||e.autoClose;const i=void 0!==this[Tt]?"r+":"w";this[Bt]=void 0===e.flags,this[ft]=void 0===e.flags?i:e.flags,void 0===this[ut]&&this[vt]()}emit(t,...e){if("error"===t){if(this[Ct])return!1;this[Ct]=!0}return super.emit(t,...e)}get fd(){return this[ut]}get path(){return this[Ot]}[Et](t){this[dt](),this[Ft]=!0,this.emit("error",t)}[vt](){i.open(this[Ot],this[ft],this[wt],(t,e)=>this[Rt](t,e))}[Rt](t,e){this[Bt]&&"r+"===this[ft]&&t&&"ENOENT"===t.code?(this[ft]="w",this[vt]()):t?this[Et](t):(this[ut]=e,this.emit("open",e),this[Ft]||this[pt]())}end(t,e){return t&&this.write(t,e),this[ct]=!0,this[Ft]||this[kt].length||"number"!=typeof this[ut]||this[St](null,0),this}write(t,e){return"string"==typeof t&&(t=Buffer.from(t,e)),this[ct]?(this.emit("error",new Error("write() after end()")),!1):void 0===this[ut]||this[Ft]||this[kt].length?(this[kt].push(t),this[gt]=!0,!1):(this[Ft]=!0,this[It](t),!0)}[It](t){i.write(this[ut],t,0,t.length,this[Tt],(t,e)=>this[St](t,e))}[St](t,e){t?this[Et](t):(void 0!==this[Tt]&&"number"==typeof e&&(this[Tt]+=e),this[kt].length?this[pt]():(this[Ft]=!1,this[ct]&&!this[mt]?(this[mt]=!0,this[dt](),this.emit("finish")):this[gt]&&(this[gt]=!1,this.emit("drain"))))}[pt](){if(0===this[kt].length)this[ct]&&this[St](null,0);else if(1===this[kt].length)this[It](this[kt].pop());else{const t=this[kt];this[kt]=[],at(this[ut],t,this[Tt],(t,e)=>this[St](t,e))}}[dt](){if(this[lt]&&"number"==typeof this[ut]){const t=this[ut];this[ut]=void 0,i.close(t,t=>t?this.emit("error",t):this.emit("close"))}}}class Ut extends zt{[vt](){let t;if(this[Bt]&&"r+"===this[ft])try{t=i.openSync(this[Ot],this[ft],this[wt])}catch(t){if("ENOENT"===t?.code)return this[ft]="w",this[vt]();throw t}else t=i.openSync(this[Ot],this[ft],this[wt]);this[Rt](null,t)}[dt](){if(this[lt]&&"number"==typeof this[ut]){const t=this[ut];this[ut]=void 0,i.closeSync(t),this.emit("close")}}[It](t){let e=!0;try{this[St](null,i.writeSync(this[ut],t,0,t.length,this[Tt])),e=!1}finally{if(e)try{this[dt]()}catch{}}}}const jt=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),Zt=t=>{const e=jt.get(t);return e||t},Ht=(t={})=>{if(!t)return{};const e={};for(const[i,s]of Object.entries(t)){e[Zt(i)]=s}return void 0===e.chmod&&!1===e.noChmod&&(e.chmod=!0),delete e.noChmod,e},Gt=(t,e,i,s,r)=>Object.assign((n=[],h,o)=>{Array.isArray(n)&&(h=n,n={}),"function"==typeof h&&(o=h,h=void 0),h=h?Array.from(h):[];const a=Ht(n);if(r?.(a,h),(l=a).sync&&l.file){if("function"==typeof o)throw new TypeError("callback not supported for sync tar functions");return t(a,h)}if((t=>!t.sync&&!!t.file)(a)){const t=e(a,h),i=o||void 0;return i?t.then(()=>i(),i):t}if((t=>!!t.sync&&!t.file)(a)){if("function"==typeof o)throw new TypeError("callback not supported for sync tar functions");return i(a,h)}if((t=>!t.sync&&!t.file)(a)){if("function"==typeof o)throw new TypeError("callback only supported with file option");return s(a,h)}throw new Error("impossible options??");var l},{syncFile:t,asyncFile:e,syncNoFile:i,asyncNoFile:s,validate:r}),Wt=w.constants||{ZLIB_VERNUM:4736},Yt=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,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,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,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_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,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,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},Wt)),$t=y.concat,Vt=Object.getOwnPropertyDescriptor(y,"concat"),qt=t=>t,Kt=!0===Vt?.writable||void 0!==Vt?.set?t=>{y.concat=t?qt:$t}:t=>{},Xt=Symbol("_superWrite");class Qt extends Error{code;errno;constructor(t,e){super("zlib: "+t.message,{cause:t}),this.code=t.code,this.errno=t.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+t.message,Error.captureStackTrace(this,e??this.constructor)}get name(){return"ZlibError"}}const Jt=Symbol("flushFlag");class te extends ot{#t=!1;#e=!1;#i;#s;#r;#n;#h;get sawError(){return this.#t}get handle(){return this.#n}get flushFlag(){return this.#i}constructor(t,e){if(!t||"object"!=typeof t)throw new TypeError("invalid options for ZlibBase constructor");if(super(t),this.#i=t.flush??0,this.#s=t.finishFlush??0,this.#r=t.fullFlushFlag??0,"function"!=typeof b[e])throw new TypeError("Compression method not supported: "+e);try{this.#n=new b[e](t)}catch(t){throw new Qt(t,this.constructor)}this.#h=t=>{this.#t||(this.#t=!0,this.close(),this.emit("error",t))},this.#n?.on("error",t=>this.#h(new Qt(t))),this.once("end",()=>this.close)}close(){this.#n&&(this.#n.close(),this.#n=void 0,this.emit("close"))}reset(){if(!this.#t)return p(this.#n,"zlib binding closed"),this.#n.reset?.()}flush(t){this.ended||("number"!=typeof t&&(t=this.#r),this.write(Object.assign(y.alloc(0),{[Jt]:t})))}end(t,e,i){return"function"==typeof t&&(i=t,e=void 0,t=void 0),"function"==typeof e&&(i=e,e=void 0),t&&(e?this.write(t,e):this.write(t)),this.flush(this.#s),this.#e=!0,super.end(i)}get ended(){return this.#e}[Xt](t){return super.write(t)}write(t,e,i){if("function"==typeof e&&(i=e,e="utf8"),"string"==typeof t&&(t=y.from(t,e)),this.#t)return;p(this.#n,"zlib binding closed");const s=this.#n._handle,r=s.close;s.close=()=>{};const n=this.#n.close;let h,o;this.#n.close=()=>{},Kt(!0);try{const e="number"==typeof t[Jt]?t[Jt]:this.#i;h=this.#n._processChunk(t,e),Kt(!1)}catch(t){Kt(!1),this.#h(new Qt(t,this.write))}finally{this.#n&&(this.#n._handle=s,s.close=r,this.#n.close=n,this.#n.removeAllListeners("error"))}if(this.#n&&this.#n.on("error",t=>this.#h(new Qt(t,this.write))),h)if(Array.isArray(h)&&h.length>0){const t=h[0];o=this[Xt](y.from(t));for(let t=1;t<h.length;t++)o=this[Xt](h[t])}else o=this[Xt](y.from(h));return i&&i(),o}}class ee extends te{#o;#a;constructor(t,e){(t=t||{}).flush=t.flush||Yt.Z_NO_FLUSH,t.finishFlush=t.finishFlush||Yt.Z_FINISH,t.fullFlushFlag=Yt.Z_FULL_FLUSH,super(t,e),this.#o=t.level,this.#a=t.strategy}params(t,e){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#o!==t||this.#a!==e){this.flush(Yt.Z_SYNC_FLUSH),p(this.handle,"zlib binding closed");const i=this.handle.flush;this.handle.flush=(t,e)=>{"function"==typeof t&&(e=t,t=this.flushFlag),this.flush(t),e?.()};try{this.handle.params(t,e)}finally{this.handle.flush=i}this.handle&&(this.#o=t,this.#a=e)}}}}class ie extends ee{#l;constructor(t){super(t,"Gzip"),this.#l=t&&!!t.portable}[Xt](t){return this.#l?(this.#l=!1,t[9]=255,super[Xt](t)):super[Xt](t)}}class se extends ee{constructor(t){super(t,"Unzip")}}class re extends te{constructor(t,e){(t=t||{}).flush=t.flush||Yt.BROTLI_OPERATION_PROCESS,t.finishFlush=t.finishFlush||Yt.BROTLI_OPERATION_FINISH,t.fullFlushFlag=Yt.BROTLI_OPERATION_FLUSH,super(t,e)}}class ne extends re{constructor(t){super(t,"BrotliCompress")}}class he extends re{constructor(t){super(t,"BrotliDecompress")}}class oe extends te{constructor(t,e){(t=t||{}).flush=t.flush||Yt.ZSTD_e_continue,t.finishFlush=t.finishFlush||Yt.ZSTD_e_end,t.fullFlushFlag=Yt.ZSTD_e_flush,super(t,e)}}class ae extends oe{constructor(t){super(t,"ZstdCompress")}}class le extends oe{constructor(t){super(t,"ZstdDecompress")}}const de=(t,e)=>{e[0]=128;for(var i=e.length;i>1;i--)e[i-1]=255&t,t=Math.floor(t/256)},ce=(t,e)=>{e[0]=255;var i=!1;t*=-1;for(var s=e.length;s>1;s--){var r=255&t;t=Math.floor(t/256),i?e[s-1]=fe(r):0===r?e[s-1]=0:(i=!0,e[s-1]=pe(r))}},ue=t=>{for(var e=t.length,i=0,s=!1,r=e-1;r>-1;r--){var n,h=Number(t[r]);s?n=fe(h):0===h?n=h:(s=!0,n=pe(h)),0!==n&&(i-=n*Math.pow(256,e-r-1))}return i},me=t=>{for(var e=t.length,i=0,s=e-1;s>-1;s--){var r=Number(t[s]);0!==r&&(i+=r*Math.pow(256,e-s-1))}return i},fe=t=>255&(255^t),pe=t=>1+(255^t)&255,ye=t=>be.has(t),be=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),we=new Map(Array.from(be).map(t=>[t[1],t[0]]));var ge=Object.freeze({__proto__:null,code:we,isCode:ye,isName:t=>we.has(t),name:be});class Ee{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#d="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(t,e=0,i,s){Buffer.isBuffer(t)?this.decode(t,e||0,i,s):t&&this.#c(t)}decode(t,e,i,s){if(e||(e=0),!(t&&t.length>=e+512))throw new Error("need 512 bytes for header");this.path=i?.path??_e(t,e,100),this.mode=i?.mode??s?.mode??Oe(t,e+100,8),this.uid=i?.uid??s?.uid??Oe(t,e+108,8),this.gid=i?.gid??s?.gid??Oe(t,e+116,8),this.size=i?.size??s?.size??Oe(t,e+124,12),this.mtime=i?.mtime??s?.mtime??Se(t,e+136,12),this.cksum=Oe(t,e+148,12),s&&this.#c(s,!0),i&&this.#c(i);const r=_e(t,e+156,1);if(ye(r)&&(this.#d=r||"0"),"0"===this.#d&&"/"===this.path.slice(-1)&&(this.#d="5"),"5"===this.#d&&(this.size=0),this.linkpath=_e(t,e+157,100),"ustar\x0000"===t.subarray(e+257,e+265).toString())if(this.uname=i?.uname??s?.uname??_e(t,e+265,32),this.gname=i?.gname??s?.gname??_e(t,e+297,32),this.devmaj=i?.devmaj??s?.devmaj??Oe(t,e+329,8)??0,this.devmin=i?.devmin??s?.devmin??Oe(t,e+337,8)??0,0!==t[e+475]){const i=_e(t,e+345,155);this.path=i+"/"+this.path}else{const r=_e(t,e+345,130);r&&(this.path=r+"/"+this.path),this.atime=i?.atime??s?.atime??Se(t,e+476,12),this.ctime=i?.ctime??s?.ctime??Se(t,e+488,12)}let n=256;for(let i=e;i<e+148;i++)n+=t[i];for(let i=e+156;i<e+512;i++)n+=t[i];this.cksumValid=n===this.cksum,void 0===this.cksum&&256===n&&(this.nullBlock=!0)}#c(t,e=!1){Object.assign(this,Object.fromEntries(Object.entries(t).filter(([t,i])=>!(null==i||"path"===t&&e||"linkpath"===t&&e||"global"===t))))}encode(t,e=0){if(t||(t=this.block=Buffer.alloc(512)),"Unsupported"===this.#d&&(this.#d="0"),!(t.length>=e+512))throw new Error("need 512 bytes for header");const i=this.ctime||this.atime?130:155,s=Re(this.path||"",i),r=s[0],n=s[1];this.needPax=!!s[2],this.needPax=Fe(t,e,100,r)||this.needPax,this.needPax=Le(t,e+100,8,this.mode)||this.needPax,this.needPax=Le(t,e+108,8,this.uid)||this.needPax,this.needPax=Le(t,e+116,8,this.gid)||this.needPax,this.needPax=Le(t,e+124,12,this.size)||this.needPax,this.needPax=Ne(t,e+136,12,this.mtime)||this.needPax,t[e+156]=this.#d.charCodeAt(0),this.needPax=Fe(t,e+157,100,this.linkpath)||this.needPax,t.write("ustar\x0000",e+257,8),this.needPax=Fe(t,e+265,32,this.uname)||this.needPax,this.needPax=Fe(t,e+297,32,this.gname)||this.needPax,this.needPax=Le(t,e+329,8,this.devmaj)||this.needPax,this.needPax=Le(t,e+337,8,this.devmin)||this.needPax,this.needPax=Fe(t,e+345,i,n)||this.needPax,0!==t[e+475]?this.needPax=Fe(t,e+345,155,n)||this.needPax:(this.needPax=Fe(t,e+345,130,n)||this.needPax,this.needPax=Ne(t,e+476,12,this.atime)||this.needPax,this.needPax=Ne(t,e+488,12,this.ctime)||this.needPax);let h=256;for(let i=e;i<e+148;i++)h+=t[i];for(let i=e+156;i<e+512;i++)h+=t[i];return this.cksum=h,Le(t,e+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return"Unsupported"===this.#d?this.#d:be.get(this.#d)}get typeKey(){return this.#d}set type(t){const e=String(we.get(t));if(ye(e)||"Unsupported"===e)this.#d=e;else{if(!ye(t))throw new TypeError("invalid entry type: "+t);this.#d=t}}}const Re=(t,e)=>{const i=100;let s,r=t,n="";const h=o.parse(t).root||".";if(Buffer.byteLength(r)<i)s=[r,n,!1];else{n=o.dirname(r),r=o.basename(r);do{Buffer.byteLength(r)<=i&&Buffer.byteLength(n)<=e?s=[r,n,!1]:Buffer.byteLength(r)>i&&Buffer.byteLength(n)<=e?s=[r.slice(0,99),n,!0]:(r=o.join(o.basename(n),r),n=o.dirname(n))}while(n!==h&&void 0===s);s||(s=[t.slice(0,99),"",!0])}return s},_e=(t,e,i)=>t.subarray(e,e+i).toString("utf8").replace(/\0.*/,""),Se=(t,e,i)=>ve(Oe(t,e,i)),ve=t=>void 0===t?void 0:new Date(1e3*t),Oe=(t,e,i)=>128&Number(t[e])?(t=>{const e=t[0],i=128===e?me(t.subarray(1,t.length)):255===e?ue(t):null;if(null===i)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(i))throw Error("parsed number outside of javascript safe integer range");return i})(t.subarray(e,e+i)):Te(t,e,i),Te=(t,e,i)=>{return s=parseInt(t.subarray(e,e+i).toString("utf8").replace(/\0.*$/,"").trim(),8),isNaN(s)?void 0:s;var s},ke={12:8589934591,8:2097151},Le=(t,e,i,s)=>void 0!==s&&(s>ke[i]||s<0?(((t,e)=>{if(!Number.isSafeInteger(t))throw Error("cannot encode number outside of javascript safe integer range");t<0?ce(t,e):de(t,e)})(s,t.subarray(e,e+i)),!0):(De(t,e,i,s),!1)),De=(t,e,i,s)=>t.write(Ae(s,i),e,i,"ascii"),Ae=(t,e)=>xe(Math.floor(t).toString(8),e),xe=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",Ne=(t,e,i,s)=>void 0!==s&&Le(t,e,i,s.getTime()/1e3),Ie=new Array(156).join("\0"),Fe=(t,e,i,s)=>void 0!==s&&(t.write(s+Ie,e,i,"utf8"),s.length!==Buffer.byteLength(s)||s.length>i);class Be{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(t,e=!1){this.atime=t.atime,this.charset=t.charset,this.comment=t.comment,this.ctime=t.ctime,this.dev=t.dev,this.gid=t.gid,this.global=e,this.gname=t.gname,this.ino=t.ino,this.linkpath=t.linkpath,this.mtime=t.mtime,this.nlink=t.nlink,this.path=t.path,this.size=t.size,this.uid=t.uid,this.uname=t.uname}encode(){const t=this.encodeBody();if(""===t)return Buffer.allocUnsafe(0);const e=Buffer.byteLength(t),i=512*Math.ceil(1+e/512),s=Buffer.allocUnsafe(i);for(let t=0;t<512;t++)s[t]=0;new Ee({path:("PaxHeader/"+a(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:e,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(s),s.write(t,512,e,"utf8");for(let t=e+512;t<s.length;t++)s[t]=0;return s}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(t){if(void 0===this[t])return"";const e=this[t],i=" "+("dev"===t||"ino"===t||"nlink"===t?"SCHILY.":"")+t+"="+(e instanceof Date?e.getTime()/1e3:e)+"\n",s=Buffer.byteLength(i);let r=Math.floor(Math.log(s)/Math.log(10))+1;s+r>=Math.pow(10,r)&&(r+=1);return r+s+i}static parse(t,e,i=!1){return new Be(Ce(Me(t),e),i)}}const Ce=(t,e)=>e?Object.assign({},e,t):t,Me=t=>t.replace(/\n$/,"").split("\n").reduce(Pe,Object.create(null)),Pe=(t,e)=>{const i=parseInt(e,10);if(i!==Buffer.byteLength(e)+1)return t;const s=(e=e.slice((i+" ").length)).split("="),r=s.shift();if(!r)return t;const n=r.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),h=s.join("=");return t[n]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(n)?new Date(1e3*Number(h)):/^[0-9]+$/.test(h)?+h:h,t},ze="win32"!==(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform)?t=>t:t=>t&&t.replace(/\\/g,"/");class Ue extends ot{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(t,e,i){switch(super({}),this.pause(),this.extended=e,this.globalExtended=i,this.header=t,this.remain=t.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=t.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!t.path)throw new Error("no path provided for tar.ReadEntry");this.path=ze(t.path),this.mode=t.mode,this.mode&&(this.mode=4095&this.mode),this.uid=t.uid,this.gid=t.gid,this.uname=t.uname,this.gname=t.gname,this.size=this.remain,this.mtime=t.mtime,this.atime=t.atime,this.ctime=t.ctime,this.linkpath=t.linkpath?ze(t.linkpath):void 0,this.uname=t.uname,this.gname=t.gname,e&&this.#c(e),i&&this.#c(i,!0)}write(t){const e=t.length;if(e>this.blockRemain)throw new Error("writing more to entry than is appropriate");const i=this.remain,s=this.blockRemain;return this.remain=Math.max(0,i-e),this.blockRemain=Math.max(0,s-e),!!this.ignore||(i>=e?super.write(t):super.write(t.subarray(0,i)))}#c(t,e=!1){t.path&&(t.path=ze(t.path)),t.linkpath&&(t.linkpath=ze(t.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(t).filter(([t,i])=>!(null==i||"path"===t&&e))))}}const je=(t,e,i,s={})=>{t.file&&(s.file=t.file),t.cwd&&(s.cwd=t.cwd),s.code=i instanceof Error&&i.code||e,s.tarCode=e,t.strict||!1===s.recoverable?i instanceof Error?t.emit("error",Object.assign(i,s)):t.emit("error",Object.assign(new Error(`${e}: ${i}`),s)):(i instanceof Error&&(s=Object.assign(i,s),i=i.message),t.emit("warn",e,i,s))},Ze=Buffer.from([31,139]),He=Buffer.from([40,181,47,253]),Ge=Math.max(Ze.length,He.length),We=Symbol("state"),Ye=Symbol("writeEntry"),$e=Symbol("readEntry"),Ve=Symbol("nextEntry"),qe=Symbol("processEntry"),Ke=Symbol("extendedHeader"),Xe=Symbol("globalExtendedHeader"),Qe=Symbol("meta"),Je=Symbol("emitMeta"),ti=Symbol("buffer"),ei=Symbol("queue"),ii=Symbol("ended"),si=Symbol("emittedEnd"),ri=Symbol("emit"),ni=Symbol("unzip"),hi=Symbol("consumeChunk"),oi=Symbol("consumeChunkSub"),ai=Symbol("consumeBody"),li=Symbol("consumeMeta"),di=Symbol("consumeHeader"),ci=Symbol("consuming"),ui=Symbol("bufferConcat"),mi=Symbol("maybeEnd"),fi=Symbol("writing"),pi=Symbol("aborted"),yi=Symbol("onDone"),bi=Symbol("sawValidEntry"),wi=Symbol("sawNullBlock"),gi=Symbol("sawEOF"),Ei=Symbol("closeStream"),Ri=()=>!0;class _i extends e{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[ei]=[];[ti];[$e];[Ye];[We]="begin";[Qe]="";[Ke];[Xe];[ii]=!1;[ni];[pi]=!1;[bi];[wi]=!1;[gi]=!1;[fi]=!1;[ci]=!1;[si]=!1;constructor(t={}){super(),this.file=t.file||"",this.on(yi,()=>{"begin"!==this[We]&&!1!==this[bi]||this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),t.ondone?this.on(yi,t.ondone):this.on(yi,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!t.strict,this.maxMetaEntrySize=t.maxMetaEntrySize||1048576,this.filter="function"==typeof t.filter?t.filter:Ri;const e=t.file&&(t.file.endsWith(".tar.br")||t.file.endsWith(".tbr"));this.brotli=t.gzip||t.zstd||void 0===t.brotli?!!e&&void 0:t.brotli;const i=t.file&&(t.file.endsWith(".tar.zst")||t.file.endsWith(".tzst"));this.zstd=t.gzip||t.brotli||void 0===t.zstd?!!i||void 0:t.zstd,this.on("end",()=>this[Ei]()),"function"==typeof t.onwarn&&this.on("warn",t.onwarn),"function"==typeof t.onReadEntry&&this.on("entry",t.onReadEntry)}warn(t,e,i={}){je(this,t,e,i)}[di](t,e){let i;void 0===this[bi]&&(this[bi]=!1);try{i=new Ee(t,e,this[Ke],this[Xe])}catch(t){return this.warn("TAR_ENTRY_INVALID",t)}if(i.nullBlock)this[wi]?(this[gi]=!0,"begin"===this[We]&&(this[We]="header"),this[ri]("eof")):(this[wi]=!0,this[ri]("nullBlock"));else if(this[wi]=!1,i.cksumValid)if(i.path){const t=i.type;if(/^(Symbolic)?Link$/.test(t)&&!i.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:i});else if(/^(Symbolic)?Link$/.test(t)||/^(Global)?ExtendedHeader$/.test(t)||!i.linkpath){const t=this[Ye]=new Ue(i,this[Ke],this[Xe]);if(!this[bi])if(t.remain){const e=()=>{t.invalid||(this[bi]=!0)};t.on("end",e)}else this[bi]=!0;t.meta?t.size>this.maxMetaEntrySize?(t.ignore=!0,this[ri]("ignoredEntry",t),this[We]="ignore",t.resume()):t.size>0&&(this[Qe]="",t.on("data",t=>this[Qe]+=t),this[We]="meta"):(this[Ke]=void 0,t.ignore=t.ignore||!this.filter(t.path,t),t.ignore?(this[ri]("ignoredEntry",t),this[We]=t.remain?"ignore":"header",t.resume()):(t.remain?this[We]="body":(this[We]="header",t.end()),this[$e]?this[ei].push(t):(this[ei].push(t),this[Ve]())))}else this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:i})}else this.warn("TAR_ENTRY_INVALID","path is required",{header:i});else this.warn("TAR_ENTRY_INVALID","checksum failure",{header:i})}[Ei](){queueMicrotask(()=>this.emit("close"))}[qe](t){let e=!0;if(t)if(Array.isArray(t)){const[e,...i]=t;this.emit(e,...i)}else this[$e]=t,this.emit("entry",t),t.emittedEnd||(t.on("end",()=>this[Ve]()),e=!1);else this[$e]=void 0,e=!1;return e}[Ve](){do{}while(this[qe](this[ei].shift()));if(!this[ei].length){const t=this[$e];!t||t.flowing||t.size===t.remain?this[fi]||this.emit("drain"):t.once("drain",()=>this.emit("drain"))}}[ai](t,e){const i=this[Ye];if(!i)throw new Error("attempt to consume body without entry??");const s=i.blockRemain??0,r=s>=t.length&&0===e?t:t.subarray(e,e+s);return i.write(r),i.blockRemain||(this[We]="header",this[Ye]=void 0,i.end()),r.length}[li](t,e){const i=this[Ye],s=this[ai](t,e);return!this[Ye]&&i&&this[Je](i),s}[ri](t,e,i){this[ei].length||this[$e]?this[ei].push([t,e,i]):this.emit(t,e,i)}[Je](t){switch(this[ri]("meta",this[Qe]),t.type){case"ExtendedHeader":case"OldExtendedHeader":this[Ke]=Be.parse(this[Qe],this[Ke],!1);break;case"GlobalExtendedHeader":this[Xe]=Be.parse(this[Qe],this[Xe],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{const t=this[Ke]??Object.create(null);this[Ke]=t,t.path=this[Qe].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{const t=this[Ke]||Object.create(null);this[Ke]=t,t.linkpath=this[Qe].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+t.type)}}abort(t){this[pi]=!0,this.emit("abort",t),this.warn("TAR_ABORT",t,{recoverable:!1})}write(t,e,i){if("function"==typeof e&&(i=e,e=void 0),"string"==typeof t&&(t=Buffer.from(t,"string"==typeof e?e:"utf8")),this[pi])return i?.(),!1;if((void 0===this[ni]||void 0===this.brotli&&!1===this[ni])&&t){if(this[ti]&&(t=Buffer.concat([this[ti],t]),this[ti]=void 0),t.length<Ge)return this[ti]=t,i?.(),!0;for(let e=0;void 0===this[ni]&&e<Ze.length;e++)t[e]!==Ze[e]&&(this[ni]=!1);let e=!1;if(!1===this[ni]&&!1!==this.zstd){e=!0;for(let i=0;i<He.length;i++)if(t[i]!==He[i]){e=!1;break}}const s=void 0===this.brotli&&!e;if(!1===this[ni]&&s)if(t.length<512){if(!this[ii])return this[ti]=t,i?.(),!0;this.brotli=!0}else try{new Ee(t.subarray(0,512)),this.brotli=!1}catch(t){this.brotli=!0}if(void 0===this[ni]||!1===this[ni]&&(this.brotli||e)){const s=this[ii];this[ii]=!1,this[ni]=void 0===this[ni]?new se({}):e?new le({}):new he({}),this[ni].on("data",t=>this[hi](t)),this[ni].on("error",t=>this.abort(t)),this[ni].on("end",()=>{this[ii]=!0,this[hi]()}),this[fi]=!0;const r=!!this[ni][s?"end":"write"](t);return this[fi]=!1,i?.(),r}}this[fi]=!0,this[ni]?this[ni].write(t):this[hi](t),this[fi]=!1;const s=!this[ei].length&&(!this[$e]||this[$e].flowing);return s||this[ei].length||this[$e]?.once("drain",()=>this.emit("drain")),i?.(),s}[ui](t){t&&!this[pi]&&(this[ti]=this[ti]?Buffer.concat([this[ti],t]):t)}[mi](){if(this[ii]&&!this[si]&&!this[pi]&&!this[ci]){this[si]=!0;const t=this[Ye];if(t&&t.blockRemain){const e=this[ti]?this[ti].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`,{entry:t}),this[ti]&&t.write(this[ti]),t.end()}this[ri](yi)}}[hi](t){if(this[ci]&&t)this[ui](t);else if(t||this[ti]){if(t){if(this[ci]=!0,this[ti]){this[ui](t);const e=this[ti];this[ti]=void 0,this[oi](e)}else this[oi](t);for(;this[ti]&&this[ti]?.length>=512&&!this[pi]&&!this[gi];){const t=this[ti];this[ti]=void 0,this[oi](t)}this[ci]=!1}}else this[mi]();this[ti]&&!this[ii]||this[mi]()}[oi](t){let e=0;const i=t.length;for(;e+512<=i&&!this[pi]&&!this[gi];)switch(this[We]){case"begin":case"header":this[di](t,e),e+=512;break;case"ignore":case"body":e+=this[ai](t,e);break;case"meta":e+=this[li](t,e);break;default:throw new Error("invalid state: "+this[We])}e<i&&(this[ti]?this[ti]=Buffer.concat([t.subarray(e),this[ti]]):this[ti]=t.subarray(e))}end(t,e,i){return"function"==typeof t&&(i=t,e=void 0,t=void 0),"function"==typeof e&&(i=e,e=void 0),"string"==typeof t&&(t=Buffer.from(t,e)),i&&this.once("finish",i),this[pi]||(this[ni]?(t&&this[ni].write(t),this[ni].end()):(this[ii]=!0,void 0!==this.brotli&&void 0!==this.zstd||(t=t||Buffer.alloc(0)),t&&this.write(t),this[mi]())),this}}const Si=t=>{let e=t.length-1,i=-1;for(;e>-1&&"/"===t.charAt(e);)i=e,e--;return-1===i?t:t.slice(0,i)},vi=(t,e)=>{const i=new Map(e.map(t=>[Si(t),!0])),s=t.filter,r=(t,e="")=>{const s=e||m(t).root||".";let n;if(t===s)n=!1;else{const e=i.get(t);n=void 0!==e?e:r(f(t),s)}return i.set(t,n),n};t.filter=s?(t,e)=>s(t,e)&&r(Si(t)):t=>r(Si(t))},Oi=Gt(t=>{const e=new _i(t),i=t.file;let s;try{s=c.openSync(i,"r");const r=c.fstatSync(s),n=t.maxReadSize||16777216;if(r.size<n){const t=Buffer.allocUnsafe(r.size),i=c.readSync(s,t,0,r.size,0);e.end(i===t.byteLength?t:t.subarray(0,i))}else{let t=0;const i=Buffer.allocUnsafe(n);for(;t<r.size;){const r=c.readSync(s,i,0,n,t);if(0===r)break;t+=r,e.write(i.subarray(0,r))}e.end()}}finally{if("number"==typeof s)try{c.closeSync(s)}catch(t){}}},(t,e)=>{const i=new _i(t),s=t.maxReadSize||16777216,r=t.file;return new Promise((t,e)=>{i.on("error",e),i.on("end",t),c.stat(r,(t,n)=>{if(t)e(t);else{const t=new Mt(r,{readSize:s,size:n.size});t.on("error",e),t.pipe(i)}})})},t=>new _i(t),t=>new _i(t),(t,e)=>{e?.length&&vi(t,e),t.noResume||(t=>{const e=t.onReadEntry;t.onReadEntry=e?t=>{e(t),t.resume()}:t=>t.resume()})(t)}),Ti=(t,e,i)=>(t&=4095,i&&(t=-19&t|384),e&&(256&t&&(t|=64),32&t&&(t|=8),4&t&&(t|=1)),t),{isAbsolute:ki,parse:Li}=l,Di=t=>{let e="",i=Li(t);for(;ki(t)||i.root;){const s="/"===t.charAt(0)&&"//?/"!==t.slice(0,4)?"/":i.root;t=t.slice(s.length),e+=s,i=Li(t)}return[e,t]},Ai=["|","<",">","?",":"],xi=Ai.map(t=>String.fromCharCode(61440+t.charCodeAt(0))),Ni=new Map(Ai.map((t,e)=>[t,xi[e]])),Ii=new Map(xi.map((t,e)=>[t,Ai[e]])),Fi=t=>Ai.reduce((t,e)=>t.split(e).join(Ni.get(e)),t),Bi=(t,e)=>e?(t=ze(t).replace(/^\.(\/|$)/,""),Si(e)+"/"+t):ze(t),Ci=Symbol("process"),Mi=Symbol("file"),Pi=Symbol("directory"),zi=Symbol("symlink"),Ui=Symbol("hardlink"),ji=Symbol("header"),Zi=Symbol("read"),Hi=Symbol("lstat"),Gi=Symbol("onlstat"),Wi=Symbol("onread"),Yi=Symbol("onreadlink"),$i=Symbol("openfile"),Vi=Symbol("onopenfile"),qi=Symbol("close"),Ki=Symbol("mode"),Xi=Symbol("awaitDrain"),Qi=Symbol("ondrain"),Ji=Symbol("prefix");class ts extends ot{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#u=!1;constructor(t,e={}){const i=Ht(e);super(),this.path=ze(t),this.portable=!!i.portable,this.maxReadSize=i.maxReadSize||16777216,this.linkCache=i.linkCache||new Map,this.statCache=i.statCache||new Map,this.preservePaths=!!i.preservePaths,this.cwd=ze(i.cwd||process.cwd()),this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.mtime=i.mtime,this.prefix=i.prefix?ze(i.prefix):void 0,this.onWriteEntry=i.onWriteEntry,"function"==typeof i.onwarn&&this.on("warn",i.onwarn);let s=!1;if(!this.preservePaths){const[t,e]=Di(this.path);t&&"string"==typeof e&&(this.path=e,s=t)}var r;this.win32=!!i.win32||"win32"===process.platform,this.win32&&(this.path=(r=this.path.replace(/\\/g,"/"),xi.reduce((t,e)=>t.split(e).join(Ii.get(e)),r)),t=t.replace(/\\/g,"/")),this.absolute=ze(i.absolute||u.resolve(this.cwd,t)),""===this.path&&(this.path="./"),s&&this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute path`,{entry:this,path:s+this.path});const n=this.statCache.get(this.absolute);n?this[Gi](n):this[Hi]()}warn(t,e,i={}){return je(this,t,e,i)}emit(t,...e){return"error"===t&&(this.#u=!0),super.emit(t,...e)}[Hi](){i.lstat(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Gi](e)})}[Gi](t){this.statCache.set(this.absolute,t),this.stat=t,t.isFile()||(t.size=0),this.type=ss(t),this.emit("stat",t),this[Ci]()}[Ci](){switch(this.type){case"File":return this[Mi]();case"Directory":return this[Pi]();case"SymbolicLink":return this[zi]();default:return this.end()}}[Ki](t){return Ti(t,"Directory"===this.type,this.portable)}[Ji](t){return Bi(t,this.prefix)}[ji](){if(!this.stat)throw new Error("cannot write header before stat");"Directory"===this.type&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new Ee({path:this[Ji](this.path),linkpath:"Link"===this.type&&void 0!==this.linkpath?this[Ji](this.linkpath):this.linkpath,mode:this[Ki](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:"Unsupported"===this.type?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new Be({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Ji](this.path),linkpath:"Link"===this.type&&void 0!==this.linkpath?this[Ji](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());const t=this.header?.block;if(!t)throw new Error("failed to encode header");super.write(t)}[Pi](){if(!this.stat)throw new Error("cannot create directory entry without stat");"/"!==this.path.slice(-1)&&(this.path+="/"),this.stat.size=0,this[ji](),this.end()}[zi](){i.readlink(this.absolute,(t,e)=>{if(t)return this.emit("error",t);this[Yi](e)})}[Yi](t){this.linkpath=ze(t),this[ji](),this.end()}[Ui](t){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=ze(u.relative(this.cwd,t)),this.stat.size=0,this[ji](),this.end()}[Mi](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){const t=`${this.stat.dev}:${this.stat.ino}`,e=this.linkCache.get(t);if(0===e?.indexOf(this.cwd))return this[Ui](e);this.linkCache.set(t,this.absolute)}if(this[ji](),0===this.stat.size)return this.end();this[$i]()}[$i](){i.open(this.absolute,"r",(t,e)=>{if(t)return this.emit("error",t);this[Vi](e)})}[Vi](t){if(this.fd=t,this.#u)return this[qi]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;const e=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(e),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Zi]()}[Zi](){const{fd:t,buf:e,offset:s,length:r,pos:n}=this;if(void 0===t||void 0===e)throw new Error("cannot read file without first opening");i.read(t,e,s,r,n,(t,e)=>{if(t)return this[qi](()=>this.emit("error",t));this[Wi](e)})}[qi](t=()=>{}){void 0!==this.fd&&i.close(this.fd,t)}[Wi](t){if(t<=0&&this.remain>0){const t=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[qi](()=>this.emit("error",t))}if(t>this.remain){const t=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[qi](()=>this.emit("error",t))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(t===this.remain)for(let e=t;e<this.length&&t<this.blockRemain;e++)this.buf[e+this.offset]=0,t++,this.remain++;const e=0===this.offset&&t===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+t);this.write(e)?this[Qi]():this[Xi](()=>this[Qi]())}[Xi](t){this.once("drain",t)}write(t,e,i){if("function"==typeof e&&(i=e,e=void 0),"string"==typeof t&&(t=Buffer.from(t,"string"==typeof e?e:"utf8")),this.blockRemain<t.length){const t=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",t)}return this.remain-=t.length,this.blockRemain-=t.length,this.pos+=t.length,this.offset+=t.length,super.write(t,null,i)}[Qi](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[qi](t=>t?this.emit("error",t):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Zi]()}}class es extends ts{sync=!0;[Hi](){this[Gi](i.lstatSync(this.absolute))}[zi](){this[Yi](i.readlinkSync(this.absolute))}[$i](){this[Vi](i.openSync(this.absolute,"r"))}[Zi](){let t=!0;try{const{fd:e,buf:s,offset:r,length:n,pos:h}=this;if(void 0===e||void 0===s)throw new Error("fd and buf must be set in READ method");const o=i.readSync(e,s,r,n,h);this[Wi](o),t=!1}finally{if(t)try{this[qi](()=>{})}catch(t){}}}[Xi](t){t()}[qi](t=()=>{}){void 0!==this.fd&&i.closeSync(this.fd),t()}}class is extends ot{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(t,e,i={}){return je(this,t,e,i)}constructor(t,e={}){const i=Ht(e);super(),this.preservePaths=!!i.preservePaths,this.portable=!!i.portable,this.strict=!!i.strict,this.noPax=!!i.noPax,this.noMtime=!!i.noMtime,this.onWriteEntry=i.onWriteEntry,this.readEntry=t;const{type:s}=t;if("Unsupported"===s)throw new Error("writing entry that should be ignored");this.type=s,"Directory"===this.type&&this.portable&&(this.noMtime=!0),this.prefix=i.prefix,this.path=ze(t.path),this.mode=void 0!==t.mode?this[Ki](t.mode):void 0,this.uid=this.portable?void 0:t.uid,this.gid=this.portable?void 0:t.gid,this.uname=this.portable?void 0:t.uname,this.gname=this.portable?void 0:t.gname,this.size=t.size,this.mtime=this.noMtime?void 0:i.mtime||t.mtime,this.atime=this.portable?void 0:t.atime,this.ctime=this.portable?void 0:t.ctime,this.linkpath=void 0!==t.linkpath?ze(t.linkpath):void 0,"function"==typeof i.onwarn&&this.on("warn",i.onwarn);let r=!1;if(!this.preservePaths){const[t,e]=Di(this.path);t&&"string"==typeof e&&(this.path=e,r=t)}this.remain=t.size,this.blockRemain=t.startBlockSize,this.onWriteEntry?.(this),this.header=new Ee({path:this[Ji](this.path),linkpath:"Link"===this.type&&void 0!==this.linkpath?this[Ji](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),r&&this.warn("TAR_ENTRY_INFO",`stripping ${r} from absolute path`,{entry:this,path:r+this.path}),this.header.encode()&&!this.noPax&&super.write(new Be({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Ji](this.path),linkpath:"Link"===this.type&&void 0!==this.linkpath?this[Ji](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());const n=this.header?.block;if(!n)throw new Error("failed to encode header");super.write(n),t.pipe(this)}[Ji](t){return Bi(t,this.prefix)}[Ki](t){return Ti(t,"Directory"===this.type,this.portable)}write(t,e,i){"function"==typeof e&&(i=e,e=void 0),"string"==typeof t&&(t=Buffer.from(t,"string"==typeof e?e:"utf8"));const s=t.length;if(s>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=s,super.write(t,i)}end(t,e,i){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),"function"==typeof t&&(i=t,e=void 0,t=void 0),"function"==typeof e&&(i=e,e=void 0),"string"==typeof t&&(t=Buffer.from(t,e??"utf8")),i&&this.once("finish",i),t?super.end(t,i):super.end(i),this}}const ss=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported";class rs{tail;head;length=0;static create(t=[]){return new rs(t)}constructor(t=[]){for(const e of t)this.push(e)}*[Symbol.iterator](){for(let t=this.head;t;t=t.next)yield t.value}removeNode(t){if(t.list!==this)throw new Error("removing node which does not belong to this list");const e=t.next,i=t.prev;return e&&(e.prev=i),i&&(i.next=e),t===this.head&&(this.head=e),t===this.tail&&(this.tail=i),this.length--,t.next=void 0,t.prev=void 0,t.list=void 0,e}unshiftNode(t){if(t===this.head)return;t.list&&t.list.removeNode(t);const e=this.head;t.list=this,t.next=e,e&&(e.prev=t),this.head=t,this.tail||(this.tail=t),this.length++}pushNode(t){if(t===this.tail)return;t.list&&t.list.removeNode(t);const e=this.tail;t.list=this,t.prev=e,e&&(e.next=t),this.tail=t,this.head||(this.head=t),this.length++}push(...t){for(let e=0,i=t.length;e<i;e++)hs(this,t[e]);return this.length}unshift(...t){for(var e=0,i=t.length;e<i;e++)os(this,t[e]);return this.length}pop(){if(!this.tail)return;const t=this.tail.value,e=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,e.list=void 0,this.length--,t}shift(){if(!this.head)return;const t=this.head.value,e=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,e.list=void 0,this.length--,t}forEach(t,e){e=e||this;for(let i=this.head,s=0;i;s++)t.call(e,i.value,s,this),i=i.next}forEachReverse(t,e){e=e||this;for(let i=this.tail,s=this.length-1;i;s--)t.call(e,i.value,s,this),i=i.prev}get(t){let e=0,i=this.head;for(;i&&e<t;e++)i=i.next;if(e===t&&i)return i.value}getReverse(t){let e=0,i=this.tail;for(;i&&e<t;e++)i=i.prev;if(e===t&&i)return i.value}map(t,e){e=e||this;const i=new rs;for(let s=this.head;s;)i.push(t.call(e,s.value,this)),s=s.next;return i}mapReverse(t,e){e=e||this;var i=new rs;for(let s=this.tail;s;)i.push(t.call(e,s.value,this)),s=s.prev;return i}reduce(t,e){let i,s=this.head;if(arguments.length>1)i=e;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");s=this.head.next,i=this.head.value}for(var r=0;s;r++)i=t(i,s.value,r),s=s.next;return i}reduceReverse(t,e){let i,s=this.tail;if(arguments.length>1)i=e;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");s=this.tail.prev,i=this.tail.value}for(let e=this.length-1;s;e--)i=t(i,s.value,e),s=s.prev;return i}toArray(){const t=new Array(this.length);for(let e=0,i=this.head;i;e++)t[e]=i.value,i=i.next;return t}toArrayReverse(){const t=new Array(this.length);for(let e=0,i=this.tail;i;e++)t[e]=i.value,i=i.prev;return t}slice(t=0,e=this.length){e<0&&(e+=this.length),t<0&&(t+=this.length);const i=new rs;if(e<t||e<0)return i;t<0&&(t=0),e>this.length&&(e=this.length);let s=this.head,r=0;for(r=0;s&&r<t;r++)s=s.next;for(;s&&r<e;r++,s=s.next)i.push(s.value);return i}sliceReverse(t=0,e=this.length){e<0&&(e+=this.length),t<0&&(t+=this.length);const i=new rs;if(e<t||e<0)return i;t<0&&(t=0),e>this.length&&(e=this.length);let s=this.length,r=this.tail;for(;r&&s>e;s--)r=r.prev;for(;r&&s>t;s--,r=r.prev)i.push(r.value);return i}splice(t,e=0,...i){t>this.length&&(t=this.length-1),t<0&&(t=this.length+t);let s=this.head;for(let e=0;s&&e<t;e++)s=s.next;const r=[];for(let t=0;s&&t<e;t++)r.push(s.value),s=this.removeNode(s);s?s!==this.tail&&(s=s.prev):s=this.tail;for(const t of i)s=ns(this,s,t);return r}reverse(){const t=this.head,e=this.tail;for(let e=t;e;e=e.prev){const t=e.prev;e.prev=e.next,e.next=t}return this.head=e,this.tail=t,this}}function ns(t,e,i){const s=e,r=e?e.next:t.head,n=new as(i,s,r,t);return void 0===n.next&&(t.tail=n),void 0===n.prev&&(t.head=n),t.length++,n}function hs(t,e){t.tail=new as(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function os(t,e){t.head=new as(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}class as{list;next;prev;value;constructor(t,e,i,s){this.list=s,this.value=t,e?(e.next=this,this.prev=e):this.prev=void 0,i?(i.prev=this,this.next=i):this.next=void 0}}class ls{path;absolute;entry;stat;readdir;pending=!1;ignore=!1;piped=!1;constructor(t,e){this.path=t||"./",this.absolute=e}}const ds=Buffer.alloc(1024),cs=Symbol("onStat"),us=Symbol("ended"),ms=Symbol("queue"),fs=Symbol("current"),ps=Symbol("process"),ys=Symbol("processing"),bs=Symbol("processJob"),ws=Symbol("jobs"),gs=Symbol("jobDone"),Es=Symbol("addFSEntry"),Rs=Symbol("addTarEntry"),_s=Symbol("stat"),Ss=Symbol("readdir"),vs=Symbol("onreaddir"),Os=Symbol("pipe"),Ts=Symbol("entry"),ks=Symbol("entryOpt"),Ls=Symbol("writeEntryClass"),Ds=Symbol("write"),As=Symbol("ondrain");class xs extends ot{sync=!1;opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Ls];onWriteEntry;[ms];[ws]=0;[ys]=!1;[us]=!1;constructor(t={}){if(super(),this.opt=t,this.file=t.file||"",this.cwd=t.cwd||process.cwd(),this.maxReadSize=t.maxReadSize,this.preservePaths=!!t.preservePaths,this.strict=!!t.strict,this.noPax=!!t.noPax,this.prefix=ze(t.prefix||""),this.linkCache=t.linkCache||new Map,this.statCache=t.statCache||new Map,this.readdirCache=t.readdirCache||new Map,this.onWriteEntry=t.onWriteEntry,this[Ls]=ts,"function"==typeof t.onwarn&&this.on("warn",t.onwarn),this.portable=!!t.portable,t.gzip||t.brotli||t.zstd){if((t.gzip?1:0)+(t.brotli?1:0)+(t.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(t.gzip&&("object"!=typeof t.gzip&&(t.gzip={}),this.portable&&(t.gzip.portable=!0),this.zip=new ie(t.gzip)),t.brotli&&("object"!=typeof t.brotli&&(t.brotli={}),this.zip=new ne(t.brotli)),t.zstd&&("object"!=typeof t.zstd&&(t.zstd={}),this.zip=new ae(t.zstd)),!this.zip)throw new Error("impossible");const e=this.zip;e.on("data",t=>super.write(t)),e.on("end",()=>super.end()),e.on("drain",()=>this[As]()),this.on("resume",()=>e.resume())}else this.on("drain",this[As]);this.noDirRecurse=!!t.noDirRecurse,this.follow=!!t.follow,this.noMtime=!!t.noMtime,t.mtime&&(this.mtime=t.mtime),this.filter="function"==typeof t.filter?t.filter:()=>!0,this[ms]=new rs,this[ws]=0,this.jobs=Number(t.jobs)||4,this[ys]=!1,this[us]=!1}[Ds](t){return super.write(t)}add(t){return this.write(t),this}end(t,e,i){return"function"==typeof t&&(i=t,t=void 0),"function"==typeof e&&(i=e,e=void 0),t&&this.add(t),this[us]=!0,this[ps](),i&&i(),this}write(t){if(this[us])throw new Error("write after end");return t instanceof Ue?this[Rs](t):this[Es](t),this.flowing}[Rs](t){const e=ze(u.resolve(this.cwd,t.path));if(this.filter(t.path,t)){const i=new ls(t.path,e);i.entry=new is(t,this[ks](i)),i.entry.on("end",()=>this[gs](i)),this[ws]+=1,this[ms].push(i)}else t.resume();this[ps]()}[Es](t){const e=ze(u.resolve(this.cwd,t));this[ms].push(new ls(t,e)),this[ps]()}[_s](t){t.pending=!0,this[ws]+=1;const e=this.follow?"stat":"lstat";i[e](t.absolute,(e,i)=>{t.pending=!1,this[ws]-=1,e?this.emit("error",e):this[cs](t,i)})}[cs](t,e){this.statCache.set(t.absolute,e),t.stat=e,this.filter(t.path,e)?e.isFile()&&e.nlink>1&&t===this[fs]&&!this.linkCache.get(`${e.dev}:${e.ino}`)&&!this.sync&&this[bs](t):t.ignore=!0,this[ps]()}[Ss](t){t.pending=!0,this[ws]+=1,i.readdir(t.absolute,(e,i)=>{if(t.pending=!1,this[ws]-=1,e)return this.emit("error",e);this[vs](t,i)})}[vs](t,e){this.readdirCache.set(t.absolute,e),t.readdir=e,this[ps]()}[ps](){if(!this[ys]){this[ys]=!0;for(let t=this[ms].head;t&&this[ws]<this.jobs;t=t.next)if(this[bs](t.value),t.value.ignore){const e=t.next;this[ms].removeNode(t),t.next=e}this[ys]=!1,this[us]&&!this[ms].length&&0===this[ws]&&(this.zip?this.zip.end(ds):(super.write(ds),super.end()))}}get[fs](){return this[ms]&&this[ms].head&&this[ms].head.value}[gs](t){this[ms].shift(),this[ws]-=1,this[ps]()}[bs](t){if(!t.pending)if(t.entry)t!==this[fs]||t.piped||this[Os](t);else{if(!t.stat){const e=this.statCache.get(t.absolute);e?this[cs](t,e):this[_s](t)}if(t.stat&&!t.ignore){if(!this.noDirRecurse&&t.stat.isDirectory()&&!t.readdir){const e=this.readdirCache.get(t.absolute);if(e?this[vs](t,e):this[Ss](t),!t.readdir)return}t.entry=this[Ts](t),t.entry?t!==this[fs]||t.piped||this[Os](t):t.ignore=!0}}}[ks](t){return{onwarn:(t,e,i)=>this.warn(t,e,i),noPax:this.noPax,cwd:this.cwd,absolute:t.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[Ts](t){this[ws]+=1;try{return new this[Ls](t.path,this[ks](t)).on("end",()=>this[gs](t)).on("error",t=>this.emit("error",t))}catch(t){this.emit("error",t)}}[As](){this[fs]&&this[fs].entry&&this[fs].entry.resume()}[Os](t){t.piped=!0,t.readdir&&t.readdir.forEach(e=>{const i=t.path,s="./"===i?"":i.replace(/\/*$/,"/");this[Es](s+e)});const e=t.entry,i=this.zip;if(!e)throw new Error("cannot pipe without source");i?e.on("data",t=>{i.write(t)||e.pause()}):e.on("data",t=>{super.write(t)||e.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(t,e,i={}){je(this,t,e,i)}}class Ns extends xs{sync=!0;constructor(t){super(t),this[Ls]=es}pause(){}resume(){}[_s](t){const e=this.follow?"statSync":"lstatSync";this[cs](t,i[e](t.absolute))}[Ss](t){this[vs](t,i.readdirSync(t.absolute))}[Os](t){const e=t.entry,i=this.zip;if(t.readdir&&t.readdir.forEach(e=>{const i=t.path,s="./"===i?"":i.replace(/\/*$/,"/");this[Es](s+e)}),!e)throw new Error("Cannot pipe without source");i?e.on("data",t=>{i.write(t)}):e.on("data",t=>{super[Ds](t)})}}const Is=(t,e)=>{e.forEach(e=>{"@"===e.charAt(0)?Oi({file:h.resolve(t.cwd,e.slice(1)),sync:!0,noResume:!0,onReadEntry:e=>t.add(e)}):t.add(e)}),t.end()},Fs=async(t,e)=>{for(let i=0;i<e.length;i++){const s=String(e[i]);"@"===s.charAt(0)?await Oi({file:h.resolve(String(t.cwd),s.slice(1)),noResume:!0,onReadEntry:e=>{t.add(e)}}):t.add(s)}t.end()},Bs=Gt((t,e)=>{const i=new Ns(t),s=new Ut(t.file,{mode:t.mode||438});i.pipe(s),Is(i,e)},(t,e)=>{const i=new xs(t),s=new zt(t.file,{mode:t.mode||438});i.pipe(s);const r=new Promise((t,e)=>{s.on("error",e),s.on("close",t),i.on("error",e)});return Fs(i,e),r},(t,e)=>{const i=new Ns(t);return Is(i,e),i},(t,e)=>{const i=new xs(t);return Fs(i,e),i},(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")}),Cs="win32"===(process.env.__FAKE_PLATFORM__||process.platform),{O_CREAT:Ms,O_TRUNC:Ps,O_WRONLY:zs}=i.constants,Us=Number(process.env.__FAKE_FS_O_FILENAME__)||i.constants.UV_FS_O_FILEMAP||0,js=Us|Ps|Ms|zs,Zs=Cs&&!!Us?t=>t<524288?js:"w":()=>"w",Hs=(t,e,i)=>{try{return c.lchownSync(t,e,i)}catch(t){if("ENOENT"!==t?.code)throw t}},Gs=(t,e,i,s)=>{c.lchown(t,e,i,t=>{s(t&&"ENOENT"!==t?.code?t:null)})},Ws=(t,e,i,s,r)=>{if(e.isDirectory())Ys(h.resolve(t,e.name),i,s,n=>{if(n)return r(n);const o=h.resolve(t,e.name);Gs(o,i,s,r)});else{const n=h.resolve(t,e.name);Gs(n,i,s,r)}},Ys=(t,e,i,s)=>{c.readdir(t,{withFileTypes:!0},(r,n)=>{if(r){if("ENOENT"===r.code)return s();if("ENOTDIR"!==r.code&&"ENOTSUP"!==r.code)return s(r)}if(r||!n.length)return Gs(t,e,i,s);let h=n.length,o=null;const a=r=>{if(!o)return r?s(o=r):0===--h?Gs(t,e,i,s):void 0};for(const s of n)Ws(t,s,e,i,a)})},$s=(t,e,i,s)=>{e.isDirectory()&&Vs(h.resolve(t,e.name),i,s),Hs(h.resolve(t,e.name),i,s)},Vs=(t,e,i)=>{let s;try{s=c.readdirSync(t,{withFileTypes:!0})}catch(s){const r=s;if("ENOENT"===r?.code)return;if("ENOTDIR"===r?.code||"ENOTSUP"===r?.code)return Hs(t,e,i);throw r}for(const r of s)$s(t,r,e,i);return Hs(t,e,i)};class qs extends Error{path;code;syscall="chdir";constructor(t,e){super(`${e}: Cannot cd into '${t}'`),this.path=t,this.code=e}get name(){return"CwdError"}}class Ks extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(t,e){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=t,this.path=e}get name(){return"SymlinkError"}}const Xs=(t,e,i)=>{t=ze(t);const s=e.umask??18,r=448|e.mode,n=0!==(r&s),o=e.uid,a=e.gid,l="number"==typeof o&&"number"==typeof a&&(o!==e.processUid||a!==e.processGid),d=e.preserve,u=e.unlink,m=ze(e.cwd),f=(e,s)=>{e?i(e):s&&l?Ys(s,o,a,t=>f(t)):n?c.chmod(t,r,i):i()};if(t===m)return((t,e)=>{c.stat(t,(i,s)=>{!i&&s.isDirectory()||(i=new qs(t,i?.code||"ENOTDIR")),e(i)})})(t,f);if(d)return R.mkdir(t,{mode:r,recursive:!0}).then(t=>f(null,t??void 0),f);const p=ze(h.relative(m,t)).split("/");Qs(m,p,r,u,m,void 0,f)},Qs=(t,e,i,s,r,n,o)=>{if(!e.length)return o(null,n);const a=e.shift(),l=ze(h.resolve(t+"/"+a));c.mkdir(l,i,Js(l,e,i,s,r,n,o))},Js=(t,e,i,s,r,n,h)=>o=>{o?c.lstat(t,(a,l)=>{if(a)a.path=a.path&&ze(a.path),h(a);else if(l.isDirectory())Qs(t,e,i,s,r,n,h);else if(s)c.unlink(t,o=>{if(o)return h(o);c.mkdir(t,i,Js(t,e,i,s,r,n,h))});else{if(l.isSymbolicLink())return h(new Ks(t,t+"/"+e.join("/")));h(o)}}):Qs(t,e,i,s,r,n=n||t,h)},tr=(t,e)=>{t=ze(t);const i=e.umask??18,s=448|e.mode,r=0!==(s&i),n=e.uid,o=e.gid,a="number"==typeof n&&"number"==typeof o&&(n!==e.processUid||o!==e.processGid),l=e.preserve,d=e.unlink,u=ze(e.cwd),m=e=>{e&&a&&Vs(e,n,o),r&&c.chmodSync(t,s)};if(t===u)return(t=>{let e,i=!1;try{i=c.statSync(t).isDirectory()}catch(t){e=t?.code}finally{if(!i)throw new qs(t,e??"ENOTDIR")}})(u),m();if(l)return m(c.mkdirSync(t,{mode:s,recursive:!0})??void 0);const f=ze(h.relative(u,t)).split("/");let p;for(let t=f.shift(),e=u;t&&(e+="/"+t);t=f.shift()){e=ze(h.resolve(e));try{c.mkdirSync(e,s),p=p||e}catch(t){const i=c.lstatSync(e);if(i.isDirectory())continue;if(d){c.unlinkSync(e),c.mkdirSync(e,s),p=p||e;continue}if(i.isSymbolicLink())return new Ks(e,e+"/"+f.join("/"))}}return m(p)},er=Object.create(null),ir=new Set,sr="win32"===(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform);class rr{#m=new Map;#f=new Map;#p=new Set;reserve(t,e){t=sr?["win32 parallelization disabled"]:t.map(t=>Si(d((t=>{ir.has(t)?ir.delete(t):er[t]=t.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"),ir.add(t);const e=er[t];let i=ir.size-1e4;if(i>1e3)for(const t of ir)if(ir.delete(t),delete er[t],--i<=0)break;return e})(t))));const i=new Set(t.map(t=>(t=>{const e=t.split("/").slice(0,-1).reduce((t,e)=>{const i=t[t.length-1];return void 0!==i&&(e=d(i,e)),t.push(e||"/"),t},[]);return e})(t)).reduce((t,e)=>t.concat(e)));this.#f.set(e,{dirs:i,paths:t});for(const i of t){const t=this.#m.get(i);t?t.push(e):this.#m.set(i,[e])}for(const t of i){const i=this.#m.get(t);if(i){const t=i[i.length-1];t instanceof Set?t.add(e):i.push(new Set([e]))}else this.#m.set(t,[new Set([e])])}return this.#y(e)}#b(t){const e=this.#f.get(t);if(!e)throw new Error("function does not have any path reservations");return{paths:e.paths.map(t=>this.#m.get(t)),dirs:[...e.dirs].map(t=>this.#m.get(t))}}check(t){const{paths:e,dirs:i}=this.#b(t);return e.every(e=>e&&e[0]===t)&&i.every(e=>e&&e[0]instanceof Set&&e[0].has(t))}#y(t){return!(this.#p.has(t)||!this.check(t))&&(this.#p.add(t),t(()=>this.#w(t)),!0)}#w(t){if(!this.#p.has(t))return!1;const e=this.#f.get(t);if(!e)throw new Error("invalid reservation");const{paths:i,dirs:s}=e,r=new Set;for(const e of i){const i=this.#m.get(e);if(!i||i?.[0]!==t)continue;const s=i[1];if(s)if(i.shift(),"function"==typeof s)r.add(s);else for(const t of s)r.add(t);else this.#m.delete(e)}for(const e of s){const i=this.#m.get(e),s=i?.[0];if(i&&s instanceof Set)if(1!==s.size||1!==i.length)if(1===s.size){i.shift();const t=i[0];"function"==typeof t&&r.add(t)}else s.delete(t);else this.#m.delete(e)}return this.#p.delete(t),r.forEach(t=>this.#y(t)),!0}}const nr=Symbol("onEntry"),hr=Symbol("checkFs"),or=Symbol("checkFs2"),ar=Symbol("isReusable"),lr=Symbol("makeFs"),dr=Symbol("file"),cr=Symbol("directory"),ur=Symbol("link"),mr=Symbol("symlink"),fr=Symbol("hardlink"),pr=Symbol("unsupported"),yr=Symbol("checkPath"),br=Symbol("stripAbsolutePath"),wr=Symbol("mkdir"),gr=Symbol("onError"),Er=Symbol("pending"),Rr=Symbol("pend"),_r=Symbol("unpend"),Sr=Symbol("ended"),vr=Symbol("maybeClose"),Or=Symbol("skip"),Tr=Symbol("doChown"),kr=Symbol("uid"),Lr=Symbol("gid"),Dr=Symbol("checkedCwd"),Ar="win32"===(process.env.TESTING_TAR_FAKE_PLATFORM||process.platform),xr=(t,e,i)=>void 0!==t&&t===t>>>0?t:void 0!==e&&e===e>>>0?e:i;class Nr extends _i{[Sr]=!1;[Dr]=!1;[Er]=0;reservations=new rr;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(t={}){if(t.ondone=()=>{this[Sr]=!0,this[vr]()},super(t),this.transform=t.transform,this.chmod=!!t.chmod,"number"==typeof t.uid||"number"==typeof t.gid){if("number"!=typeof t.uid||"number"!=typeof t.gid)throw new TypeError("cannot set owner without number uid and gid");if(t.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=t.uid,this.gid=t.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;void 0===t.preserveOwner&&"number"!=typeof t.uid?this.preserveOwner=!(!process.getuid||0!==process.getuid()):this.preserveOwner=!!t.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth="number"==typeof t.maxDepth?t.maxDepth:1024,this.forceChown=!0===t.forceChown,this.win32=!!t.win32||Ar,this.newer=!!t.newer,this.keep=!!t.keep,this.noMtime=!!t.noMtime,this.preservePaths=!!t.preservePaths,this.unlink=!!t.unlink,this.cwd=ze(h.resolve(t.cwd||process.cwd())),this.strip=Number(t.strip)||0,this.processUmask=this.chmod?"number"==typeof t.processUmask?t.processUmask:process.umask():0,this.umask="number"==typeof t.umask?t.umask:this.processUmask,this.dmode=t.dmode||511&~this.umask,this.fmode=t.fmode||438&~this.umask,this.on("entry",t=>this[nr](t))}warn(t,e,i={}){return"TAR_BAD_ARCHIVE"!==t&&"TAR_ABORT"!==t||(i.recoverable=!1),super.warn(t,e,i)}[vr](){this[Sr]&&0===this[Er]&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[br](t,e){const i=t[e];if(!i||this.preservePaths)return!0;const s=i.split("/");if(s.includes("..")||Ar&&/^[a-z]:\.\.$/i.test(s[0]??"")){if("path"===e)return this.warn("TAR_ENTRY_ERROR",`${e} contains '..'`,{entry:t,[e]:i}),!1;{const s=h.posix.dirname(t.path),r=h.posix.normalize(h.posix.join(s,i));if(r.startsWith("../")||".."===r)return this.warn("TAR_ENTRY_ERROR",`${e} escapes extraction directory`,{entry:t,[e]:i}),!1}}const[r,n]=Di(i);return r&&(t[e]=String(n),this.warn("TAR_ENTRY_INFO",`stripping ${r} from absolute ${e}`,{entry:t,[e]:i})),!0}[yr](t){const e=ze(t.path),i=e.split("/");if(this.strip){if(i.length<this.strip)return!1;if("Link"===t.type){const e=ze(String(t.linkpath)).split("/");if(!(e.length>=this.strip))return!1;t.linkpath=e.slice(this.strip).join("/")}i.splice(0,this.strip),t.path=i.join("/")}if(isFinite(this.maxDepth)&&i.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:t,path:e,depth:i.length,maxDepth:this.maxDepth}),!1;if(!this[br](t,"path")||!this[br](t,"linkpath"))return!1;if(h.isAbsolute(t.path)?t.absolute=ze(h.resolve(t.path)):t.absolute=ze(h.resolve(this.cwd,t.path)),!this.preservePaths&&"string"==typeof t.absolute&&0!==t.absolute.indexOf(this.cwd+"/")&&t.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:t,path:ze(t.path),resolvedPath:t.absolute,cwd:this.cwd}),!1;if(t.absolute===this.cwd&&"Directory"!==t.type&&"GNUDumpDir"!==t.type)return!1;if(this.win32){const{root:e}=h.win32.parse(String(t.absolute));t.absolute=e+Fi(String(t.absolute).slice(e.length));const{root:i}=h.win32.parse(t.path);t.path=i+Fi(t.path.slice(i.length))}return!0}[nr](t){if(!this[yr](t))return t.resume();switch(g.equal(typeof t.absolute,"string"),t.type){case"Directory":case"GNUDumpDir":t.mode&&(t.mode=448|t.mode);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[hr](t);default:return this[pr](t)}}[gr](t,e){"CwdError"===t.name?this.emit("error",t):(this.warn("TAR_ENTRY_ERROR",t,{entry:e}),this[_r](),e.resume())}[wr](t,e,i){Xs(ze(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e},i)}[Tr](t){return this.forceChown||this.preserveOwner&&("number"==typeof t.uid&&t.uid!==this.processUid||"number"==typeof t.gid&&t.gid!==this.processGid)||"number"==typeof this.uid&&this.uid!==this.processUid||"number"==typeof this.gid&&this.gid!==this.processGid}[kr](t){return xr(this.uid,t.uid,this.processUid)}[Lr](t){return xr(this.gid,t.gid,this.processGid)}[dr](t,e){const i="number"==typeof t.mode?4095&t.mode:this.fmode,s=new zt(String(t.absolute),{flags:Zs(t.size),mode:i,autoClose:!1});s.on("error",i=>{s.fd&&c.close(s.fd,()=>{}),s.write=()=>!0,this[gr](i,t),e()});let r=1;const n=i=>{if(i)return s.fd&&c.close(s.fd,()=>{}),this[gr](i,t),void e();0===--r&&void 0!==s.fd&&c.close(s.fd,i=>{i?this[gr](i,t):this[_r](),e()})};s.on("finish",()=>{const e=String(t.absolute),i=s.fd;if("number"==typeof i&&t.mtime&&!this.noMtime){r++;const s=t.atime||new Date,h=t.mtime;c.futimes(i,s,h,t=>t?c.utimes(e,s,h,e=>n(e&&t)):n())}if("number"==typeof i&&this[Tr](t)){r++;const s=this[kr](t),h=this[Lr](t);"number"==typeof s&&"number"==typeof h&&c.fchown(i,s,h,t=>t?c.chown(e,s,h,e=>n(e&&t)):n())}n()});const h=this.transform&&this.transform(t)||t;h!==t&&(h.on("error",i=>{this[gr](i,t),e()}),t.pipe(h)),h.pipe(s)}[cr](t,e){const i="number"==typeof t.mode?4095&t.mode:this.dmode;this[wr](String(t.absolute),i,i=>{if(i)return this[gr](i,t),void e();let s=1;const r=()=>{0===--s&&(e(),this[_r](),t.resume())};t.mtime&&!this.noMtime&&(s++,c.utimes(String(t.absolute),t.atime||new Date,t.mtime,r)),this[Tr](t)&&(s++,c.chown(String(t.absolute),Number(this[kr](t)),Number(this[Lr](t)),r)),r()})}[pr](t){t.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${t.type}`,{entry:t}),t.resume()}[mr](t,e){this[ur](t,String(t.linkpath),"symlink",e)}[fr](t,e){const i=ze(h.resolve(this.cwd,String(t.linkpath)));this[ur](t,i,"link",e)}[Rr](){this[Er]++}[_r](){this[Er]--,this[vr]()}[Or](t){this[_r](),t.resume()}[ar](t,e){return"File"===t.type&&!this.unlink&&e.isFile()&&e.nlink<=1&&!Ar}[hr](t){this[Rr]();const e=[t.path];t.linkpath&&e.push(t.linkpath),this.reservations.reserve(e,e=>this[or](t,e))}[or](t,e){const i=t=>{e(t)},s=()=>{this[wr](this.cwd,this.dmode,e=>{if(e)return this[gr](e,t),void i();this[Dr]=!0,r()})},r=()=>{if(t.absolute!==this.cwd){const e=ze(h.dirname(String(t.absolute)));if(e!==this.cwd)return this[wr](e,this.dmode,e=>{if(e)return this[gr](e,t),void i();n()})}n()},n=()=>{c.lstat(String(t.absolute),(e,s)=>{if(s&&(this.keep||this.newer&&s.mtime>(t.mtime??s.mtime)))return this[Or](t),void i();if(e||this[ar](t,s))return this[lr](null,t,i);if(s.isDirectory()){if("Directory"===t.type){const e=e=>this[lr](e??null,t,i);return this.chmod&&t.mode&&(4095&s.mode)!==t.mode?c.chmod(String(t.absolute),Number(t.mode),e):e()}if(t.absolute!==this.cwd)return c.rmdir(String(t.absolute),e=>this[lr](e??null,t,i))}if(t.absolute===this.cwd)return this[lr](null,t,i);((t,e)=>{if(!Ar)return c.unlink(t,e);const i=t+".DELETE."+E(16).toString("hex");c.rename(t,i,t=>{if(t)return e(t);c.unlink(i,e)})})(String(t.absolute),e=>this[lr](e??null,t,i))})};this[Dr]?r():s()}[lr](t,e,i){if(t)return this[gr](t,e),void i();switch(e.type){case"File":case"OldFile":case"ContiguousFile":return this[dr](e,i);case"Link":return this[fr](e,i);case"SymbolicLink":return this[mr](e,i);case"Directory":case"GNUDumpDir":return this[cr](e,i)}}[ur](t,e,i,s){c[i](e,String(t.absolute),e=>{e?this[gr](e,t):(this[_r](),t.resume()),s()})}}const Ir=t=>{try{return[null,t()]}catch(t){return[t,null]}};class Fr extends Nr{sync=!0;[lr](t,e){return super[lr](t,e,()=>{})}[hr](t){if(!this[Dr]){const e=this[wr](this.cwd,this.dmode);if(e)return this[gr](e,t);this[Dr]=!0}if(t.absolute!==this.cwd){const e=ze(h.dirname(String(t.absolute)));if(e!==this.cwd){const i=this[wr](e,this.dmode);if(i)return this[gr](i,t)}}const[e,i]=Ir(()=>c.lstatSync(String(t.absolute)));if(i&&(this.keep||this.newer&&i.mtime>(t.mtime??i.mtime)))return this[Or](t);if(e||this[ar](t,i))return this[lr](null,t);if(i.isDirectory()){if("Directory"===t.type){const e=this.chmod&&t.mode&&(4095&i.mode)!==t.mode,[s]=e?Ir(()=>{c.chmodSync(String(t.absolute),Number(t.mode))}):[];return this[lr](s,t)}const[e]=Ir(()=>c.rmdirSync(String(t.absolute)));this[lr](e,t)}const[s]=t.absolute===this.cwd?[]:Ir(()=>(t=>{if(!Ar)return c.unlinkSync(t);const e=t+".DELETE."+E(16).toString("hex");c.renameSync(t,e),c.unlinkSync(e)})(String(t.absolute)));this[lr](s,t)}[dr](t,e){const i="number"==typeof t.mode?4095&t.mode:this.fmode,s=i=>{let s;try{c.closeSync(r)}catch(t){s=t}(i||s)&&this[gr](i||s,t),e()};let r;try{r=c.openSync(String(t.absolute),Zs(t.size),i)}catch(t){return s(t)}const n=this.transform&&this.transform(t)||t;n!==t&&(n.on("error",e=>this[gr](e,t)),t.pipe(n)),n.on("data",t=>{try{c.writeSync(r,t,0,t.length)}catch(t){s(t)}}),n.on("end",()=>{let e=null;if(t.mtime&&!this.noMtime){const i=t.atime||new Date,s=t.mtime;try{c.futimesSync(r,i,s)}catch(r){try{c.utimesSync(String(t.absolute),i,s)}catch(t){e=r}}}if(this[Tr](t)){const i=this[kr](t),s=this[Lr](t);try{c.fchownSync(r,Number(i),Number(s))}catch(r){try{c.chownSync(String(t.absolute),Number(i),Number(s))}catch(t){e=e||r}}}s(e)})}[cr](t,e){const i="number"==typeof t.mode?4095&t.mode:this.dmode,s=this[wr](String(t.absolute),i);if(s)return this[gr](s,t),void e();if(t.mtime&&!this.noMtime)try{c.utimesSync(String(t.absolute),t.atime||new Date,t.mtime)}catch(s){}if(this[Tr](t))try{c.chownSync(String(t.absolute),Number(this[kr](t)),Number(this[Lr](t)))}catch(s){}e(),t.resume()}[wr](t,e){try{return tr(ze(t),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:e})}catch(t){return t}}[ur](t,e,i,s){const r=`${i}Sync`;try{c[r](e,String(t.absolute)),s(),t.resume()}catch(e){return this[gr](e,t)}}}const Br=Gt(t=>{const e=new Fr(t),i=t.file,s=c.statSync(i),r=t.maxReadSize||16777216;new Pt(i,{readSize:r,size:s.size}).pipe(e)},(t,e)=>{const i=new Nr(t),s=t.maxReadSize||16777216,r=t.file;return new Promise((t,e)=>{i.on("error",e),i.on("close",t),c.stat(r,(t,n)=>{if(t)e(t);else{const t=new Mt(r,{readSize:s,size:n.size});t.on("error",e),t.pipe(i)}})})},t=>new Fr(t),t=>new Nr(t),(t,e)=>{e?.length&&vi(t,e)}),Cr=(t,e,i,s,r)=>{const n=new Ut(t.file,{fd:s,start:i});e.pipe(n),Mr(e,r)},Mr=(t,e)=>{e.forEach(e=>{"@"===e.charAt(0)?Oi({file:h.resolve(t.cwd,e.slice(1)),sync:!0,noResume:!0,onReadEntry:e=>t.add(e)}):t.add(e)}),t.end()},Pr=async(t,e)=>{for(let i=0;i<e.length;i++){const s=String(e[i]);"@"===s.charAt(0)?await Oi({file:h.resolve(String(t.cwd),s.slice(1)),noResume:!0,onReadEntry:e=>t.add(e)}):t.add(s)}t.end()},zr=Gt((t,e)=>{const i=new Ns(t);let s,r,n=!0;try{try{s=c.openSync(t.file,"r+")}catch(e){if("ENOENT"!==e?.code)throw e;s=c.openSync(t.file,"w+")}const h=c.fstatSync(s),o=Buffer.alloc(512);t:for(r=0;r<h.size;r+=512){for(let t=0,e=0;t<512;t+=e){if(e=c.readSync(s,o,t,o.length-t,r+t),0===r&&31===o[0]&&139===o[1])throw new Error("cannot append to compressed archives");if(!e)break t}const e=new Ee(o);if(!e.cksumValid)break;const i=512*Math.ceil((e.size||0)/512);if(r+i+512>h.size)break;r+=i,t.mtimeCache&&e.mtime&&t.mtimeCache.set(String(e.path),e.mtime)}n=!1,Cr(t,i,r,s,e)}finally{if(n)try{c.closeSync(s)}catch(t){}}},(t,e)=>{e=Array.from(e);const i=new xs(t),s=new Promise((s,r)=>{i.on("error",r);let n="r+";const h=(o,a)=>o&&"ENOENT"===o.code&&"r+"===n?(n="w+",c.open(t.file,n,h)):o||!a?r(o):void c.fstat(a,(n,h)=>{if(n)return c.close(a,()=>r(n));((e,i,s)=>{const r=(t,i)=>{t?c.close(e,e=>s(t)):s(null,i)};let n=0;if(0===i)return r(null,0);let h=0;const o=Buffer.alloc(512),a=(s,l)=>{if(s||void 0===l)return r(s);if(h+=l,h<512&&l)return c.read(e,o,h,o.length-h,n+h,a);if(0===n&&31===o[0]&&139===o[1])return r(new Error("cannot append to compressed archives"));if(h<512)return r(null,n);const d=new Ee(o);if(!d.cksumValid)return r(null,n);const u=512*Math.ceil((d.size??0)/512);return n+u+512>i?r(null,n):(n+=u+512,n>=i?r(null,n):(t.mtimeCache&&d.mtime&&t.mtimeCache.set(String(d.path),d.mtime),h=0,void c.read(e,o,0,512,n,a)))};c.read(e,o,0,512,n,a)})(a,h.size,(n,h)=>{if(n)return r(n);const o=new zt(t.file,{fd:a,start:h});i.pipe(o),o.on("error",r),o.on("close",s),Pr(i,e)})});c.open(t.file,n,h)});return s},()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!t.file)throw new TypeError("file is required");if(t.gzip||t.brotli||t.zstd||t.file.endsWith(".br")||t.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!e?.length)throw new TypeError("no paths specified to add/replace")}),Ur=Gt(zr.syncFile,zr.asyncFile,zr.syncNoFile,zr.asyncNoFile,(t,e=[])=>{zr.validate?.(t,e),jr(t)}),jr=t=>{const e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(i,s)=>e(i,s)&&!((t.mtimeCache?.get(i)??s.mtime??0)>(s.mtime??0)):(e,i)=>!((t.mtimeCache?.get(e)??i.mtime??0)>(i.mtime??0))};export{Ee as Header,xs as Pack,ls as PackJob,Ns as PackSync,_i as Parser,Be as Pax,Ue as ReadEntry,Nr as Unpack,Fr as UnpackSync,ts as WriteEntry,es as WriteEntrySync,is as WriteEntryTar,Bs as c,Bs as create,Br as extract,vi as filesFilter,Oi as list,zr as r,zr as replace,Oi as t,ge as types,Ur as u,Ur as update,Br as x};
|