@befive/wc-repository 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +17 -0
  2. package/bin.js +5 -0
  3. package/package.json +15 -0
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # This "repository" combine CDN and API
2
+
3
+ In the future, it should be dissociate to an NGINX and API.
4
+ For the moment, no verification except the existence of the file.
5
+ Only one instance is accepted.
6
+
7
+ Ideally, we can create a cluster.
8
+ Add node easily and nodes distributes the responsability of each namespace.
9
+ Node communicate with the storage of CDN to add the new component.
10
+
11
+
12
+ # DO NOT FORGOT security checks because of javascript
13
+
14
+ # Some important features for the production :
15
+ 1. Searches
16
+ 2. Auth
17
+ 3. Securities and Warnings
package/bin.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+ import{mkdirSync as t4,copyFileSync as e4,readdirSync as $2,rmSync as V2,statSync as i7}from"fs";import{dirname as Q2}from"path";import{dirname as n4,join as m9,relative as c7,resolve as r4}from"path";function q8(...$){return r4(m9(...$))}function C0(...$){return m9(...$)}function A0($){return n4($)}function S9($){return Bun.file($)}async function D9($,V){return w$(Q2($)),await Bun.file($).write(V)}function w$($){t4($,{recursive:!0})}async function N9($){return await Bun.file($).json()}async function o$($){return await Bun.file($).exists()}function R9($,V){e4($,V)}function K8($,V){w$(V);let Q=$2($,{withFileTypes:!0});for(let X of Q){let J=C0($,X.name),Z=C0(V,X.name);if(X.isDirectory())K8(J,Z);else R9(J,Z)}}function G8($){V2($,{recursive:!0,force:!0})}function k9($,V){G8(V),R9($,V)}class H8{port;routes={};constructor($){this.port=$?.port??8080}createRouteDefinition($,V,Q){if(!this.routes[$])this.routes[$]={};this.routes[$][V]=async(X)=>{let J=new URL(X.url),Z=Object.fromEntries(J.searchParams.entries());return Q({method:X.method,url:X.url,path:J.pathname,headers:X.headers,params:{...Z,...X.params},body:{txt:()=>X.text(),json:()=>X.json(),bytes:()=>X.body?.bytes(),blob:()=>X.body?.blob()}})}}post($,V){return this.createRouteDefinition($,"POST",V),this}get($,V){return this.createRouteDefinition($,"GET",V),this}put($,V){return this.createRouteDefinition($,"PUT",V),this}delete($,V){return this.createRouteDefinition($,"DELETE",V),this}options($,V){return this.createRouteDefinition($,"OPTIONS",V),this}patch($,V){return this.createRouteDefinition($,"PATCH",V),this}start(){return Bun.serve({port:this.port,routes:this.routes,fetch:async()=>{return new Response("Not Found",{status:404})}})}}import W2 from"events";import g from"fs";import{EventEmitter as B8}from"events";import h9 from"stream";import{StringDecoder as X2}from"string_decoder";var y9=typeof process==="object"&&process?process:{stdout:null,stderr:null},J2=($)=>!!$&&typeof $==="object"&&($ instanceof D||$ instanceof h9||Z2($)||q2($)),Z2=($)=>!!$&&typeof $==="object"&&$ instanceof B8&&typeof $.pipe==="function"&&$.pipe!==h9.Writable.prototype.pipe,q2=($)=>!!$&&typeof $==="object"&&$ instanceof B8&&typeof $.write==="function"&&typeof $.end==="function",n=Symbol("EOF"),r=Symbol("maybeEmitEnd"),X$=Symbol("emittedEnd"),U0=Symbol("emittingEnd"),n$=Symbol("emittedError"),j0=Symbol("closed"),l9=Symbol("read"),F0=Symbol("flush"),b9=Symbol("flushChunk"),u=Symbol("encoding"),k$=Symbol("decoder"),C=Symbol("flowing"),r$=Symbol("paused"),y$=Symbol("resume"),A=Symbol("buffer"),O=Symbol("pipes"),U=Symbol("bufferLength"),v8=Symbol("bufferPush"),I0=Symbol("bufferShift"),I=Symbol("objectMode"),M=Symbol("destroyed"),z8=Symbol("error"),Y8=Symbol("emitData"),u9=Symbol("emitEnd"),W8=Symbol("emitEnd2"),i=Symbol("async"),x8=Symbol("abort"),_0=Symbol("aborted"),t$=Symbol("signal"),C$=Symbol("dataListeners"),S=Symbol("discarded"),e$=($)=>Promise.resolve().then($),K2=($)=>$(),G2=($)=>$==="end"||$==="finish"||$==="prefinish",H2=($)=>$ instanceof ArrayBuffer||!!$&&typeof $==="object"&&$.constructor&&$.constructor.name==="ArrayBuffer"&&$.byteLength>=0,v2=($)=>!Buffer.isBuffer($)&&ArrayBuffer.isView($);class L8{src;dest;opts;ondrain;constructor($,V,Q){this.src=$,this.dest=V,this.opts=Q,this.ondrain=()=>$[y$](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors($){}end(){if(this.unpipe(),this.opts.end)this.dest.end()}}class c9 extends L8{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor($,V,Q){super($,V,Q);this.proxyErrors=(X)=>V.emit("error",X),$.on("error",this.proxyErrors)}}var z2=($)=>!!$.objectMode,Y2=($)=>!$.objectMode&&!!$.encoding&&$.encoding!=="buffer";class D extends B8{[C]=!1;[r$]=!1;[O]=[];[A]=[];[I];[u];[i];[k$];[n]=!1;[X$]=!1;[U0]=!1;[j0]=!1;[n$]=null;[U]=0;[M]=!1;[t$];[_0]=!1;[C$]=0;[S]=!1;writable=!0;readable=!0;constructor(...$){let V=$[0]||{};super();if(V.objectMode&&typeof V.encoding==="string")throw TypeError("Encoding and objectMode may not be used together");if(z2(V))this[I]=!0,this[u]=null;else if(Y2(V))this[u]=V.encoding,this[I]=!1;else this[I]=!1,this[u]=null;if(this[i]=!!V.async,this[k$]=this[u]?new X2(this[u]):null,V&&V.debugExposeBuffer===!0)Object.defineProperty(this,"buffer",{get:()=>this[A]});if(V&&V.debugExposePipes===!0)Object.defineProperty(this,"pipes",{get:()=>this[O]});let{signal:Q}=V;if(Q)if(this[t$]=Q,Q.aborted)this[x8]();else Q.addEventListener("abort",()=>this[x8]())}get bufferLength(){return this[U]}get encoding(){return this[u]}set encoding($){throw Error("Encoding must be set at instantiation time")}setEncoding($){throw Error("Encoding must be set at instantiation time")}get objectMode(){return this[I]}set objectMode($){throw Error("objectMode must be set at instantiation time")}get["async"](){return this[i]}set["async"]($){this[i]=this[i]||!!$}[x8](){this[_0]=!0,this.emit("abort",this[t$]?.reason),this.destroy(this[t$]?.reason)}get aborted(){return this[_0]}set aborted($){}write($,V,Q){if(this[_0])return!1;if(this[n])throw Error("write after end");if(this[M])return this.emit("error",Object.assign(Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;if(typeof V==="function")Q=V,V="utf8";if(!V)V="utf8";let X=this[i]?e$:K2;if(!this[I]&&!Buffer.isBuffer($)){if(v2($))$=Buffer.from($.buffer,$.byteOffset,$.byteLength);else if(H2($))$=Buffer.from($);else if(typeof $!=="string")throw Error("Non-contiguous data written to non-objectMode stream")}if(this[I]){if(this[C]&&this[U]!==0)this[F0](!0);if(this[C])this.emit("data",$);else this[v8]($);if(this[U]!==0)this.emit("readable");if(Q)X(Q);return this[C]}if(!$.length){if(this[U]!==0)this.emit("readable");if(Q)X(Q);return this[C]}if(typeof $==="string"&&!(V===this[u]&&!this[k$]?.lastNeed))$=Buffer.from($,V);if(Buffer.isBuffer($)&&this[u])$=this[k$].write($);if(this[C]&&this[U]!==0)this[F0](!0);if(this[C])this.emit("data",$);else this[v8]($);if(this[U]!==0)this.emit("readable");if(Q)X(Q);return this[C]}read($){if(this[M])return null;if(this[S]=!1,this[U]===0||$===0||$&&$>this[U])return this[r](),null;if(this[I])$=null;if(this[A].length>1&&!this[I])this[A]=[this[u]?this[A].join(""):Buffer.concat(this[A],this[U])];let V=this[l9]($||null,this[A][0]);return this[r](),V}[l9]($,V){if(this[I])this[I0]();else{let Q=V;if($===Q.length||$===null)this[I0]();else if(typeof Q==="string")this[A][0]=Q.slice($),V=Q.slice(0,$),this[U]-=$;else this[A][0]=Q.subarray($),V=Q.subarray(0,$),this[U]-=$}if(this.emit("data",V),!this[A].length&&!this[n])this.emit("drain");return V}end($,V,Q){if(typeof $==="function")Q=$,$=void 0;if(typeof V==="function")Q=V,V="utf8";if($!==void 0)this.write($,V);if(Q)this.once("end",Q);if(this[n]=!0,this.writable=!1,this[C]||!this[r$])this[r]();return this}[y$](){if(this[M])return;if(!this[C$]&&!this[O].length)this[S]=!0;if(this[r$]=!1,this[C]=!0,this.emit("resume"),this[A].length)this[F0]();else if(this[n])this[r]();else this.emit("drain")}resume(){return this[y$]()}pause(){this[C]=!1,this[r$]=!0,this[S]=!1}get destroyed(){return this[M]}get flowing(){return this[C]}get paused(){return this[r$]}[v8]($){if(this[I])this[U]+=1;else this[U]+=$.length;this[A].push($)}[I0](){if(this[I])this[U]-=1;else this[U]-=this[A][0].length;return this[A].shift()}[F0]($=!1){do;while(this[b9](this[I0]())&&this[A].length);if(!$&&!this[A].length&&!this[n])this.emit("drain")}[b9]($){return this.emit("data",$),this[C]}pipe($,V){if(this[M])return $;this[S]=!1;let Q=this[X$];if(V=V||{},$===y9.stdout||$===y9.stderr)V.end=!1;else V.end=V.end!==!1;if(V.proxyErrors=!!V.proxyErrors,Q){if(V.end)$.end()}else if(this[O].push(!V.proxyErrors?new L8(this,$,V):new c9(this,$,V)),this[i])e$(()=>this[y$]());else this[y$]();return $}unpipe($){let V=this[O].find((Q)=>Q.dest===$);if(V){if(this[O].length===1){if(this[C]&&this[C$]===0)this[C]=!1;this[O]=[]}else this[O].splice(this[O].indexOf(V),1);V.unpipe()}}addListener($,V){return this.on($,V)}on($,V){let Q=super.on($,V);if($==="data"){if(this[S]=!1,this[C$]++,!this[O].length&&!this[C])this[y$]()}else if($==="readable"&&this[U]!==0)super.emit("readable");else if(G2($)&&this[X$])super.emit($),this.removeAllListeners($);else if($==="error"&&this[n$]){let X=V;if(this[i])e$(()=>X.call(this,this[n$]));else X.call(this,this[n$])}return Q}removeListener($,V){return this.off($,V)}off($,V){let Q=super.off($,V);if($==="data"){if(this[C$]=this.listeners("data").length,this[C$]===0&&!this[S]&&!this[O].length)this[C]=!1}return Q}removeAllListeners($){let V=super.removeAllListeners($);if($==="data"||$===void 0){if(this[C$]=0,!this[S]&&!this[O].length)this[C]=!1}return V}get emittedEnd(){return this[X$]}[r](){if(!this[U0]&&!this[X$]&&!this[M]&&this[A].length===0&&this[n]){if(this[U0]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[j0])this.emit("close");this[U0]=!1}}emit($,...V){let Q=V[0];if($!=="error"&&$!=="close"&&$!==M&&this[M])return!1;else if($==="data")return!this[I]&&!Q?!1:this[i]?(e$(()=>this[Y8](Q)),!0):this[Y8](Q);else if($==="end")return this[u9]();else if($==="close"){if(this[j0]=!0,!this[X$]&&!this[M])return!1;let J=super.emit("close");return this.removeAllListeners("close"),J}else if($==="error"){this[n$]=Q,super.emit(z8,Q);let J=!this[t$]||this.listeners("error").length?super.emit("error",Q):!1;return this[r](),J}else if($==="resume"){let J=super.emit("resume");return this[r](),J}else if($==="finish"||$==="prefinish"){let J=super.emit($);return this.removeAllListeners($),J}let X=super.emit($,...V);return this[r](),X}[Y8]($){for(let Q of this[O])if(Q.dest.write($)===!1)this.pause();let V=this[S]?!1:super.emit("data",$);return this[r](),V}[u9](){if(this[X$])return!1;return this[X$]=!0,this.readable=!1,this[i]?(e$(()=>this[W8]()),!0):this[W8]()}[W8](){if(this[k$]){let V=this[k$].end();if(V){for(let Q of this[O])Q.dest.write(V);if(!this[S])super.emit("data",V)}}for(let V of this[O])V.end();let $=super.emit("end");return this.removeAllListeners("end"),$}async collect(){let $=Object.assign([],{dataLength:0});if(!this[I])$.dataLength=0;let V=this.promise();return this.on("data",(Q)=>{if($.push(Q),!this[I])$.dataLength+=Q.length}),await V,$}async concat(){if(this[I])throw Error("cannot concat in objectMode");let $=await this.collect();return this[u]?$.join(""):Buffer.concat($,$.dataLength)}async promise(){return new Promise(($,V)=>{this.on(M,()=>V(Error("stream destroyed"))),this.on("error",(Q)=>V(Q)),this.on("end",()=>$())})}[Symbol.asyncIterator](){this[S]=!1;let $=!1,V=async()=>{return this.pause(),$=!0,{value:void 0,done:!0}};return{next:()=>{if($)return V();let X=this.read();if(X!==null)return Promise.resolve({done:!1,value:X});if(this[n])return V();let J,Z,q=(v)=>{this.off("data",K),this.off("end",G),this.off(M,H),V(),Z(v)},K=(v)=>{this.off("error",q),this.off("end",G),this.off(M,H),this.pause(),J({value:v,done:!!this[n]})},G=()=>{this.off("error",q),this.off("data",K),this.off(M,H),V(),J({done:!0,value:void 0})},H=()=>q(Error("stream destroyed"));return new Promise((v,W)=>{Z=W,J=v,this.once(M,H),this.once("error",q),this.once("end",G),this.once("data",K)})},throw:V,return:V,[Symbol.asyncIterator](){return this}}}[Symbol.iterator](){this[S]=!1;let $=!1,V=()=>{return this.pause(),this.off(z8,V),this.off(M,V),this.off("end",V),$=!0,{done:!0,value:void 0}},Q=()=>{if($)return V();let X=this.read();return X===null?V():{done:!1,value:X}};return this.once("end",V),this.once(z8,V),this.once(M,V),{next:Q,throw:V,return:V,[Symbol.iterator](){return this}}}destroy($){if(this[M]){if($)this.emit("error",$);else this.emit(M);return this}this[M]=!0,this[S]=!0,this[A].length=0,this[U]=0;let V=this;if(typeof V.close==="function"&&!this[j0])V.close();if($)this.emit("error",$);else this.emit(M);return this}static get isStream(){return J2}}var x2=g.writev,Z$=Symbol("_autoClose"),c=Symbol("_close"),$0=Symbol("_ended"),x=Symbol("_fd"),P8=Symbol("_finished"),e=Symbol("_flags"),M8=Symbol("_flush"),U8=Symbol("_handleChunk"),j8=Symbol("_makeBuf"),Q0=Symbol("_mode"),T0=Symbol("_needDrain"),u$=Symbol("_onerror"),h$=Symbol("_onopen"),w8=Symbol("_onread"),l$=Symbol("_onwrite"),q$=Symbol("_open"),h=Symbol("_path"),J$=Symbol("_pos"),d=Symbol("_queue"),b$=Symbol("_read"),C8=Symbol("_readSize"),t=Symbol("_reading"),V0=Symbol("_remain"),A8=Symbol("_size"),O0=Symbol("_write"),A$=Symbol("_writing"),g0=Symbol("_defaultFlag"),U$=Symbol("_errored");class c$ extends D{[U$]=!1;[x];[h];[C8];[t]=!1;[A8];[V0];[Z$];constructor($,V){V=V||{};super(V);if(this.readable=!0,this.writable=!1,typeof $!=="string")throw TypeError("path must be a string");if(this[U$]=!1,this[x]=typeof V.fd==="number"?V.fd:void 0,this[h]=$,this[C8]=V.readSize||16777216,this[t]=!1,this[A8]=typeof V.size==="number"?V.size:1/0,this[V0]=this[A8],this[Z$]=typeof V.autoClose==="boolean"?V.autoClose:!0,typeof this[x]==="number")this[b$]();else this[q$]()}get fd(){return this[x]}get path(){return this[h]}write(){throw TypeError("this is a readable stream")}end(){throw TypeError("this is a readable stream")}[q$](){g.open(this[h],"r",($,V)=>this[h$]($,V))}[h$]($,V){if($)this[u$]($);else this[x]=V,this.emit("open",V),this[b$]()}[j8](){return Buffer.allocUnsafe(Math.min(this[C8],this[V0]))}[b$](){if(!this[t]){this[t]=!0;let $=this[j8]();if($.length===0)return process.nextTick(()=>this[w8](null,0,$));g.read(this[x],$,0,$.length,null,(V,Q,X)=>this[w8](V,Q,X))}}[w8]($,V,Q){if(this[t]=!1,$)this[u$]($);else if(this[U8](V,Q))this[b$]()}[c](){if(this[Z$]&&typeof this[x]==="number"){let $=this[x];this[x]=void 0,g.close($,(V)=>V?this.emit("error",V):this.emit("close"))}}[u$]($){this[t]=!0,this[c](),this.emit("error",$)}[U8]($,V){let Q=!1;if(this[V0]-=$,$>0)Q=super.write($<V.length?V.subarray(0,$):V);if($===0||this[V0]<=0)Q=!1,this[c](),super.end();return Q}emit($,...V){switch($){case"prefinish":case"finish":return!1;case"drain":if(typeof this[x]==="number")this[b$]();return!1;case"error":if(this[U$])return!1;return this[U$]=!0,super.emit($,...V);default:return super.emit($,...V)}}}class F8 extends c${[q$](){let $=!0;try{this[h$](null,g.openSync(this[h],"r")),$=!1}finally{if($)this[c]()}}[b$](){let $=!0;try{if(!this[t]){this[t]=!0;do{let V=this[j8](),Q=V.length===0?0:g.readSync(this[x],V,0,V.length,null);if(!this[U8](Q,V))break}while(!0);this[t]=!1}$=!1}finally{if($)this[c]()}}[c](){if(this[Z$]&&typeof this[x]==="number"){let $=this[x];this[x]=void 0,g.closeSync($),this.emit("close")}}}class K$ extends W2{readable=!1;writable=!0;[U$]=!1;[A$]=!1;[$0]=!1;[d]=[];[T0]=!1;[h];[Q0];[Z$];[x];[g0];[e];[P8]=!1;[J$];constructor($,V){V=V||{};super(V);this[h]=$,this[x]=typeof V.fd==="number"?V.fd:void 0,this[Q0]=V.mode===void 0?438:V.mode,this[J$]=typeof V.start==="number"?V.start:void 0,this[Z$]=typeof V.autoClose==="boolean"?V.autoClose:!0;let Q=this[J$]!==void 0?"r+":"w";if(this[g0]=V.flags===void 0,this[e]=V.flags===void 0?Q:V.flags,this[x]===void 0)this[q$]()}emit($,...V){if($==="error"){if(this[U$])return!1;this[U$]=!0}return super.emit($,...V)}get fd(){return this[x]}get path(){return this[h]}[u$]($){this[c](),this[A$]=!0,this.emit("error",$)}[q$](){g.open(this[h],this[e],this[Q0],($,V)=>this[h$]($,V))}[h$]($,V){if(this[g0]&&this[e]==="r+"&&$&&$.code==="ENOENT")this[e]="w",this[q$]();else if($)this[u$]($);else if(this[x]=V,this.emit("open",V),!this[A$])this[M8]()}end($,V){if($)this.write($,V);if(this[$0]=!0,!this[A$]&&!this[d].length&&typeof this[x]==="number")this[l$](null,0);return this}write($,V){if(typeof $==="string")$=Buffer.from($,V);if(this[$0])return this.emit("error",Error("write() after end()")),!1;if(this[x]===void 0||this[A$]||this[d].length)return this[d].push($),this[T0]=!0,!1;return this[A$]=!0,this[O0]($),!0}[O0]($){g.write(this[x],$,0,$.length,this[J$],(V,Q)=>this[l$](V,Q))}[l$]($,V){if($)this[u$]($);else{if(this[J$]!==void 0&&typeof V==="number")this[J$]+=V;if(this[d].length)this[M8]();else if(this[A$]=!1,this[$0]&&!this[P8])this[P8]=!0,this[c](),this.emit("finish");else if(this[T0])this[T0]=!1,this.emit("drain")}}[M8](){if(this[d].length===0){if(this[$0])this[l$](null,0)}else if(this[d].length===1)this[O0](this[d].pop());else{let $=this[d];this[d]=[],x2(this[x],$,this[J$],(V,Q)=>this[l$](V,Q))}}[c](){if(this[Z$]&&typeof this[x]==="number"){let $=this[x];this[x]=void 0,g.close($,(V)=>V?this.emit("error",V):this.emit("close"))}}}class X0 extends K${[q$](){let $;if(this[g0]&&this[e]==="r+")try{$=g.openSync(this[h],this[e],this[Q0])}catch(V){if(V?.code==="ENOENT")return this[e]="w",this[q$]();else throw V}else $=g.openSync(this[h],this[e],this[Q0]);this[h$](null,$)}[c](){if(this[Z$]&&typeof this[x]==="number"){let $=this[x];this[x]=void 0,g.closeSync($),this.emit("close")}}[O0]($){let V=!0;try{this[l$](null,g.writeSync(this[x],$,0,$.length,this[J$])),V=!1}finally{if(V)try{this[c]()}catch{}}}}import A4 from"path";import i$ from"fs";import{dirname as d2,parse as p2}from"path";var B2=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"]]),E9=($)=>!!$.sync&&!!$.file,f9=($)=>!$.sync&&!!$.file,i9=($)=>!!$.sync&&!$.file,d9=($)=>!$.sync&&!$.file;var p9=($)=>!!$.file;var L2=($)=>{let V=B2.get($);if(V)return V;return $},J0=($={})=>{if(!$)return{};let V={};for(let[Q,X]of Object.entries($)){let J=L2(Q);V[J]=X}if(V.chmod===void 0&&V.noChmod===!1)V.chmod=!0;return delete V.noChmod,V};var p=($,V,Q,X,J)=>{return Object.assign((Z=[],q,K)=>{if(Array.isArray(Z))q=Z,Z={};if(typeof q==="function")K=q,q=void 0;if(!q)q=[];else q=Array.from(q);let G=J0(Z);if(J?.(G,q),E9(G)){if(typeof K==="function")throw TypeError("callback not supported for sync tar functions");return $(G,q)}else if(f9(G)){let H=V(G,q),v=K?K:void 0;return v?H.then(()=>v(),v):H}else if(i9(G)){if(typeof K==="function")throw TypeError("callback not supported for sync tar functions");return Q(G,q)}else if(d9(G)){if(typeof K==="function")throw TypeError("callback only supported with file option");return X(G,q)}else throw Error("impossible options??")},{syncFile:$,asyncFile:V,syncNoFile:Q,asyncNoFile:X,validate:J})};import{EventEmitter as c2}from"events";import O8 from"assert";import{Buffer as j$}from"buffer";import*as s9 from"zlib";import P2 from"zlib";var M2=P2.constants||{ZLIB_VERNUM:4736},k=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},M2));var w2=j$.concat,a9=Object.getOwnPropertyDescriptor(j$,"concat"),C2=($)=>$,_8=a9?.writable===!0||a9?.set!==void 0?($)=>{j$.concat=$?C2:w2}:($)=>{},F$=Symbol("_superWrite");class Z0 extends Error{code;errno;constructor($,V){super("zlib: "+$.message,{cause:$});if(this.code=$.code,this.errno=$.errno,!this.code)this.code="ZLIB_ERROR";this.message="zlib: "+$.message,Error.captureStackTrace(this,V??this.constructor)}get name(){return"ZlibError"}}var T8=Symbol("flushFlag");class m0 extends D{#$=!1;#Q=!1;#X;#Z;#J;#V;#q;get sawError(){return this.#$}get handle(){return this.#V}get flushFlag(){return this.#X}constructor($,V){if(!$||typeof $!=="object")throw TypeError("invalid options for ZlibBase constructor");super($);if(this.#X=$.flush??0,this.#Z=$.finishFlush??0,this.#J=$.fullFlushFlag??0,typeof s9[V]!=="function")throw TypeError("Compression method not supported: "+V);try{this.#V=new s9[V]($)}catch(Q){throw new Z0(Q,this.constructor)}this.#q=(Q)=>{if(this.#$)return;this.#$=!0,this.close(),this.emit("error",Q)},this.#V?.on("error",(Q)=>this.#q(new Z0(Q))),this.once("end",()=>this.close)}close(){if(this.#V)this.#V.close(),this.#V=void 0,this.emit("close")}reset(){if(!this.#$)return O8(this.#V,"zlib binding closed"),this.#V.reset?.()}flush($){if(this.ended)return;if(typeof $!=="number")$=this.#J;this.write(Object.assign(j$.alloc(0),{[T8]:$}))}end($,V,Q){if(typeof $==="function")Q=$,V=void 0,$=void 0;if(typeof V==="function")Q=V,V=void 0;if($)if(V)this.write($,V);else this.write($);return this.flush(this.#Z),this.#Q=!0,super.end(Q)}get ended(){return this.#Q}[F$]($){return super.write($)}write($,V,Q){if(typeof V==="function")Q=V,V="utf8";if(typeof $==="string")$=j$.from($,V);if(this.#$)return;O8(this.#V,"zlib binding closed");let X=this.#V._handle,J=X.close;X.close=()=>{};let Z=this.#V.close;this.#V.close=()=>{},_8(!0);let q=void 0;try{let G=typeof $[T8]==="number"?$[T8]:this.#X;q=this.#V._processChunk($,G),_8(!1)}catch(G){_8(!1),this.#q(new Z0(G,this.write))}finally{if(this.#V)this.#V._handle=X,X.close=J,this.#V.close=Z,this.#V.removeAllListeners("error")}if(this.#V)this.#V.on("error",(G)=>this.#q(new Z0(G,this.write)));let K;if(q)if(Array.isArray(q)&&q.length>0){let G=q[0];K=this[F$](j$.from(G));for(let H=1;H<q.length;H++)K=this[F$](q[H])}else K=this[F$](j$.from(q));if(Q)Q();return K}}class g8 extends m0{#$;#Q;constructor($,V){$=$||{},$.flush=$.flush||k.Z_NO_FLUSH,$.finishFlush=$.finishFlush||k.Z_FINISH,$.fullFlushFlag=k.Z_FULL_FLUSH;super($,V);this.#$=$.level,this.#Q=$.strategy}params($,V){if(this.sawError)return;if(!this.handle)throw Error("cannot switch params when binding is closed");if(!this.handle.params)throw Error("not supported in this implementation");if(this.#$!==$||this.#Q!==V){this.flush(k.Z_SYNC_FLUSH),O8(this.handle,"zlib binding closed");let Q=this.handle.flush;this.handle.flush=(X,J)=>{if(typeof X==="function")J=X,X=this.flushFlag;this.flush(X),J?.()};try{this.handle.params($,V)}finally{this.handle.flush=Q}if(this.handle)this.#$=$,this.#Q=V}}}class m8 extends g8{#$;constructor($){super($,"Gzip");this.#$=$&&!!$.portable}[F$]($){if(!this.#$)return super[F$]($);return this.#$=!1,$[9]=255,super[F$]($)}}class S8 extends g8{constructor($){super($,"Unzip")}}class D8 extends m0{constructor($,V){$=$||{},$.flush=$.flush||k.BROTLI_OPERATION_PROCESS,$.finishFlush=$.finishFlush||k.BROTLI_OPERATION_FINISH,$.fullFlushFlag=k.BROTLI_OPERATION_FLUSH;super($,V)}}class N8 extends D8{constructor($){super($,"BrotliCompress")}}class R8 extends D8{constructor($){super($,"BrotliDecompress")}}class k8 extends m0{constructor($,V){$=$||{},$.flush=$.flush||k.ZSTD_e_continue,$.finishFlush=$.finishFlush||k.ZSTD_e_end,$.fullFlushFlag=k.ZSTD_e_flush;super($,V)}}class y8 extends k8{constructor($){super($,"ZstdCompress")}}class l8 extends k8{constructor($){super($,"ZstdDecompress")}}import{posix as E$}from"path";var o9=($,V)=>{if(!Number.isSafeInteger($))throw Error("cannot encode number outside of javascript safe integer range");else if($<0)j2($,V);else U2($,V);return V},U2=($,V)=>{V[0]=128;for(var Q=V.length;Q>1;Q--)V[Q-1]=$&255,$=Math.floor($/256)},j2=($,V)=>{V[0]=255;var Q=!1;$=$*-1;for(var X=V.length;X>1;X--){var J=$&255;if($=Math.floor($/256),Q)V[X-1]=r9(J);else if(J===0)V[X-1]=0;else Q=!0,V[X-1]=t9(J)}},n9=($)=>{let V=$[0],Q=V===128?I2($.subarray(1,$.length)):V===255?F2($):null;if(Q===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(Q))throw Error("parsed number outside of javascript safe integer range");return Q},F2=($)=>{var V=$.length,Q=0,X=!1;for(var J=V-1;J>-1;J--){var Z=Number($[J]),q;if(X)q=r9(Z);else if(Z===0)q=Z;else X=!0,q=t9(Z);if(q!==0)Q-=q*Math.pow(256,V-J-1)}return Q},I2=($)=>{var V=$.length,Q=0;for(var X=V-1;X>-1;X--){var J=Number($[X]);if(J!==0)Q+=J*Math.pow(256,V-X-1)}return Q},r9=($)=>(255^$)&255,t9=($)=>(255^$)+1&255;var S0=($)=>D0.has($);var D0=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"]]),e9=new Map(Array.from(D0).map(($)=>[$[1],$[0]]));class y{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#$="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor($,V=0,Q,X){if(Buffer.isBuffer($))this.decode($,V||0,Q,X);else if($)this.#Q($)}decode($,V,Q,X){if(!V)V=0;if(!$||!($.length>=V+512))throw Error("need 512 bytes for header");if(this.path=Q?.path??I$($,V,100),this.mode=Q?.mode??X?.mode??G$($,V+100,8),this.uid=Q?.uid??X?.uid??G$($,V+108,8),this.gid=Q?.gid??X?.gid??G$($,V+116,8),this.size=Q?.size??X?.size??G$($,V+124,12),this.mtime=Q?.mtime??X?.mtime??b8($,V+136,12),this.cksum=G$($,V+148,12),X)this.#Q(X,!0);if(Q)this.#Q(Q);let J=I$($,V+156,1);if(S0(J))this.#$=J||"0";if(this.#$==="0"&&this.path.slice(-1)==="/")this.#$="5";if(this.#$==="5")this.size=0;if(this.linkpath=I$($,V+157,100),$.subarray(V+257,V+265).toString()==="ustar\x0000")if(this.uname=Q?.uname??X?.uname??I$($,V+265,32),this.gname=Q?.gname??X?.gname??I$($,V+297,32),this.devmaj=Q?.devmaj??X?.devmaj??G$($,V+329,8)??0,this.devmin=Q?.devmin??X?.devmin??G$($,V+337,8)??0,$[V+475]!==0){let q=I$($,V+345,155);this.path=q+"/"+this.path}else{let q=I$($,V+345,130);if(q)this.path=q+"/"+this.path;this.atime=Q?.atime??X?.atime??b8($,V+476,12),this.ctime=Q?.ctime??X?.ctime??b8($,V+488,12)}let Z=256;for(let q=V;q<V+148;q++)Z+=$[q];for(let q=V+156;q<V+512;q++)Z+=$[q];if(this.cksumValid=Z===this.cksum,this.cksum===void 0&&Z===256)this.nullBlock=!0}#Q($,V=!1){Object.assign(this,Object.fromEntries(Object.entries($).filter(([Q,X])=>{return!(X===null||X===void 0||Q==="path"&&V||Q==="linkpath"&&V||Q==="global")})))}encode($,V=0){if(!$)$=this.block=Buffer.alloc(512);if(this.#$==="Unsupported")this.#$="0";if(!($.length>=V+512))throw Error("need 512 bytes for header");let Q=this.ctime||this.atime?130:155,X=T2(this.path||"",Q),J=X[0],Z=X[1];if(this.needPax=!!X[2],this.needPax=_$($,V,100,J)||this.needPax,this.needPax=H$($,V+100,8,this.mode)||this.needPax,this.needPax=H$($,V+108,8,this.uid)||this.needPax,this.needPax=H$($,V+116,8,this.gid)||this.needPax,this.needPax=H$($,V+124,12,this.size)||this.needPax,this.needPax=u8($,V+136,12,this.mtime)||this.needPax,$[V+156]=this.#$.charCodeAt(0),this.needPax=_$($,V+157,100,this.linkpath)||this.needPax,$.write("ustar\x0000",V+257,8),this.needPax=_$($,V+265,32,this.uname)||this.needPax,this.needPax=_$($,V+297,32,this.gname)||this.needPax,this.needPax=H$($,V+329,8,this.devmaj)||this.needPax,this.needPax=H$($,V+337,8,this.devmin)||this.needPax,this.needPax=_$($,V+345,Q,Z)||this.needPax,$[V+475]!==0)this.needPax=_$($,V+345,155,Z)||this.needPax;else this.needPax=_$($,V+345,130,Z)||this.needPax,this.needPax=u8($,V+476,12,this.atime)||this.needPax,this.needPax=u8($,V+488,12,this.ctime)||this.needPax;let q=256;for(let K=V;K<V+148;K++)q+=$[K];for(let K=V+156;K<V+512;K++)q+=$[K];return this.cksum=q,H$($,V+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#$==="Unsupported"?this.#$:D0.get(this.#$)}get typeKey(){return this.#$}set type($){let V=String(e9.get($));if(S0(V)||V==="Unsupported")this.#$=V;else if(S0($))this.#$=$;else throw TypeError("invalid entry type: "+$)}}var T2=($,V)=>{let X=$,J="",Z=void 0,q=E$.parse($).root||".";if(Buffer.byteLength(X)<100)Z=[X,J,!1];else{J=E$.dirname(X),X=E$.basename(X);do if(Buffer.byteLength(X)<=100&&Buffer.byteLength(J)<=V)Z=[X,J,!1];else if(Buffer.byteLength(X)>100&&Buffer.byteLength(J)<=V)Z=[X.slice(0,99),J,!0];else X=E$.join(E$.basename(J),X),J=E$.dirname(J);while(J!==q&&Z===void 0);if(!Z)Z=[$.slice(0,99),"",!0]}return Z},I$=($,V,Q)=>$.subarray(V,V+Q).toString("utf8").replace(/\0.*/,""),b8=($,V,Q)=>O2(G$($,V,Q)),O2=($)=>$===void 0?void 0:new Date($*1000),G$=($,V,Q)=>Number($[V])&128?n9($.subarray(V,V+Q)):m2($,V,Q),g2=($)=>isNaN($)?void 0:$,m2=($,V,Q)=>g2(parseInt($.subarray(V,V+Q).toString("utf8").replace(/\0.*$/,"").trim(),8)),S2={12:8589934591,8:2097151},H$=($,V,Q,X)=>X===void 0?!1:X>S2[Q]||X<0?(o9(X,$.subarray(V,V+Q)),!0):(D2($,V,Q,X),!1),D2=($,V,Q,X)=>$.write(N2(X,Q),V,Q,"ascii"),N2=($,V)=>R2(Math.floor($).toString(8),V),R2=($,V)=>($.length===V-1?$:Array(V-$.length-1).join("0")+$+" ")+"\x00",u8=($,V,Q,X)=>X===void 0?!1:H$($,V,Q,X.getTime()/1000),k2=Array(156).join("\x00"),_$=($,V,Q,X)=>X===void 0?!1:($.write(X+k2,V,Q,"utf8"),X.length!==Buffer.byteLength(X)||X.length>Q);import{basename as y2}from"path";class v${atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor($,V=!1){this.atime=$.atime,this.charset=$.charset,this.comment=$.comment,this.ctime=$.ctime,this.dev=$.dev,this.gid=$.gid,this.global=V,this.gname=$.gname,this.ino=$.ino,this.linkpath=$.linkpath,this.mtime=$.mtime,this.nlink=$.nlink,this.path=$.path,this.size=$.size,this.uid=$.uid,this.uname=$.uname}encode(){let $=this.encodeBody();if($==="")return Buffer.allocUnsafe(0);let V=Buffer.byteLength($),Q=512*Math.ceil(1+V/512),X=Buffer.allocUnsafe(Q);for(let J=0;J<512;J++)X[J]=0;new y({path:("PaxHeader/"+y2(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:V,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(X),X.write($,512,V,"utf8");for(let J=V+512;J<X.length;J++)X[J]=0;return X}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($){if(this[$]===void 0)return"";let V=this[$],Q=V instanceof Date?V.getTime()/1000:V,X=" "+($==="dev"||$==="ino"||$==="nlink"?"SCHILY.":"")+$+"="+Q+`
4
+ `,J=Buffer.byteLength(X),Z=Math.floor(Math.log(J)/Math.log(10))+1;if(J+Z>=Math.pow(10,Z))Z+=1;return Z+J+X}static parse($,V,Q=!1){return new v$(l2(b2($),V),Q)}}var l2=($,V)=>V?Object.assign({},V,$):$,b2=($)=>$.replace(/\n$/,"").split(`
5
+ `).reduce(u2,Object.create(null)),u2=($,V)=>{let Q=parseInt(V,10);if(Q!==Buffer.byteLength(V)+1)return $;V=V.slice((Q+" ").length);let X=V.split("="),J=X.shift();if(!J)return $;let Z=J.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),q=X.join("=");return $[Z]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(Z)?new Date(Number(q)*1000):/^[0-9]+$/.test(q)?+q:q,$};var h2=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,z=h2!=="win32"?($)=>$:($)=>$&&$.replace(/\\/g,"/");class q0 extends D{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($,V,Q){super({});switch(this.pause(),this.extended=V,this.globalExtended=Q,this.header=$,this.remain=$.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=$.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(!$.path)throw Error("no path provided for tar.ReadEntry");if(this.path=z($.path),this.mode=$.mode,this.mode)this.mode=this.mode&4095;if(this.uid=$.uid,this.gid=$.gid,this.uname=$.uname,this.gname=$.gname,this.size=this.remain,this.mtime=$.mtime,this.atime=$.atime,this.ctime=$.ctime,this.linkpath=$.linkpath?z($.linkpath):void 0,this.uname=$.uname,this.gname=$.gname,V)this.#$(V);if(Q)this.#$(Q,!0)}write($){let V=$.length;if(V>this.blockRemain)throw Error("writing more to entry than is appropriate");let Q=this.remain,X=this.blockRemain;if(this.remain=Math.max(0,Q-V),this.blockRemain=Math.max(0,X-V),this.ignore)return!0;if(Q>=V)return super.write($);return super.write($.subarray(0,Q))}#$($,V=!1){if($.path)$.path=z($.path);if($.linkpath)$.linkpath=z($.linkpath);Object.assign(this,Object.fromEntries(Object.entries($).filter(([Q,X])=>{return!(X===null||X===void 0||Q==="path"&&V)})))}}var T$=($,V,Q,X={})=>{if($.file)X.file=$.file;if($.cwd)X.cwd=$.cwd;if(X.code=Q instanceof Error&&Q.code||V,X.tarCode=V,!$.strict&&X.recoverable!==!1){if(Q instanceof Error)X=Object.assign(Q,X),Q=Q.message;$.emit("warn",V,Q,X)}else if(Q instanceof Error)$.emit("error",Object.assign(Q,X));else $.emit("error",Object.assign(Error(`${V}: ${Q}`),X))};var E2=1048576,i8=Buffer.from([31,139]),d8=Buffer.from([40,181,47,253]),f2=Math.max(i8.length,d8.length),l=Symbol("state"),O$=Symbol("writeEntry"),$$=Symbol("readEntry"),h8=Symbol("nextEntry"),V4=Symbol("processEntry"),s=Symbol("extendedHeader"),K0=Symbol("globalExtendedHeader"),z$=Symbol("meta"),Q4=Symbol("emitMeta"),L=Symbol("buffer"),V$=Symbol("queue"),Y$=Symbol("ended"),c8=Symbol("emittedEnd"),g$=Symbol("emit"),w=Symbol("unzip"),N0=Symbol("consumeChunk"),R0=Symbol("consumeChunkSub"),E8=Symbol("consumeBody"),X4=Symbol("consumeMeta"),J4=Symbol("consumeHeader"),G0=Symbol("consuming"),f8=Symbol("bufferConcat"),k0=Symbol("maybeEnd"),f$=Symbol("writing"),W$=Symbol("aborted"),y0=Symbol("onDone"),m$=Symbol("sawValidEntry"),l0=Symbol("sawNullBlock"),b0=Symbol("sawEOF"),Z4=Symbol("closeStream"),i2=()=>!0;class x$ extends c2{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[V$]=[];[L];[$$];[O$];[l]="begin";[z$]="";[s];[K0];[Y$]=!1;[w];[W$]=!1;[m$];[l0]=!1;[b0]=!1;[f$]=!1;[G0]=!1;[c8]=!1;constructor($={}){super();if(this.file=$.file||"",this.on(y0,()=>{if(this[l]==="begin"||this[m$]===!1)this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),$.ondone)this.on(y0,$.ondone);else this.on(y0,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")});this.strict=!!$.strict,this.maxMetaEntrySize=$.maxMetaEntrySize||E2,this.filter=typeof $.filter==="function"?$.filter:i2;let V=$.file&&($.file.endsWith(".tar.br")||$.file.endsWith(".tbr"));this.brotli=!($.gzip||$.zstd)&&$.brotli!==void 0?$.brotli:V?void 0:!1;let Q=$.file&&($.file.endsWith(".tar.zst")||$.file.endsWith(".tzst"));if(this.zstd=!($.gzip||$.brotli)&&$.zstd!==void 0?$.zstd:Q?!0:void 0,this.on("end",()=>this[Z4]()),typeof $.onwarn==="function")this.on("warn",$.onwarn);if(typeof $.onReadEntry==="function")this.on("entry",$.onReadEntry)}warn($,V,Q={}){T$(this,$,V,Q)}[J4]($,V){if(this[m$]===void 0)this[m$]=!1;let Q;try{Q=new y($,V,this[s],this[K0])}catch(X){return this.warn("TAR_ENTRY_INVALID",X)}if(Q.nullBlock)if(this[l0]){if(this[b0]=!0,this[l]==="begin")this[l]="header";this[g$]("eof")}else this[l0]=!0,this[g$]("nullBlock");else if(this[l0]=!1,!Q.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:Q});else if(!Q.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:Q});else{let X=Q.type;if(/^(Symbolic)?Link$/.test(X)&&!Q.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:Q});else if(!/^(Symbolic)?Link$/.test(X)&&!/^(Global)?ExtendedHeader$/.test(X)&&Q.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:Q});else{let J=this[O$]=new q0(Q,this[s],this[K0]);if(!this[m$])if(J.remain){let Z=()=>{if(!J.invalid)this[m$]=!0};J.on("end",Z)}else this[m$]=!0;if(J.meta){if(J.size>this.maxMetaEntrySize)J.ignore=!0,this[g$]("ignoredEntry",J),this[l]="ignore",J.resume();else if(J.size>0)this[z$]="",J.on("data",(Z)=>this[z$]+=Z),this[l]="meta"}else if(this[s]=void 0,J.ignore=J.ignore||!this.filter(J.path,J),J.ignore)this[g$]("ignoredEntry",J),this[l]=J.remain?"ignore":"header",J.resume();else{if(J.remain)this[l]="body";else this[l]="header",J.end();if(!this[$$])this[V$].push(J),this[h8]();else this[V$].push(J)}}}}[Z4](){queueMicrotask(()=>this.emit("close"))}[V4]($){let V=!0;if(!$)this[$$]=void 0,V=!1;else if(Array.isArray($)){let[Q,...X]=$;this.emit(Q,...X)}else if(this[$$]=$,this.emit("entry",$),!$.emittedEnd)$.on("end",()=>this[h8]()),V=!1;return V}[h8](){do;while(this[V4](this[V$].shift()));if(!this[V$].length){let $=this[$$];if(!$||$.flowing||$.size===$.remain){if(!this[f$])this.emit("drain")}else $.once("drain",()=>this.emit("drain"))}}[E8]($,V){let Q=this[O$];if(!Q)throw Error("attempt to consume body without entry??");let X=Q.blockRemain??0,J=X>=$.length&&V===0?$:$.subarray(V,V+X);if(Q.write(J),!Q.blockRemain)this[l]="header",this[O$]=void 0,Q.end();return J.length}[X4]($,V){let Q=this[O$],X=this[E8]($,V);if(!this[O$]&&Q)this[Q4](Q);return X}[g$]($,V,Q){if(!this[V$].length&&!this[$$])this.emit($,V,Q);else this[V$].push([$,V,Q])}[Q4]($){switch(this[g$]("meta",this[z$]),$.type){case"ExtendedHeader":case"OldExtendedHeader":this[s]=v$.parse(this[z$],this[s],!1);break;case"GlobalExtendedHeader":this[K0]=v$.parse(this[z$],this[K0],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let V=this[s]??Object.create(null);this[s]=V,V.path=this[z$].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let V=this[s]||Object.create(null);this[s]=V,V.linkpath=this[z$].replace(/\0.*/,"");break}default:throw Error("unknown meta: "+$.type)}}abort($){this[W$]=!0,this.emit("abort",$),this.warn("TAR_ABORT",$,{recoverable:!1})}write($,V,Q){if(typeof V==="function")Q=V,V=void 0;if(typeof $==="string")$=Buffer.from($,typeof V==="string"?V:"utf8");if(this[W$])return Q?.(),!1;if((this[w]===void 0||this.brotli===void 0&&this[w]===!1)&&$){if(this[L])$=Buffer.concat([this[L],$]),this[L]=void 0;if($.length<f2)return this[L]=$,Q?.(),!0;for(let K=0;this[w]===void 0&&K<i8.length;K++)if($[K]!==i8[K])this[w]=!1;let Z=!1;if(this[w]===!1&&this.zstd!==!1){Z=!0;for(let K=0;K<d8.length;K++)if($[K]!==d8[K]){Z=!1;break}}let q=this.brotli===void 0&&!Z;if(this[w]===!1&&q)if($.length<512)if(this[Y$])this.brotli=!0;else return this[L]=$,Q?.(),!0;else try{new y($.subarray(0,512)),this.brotli=!1}catch(K){this.brotli=!0}if(this[w]===void 0||this[w]===!1&&(this.brotli||Z)){let K=this[Y$];this[Y$]=!1,this[w]=this[w]===void 0?new S8({}):Z?new l8({}):new R8({}),this[w].on("data",(H)=>this[N0](H)),this[w].on("error",(H)=>this.abort(H)),this[w].on("end",()=>{this[Y$]=!0,this[N0]()}),this[f$]=!0;let G=!!this[w][K?"end":"write"]($);return this[f$]=!1,Q?.(),G}}if(this[f$]=!0,this[w])this[w].write($);else this[N0]($);this[f$]=!1;let J=this[V$].length?!1:this[$$]?this[$$].flowing:!0;if(!J&&!this[V$].length)this[$$]?.once("drain",()=>this.emit("drain"));return Q?.(),J}[f8]($){if($&&!this[W$])this[L]=this[L]?Buffer.concat([this[L],$]):$}[k0](){if(this[Y$]&&!this[c8]&&!this[W$]&&!this[G0]){this[c8]=!0;let $=this[O$];if($&&$.blockRemain){let V=this[L]?this[L].length:0;if(this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${$.blockRemain} more bytes, only ${V} available)`,{entry:$}),this[L])$.write(this[L]);$.end()}this[g$](y0)}}[N0]($){if(this[G0]&&$)this[f8]($);else if(!$&&!this[L])this[k0]();else if($){if(this[G0]=!0,this[L]){this[f8]($);let V=this[L];this[L]=void 0,this[R0](V)}else this[R0]($);while(this[L]&&this[L]?.length>=512&&!this[W$]&&!this[b0]){let V=this[L];this[L]=void 0,this[R0](V)}this[G0]=!1}if(!this[L]||this[Y$])this[k0]()}[R0]($){let V=0,Q=$.length;while(V+512<=Q&&!this[W$]&&!this[b0])switch(this[l]){case"begin":case"header":this[J4]($,V),V+=512;break;case"ignore":case"body":V+=this[E8]($,V);break;case"meta":V+=this[X4]($,V);break;default:throw Error("invalid state: "+this[l])}if(V<Q)if(this[L])this[L]=Buffer.concat([$.subarray(V),this[L]]);else this[L]=$.subarray(V)}end($,V,Q){if(typeof $==="function")Q=$,V=void 0,$=void 0;if(typeof V==="function")Q=V,V=void 0;if(typeof $==="string")$=Buffer.from($,V);if(Q)this.once("finish",Q);if(!this[W$])if(this[w]){if($)this[w].write($);this[w].end()}else{if(this[Y$]=!0,this.brotli===void 0||this.zstd===void 0)$=$||Buffer.alloc(0);if($)this.write($);this[k0]()}return this}}var B$=($)=>{let V=$.length-1,Q=-1;while(V>-1&&$.charAt(V)==="/")Q=V,V--;return Q===-1?$:$.slice(0,Q)};var s2=($)=>{let V=$.onReadEntry;$.onReadEntry=V?(Q)=>{V(Q),Q.resume()}:(Q)=>Q.resume()},p8=($,V)=>{let Q=new Map(V.map((Z)=>[B$(Z),!0])),X=$.filter,J=(Z,q="")=>{let K=q||p2(Z).root||".",G;if(Z===K)G=!1;else{let H=Q.get(Z);if(H!==void 0)G=H;else G=J(d2(Z),K)}return Q.set(Z,G),G};$.filter=X?(Z,q)=>X(Z,q)&&J(B$(Z)):(Z)=>J(B$(Z))},a2=($)=>{let V=new x$($),Q=$.file,X;try{X=i$.openSync(Q,"r");let J=i$.fstatSync(X),Z=$.maxReadSize||16777216;if(J.size<Z){let q=Buffer.allocUnsafe(J.size),K=i$.readSync(X,q,0,J.size,0);V.end(K===q.byteLength?q:q.subarray(0,K))}else{let q=0,K=Buffer.allocUnsafe(Z);while(q<J.size){let G=i$.readSync(X,K,0,Z,q);if(G===0)break;q+=G,V.write(K.subarray(0,G))}V.end()}}finally{if(typeof X==="number")try{i$.closeSync(X)}catch(J){}}},o2=($,V)=>{let Q=new x$($),X=$.maxReadSize||16777216,J=$.file;return new Promise((q,K)=>{Q.on("error",K),Q.on("end",q),i$.stat(J,(G,H)=>{if(G)K(G);else{let v=new c$(J,{readSize:X,size:H.size});v.on("error",K),v.pipe(Q)}})})},S$=p(a2,o2,($)=>new x$($),($)=>new x$($),($,V)=>{if(V?.length)p8($,V);if(!$.noResume)s2($)});import n0 from"fs";import a from"fs";import H4 from"path";var s8=($,V,Q)=>{if($&=4095,Q)$=($|384)&-19;if(V){if($&256)$|=64;if($&32)$|=8;if($&4)$|=1}return $};import{win32 as n2}from"path";var{isAbsolute:r2,parse:q4}=n2,H0=($)=>{let V="",Q=q4($);while(r2($)||Q.root){let X=$.charAt(0)==="/"&&$.slice(0,4)!=="//?/"?"/":Q.root;$=$.slice(X.length),V+=X,Q=q4($)}return[V,$]};var u0=["|","<",">","?",":"],a8=u0.map(($)=>String.fromCharCode(61440+$.charCodeAt(0))),t2=new Map(u0.map(($,V)=>[$,a8[V]])),e2=new Map(a8.map(($,V)=>[$,u0[V]])),o8=($)=>u0.reduce((V,Q)=>V.split(Q).join(t2.get(Q)),$),K4=($)=>a8.reduce((V,Q)=>V.split(Q).join(e2.get(Q)),$);var x4=($,V)=>{if(!V)return z($);return $=z($).replace(/^\.(\/|$)/,""),B$(V)+"/"+$},$7=16777216,v4=Symbol("process"),z4=Symbol("file"),Y4=Symbol("directory"),r8=Symbol("symlink"),W4=Symbol("hardlink"),v0=Symbol("header"),h0=Symbol("read"),t8=Symbol("lstat"),c0=Symbol("onlstat"),e8=Symbol("onread"),$9=Symbol("onreadlink"),V9=Symbol("openfile"),Q9=Symbol("onopenfile"),L$=Symbol("close"),E0=Symbol("mode"),X9=Symbol("awaitDrain"),n8=Symbol("ondrain"),o=Symbol("prefix");class f0 extends D{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;#$=!1;constructor($,V={}){let Q=J0(V);super();if(this.path=z($),this.portable=!!Q.portable,this.maxReadSize=Q.maxReadSize||$7,this.linkCache=Q.linkCache||new Map,this.statCache=Q.statCache||new Map,this.preservePaths=!!Q.preservePaths,this.cwd=z(Q.cwd||process.cwd()),this.strict=!!Q.strict,this.noPax=!!Q.noPax,this.noMtime=!!Q.noMtime,this.mtime=Q.mtime,this.prefix=Q.prefix?z(Q.prefix):void 0,this.onWriteEntry=Q.onWriteEntry,typeof Q.onwarn==="function")this.on("warn",Q.onwarn);let X=!1;if(!this.preservePaths){let[Z,q]=H0(this.path);if(Z&&typeof q==="string")this.path=q,X=Z}if(this.win32=!!Q.win32||process.platform==="win32",this.win32)this.path=K4(this.path.replace(/\\/g,"/")),$=$.replace(/\\/g,"/");if(this.absolute=z(Q.absolute||H4.resolve(this.cwd,$)),this.path==="")this.path="./";if(X)this.warn("TAR_ENTRY_INFO",`stripping ${X} from absolute path`,{entry:this,path:X+this.path});let J=this.statCache.get(this.absolute);if(J)this[c0](J);else this[t8]()}warn($,V,Q={}){return T$(this,$,V,Q)}emit($,...V){if($==="error")this.#$=!0;return super.emit($,...V)}[t8](){a.lstat(this.absolute,($,V)=>{if($)return this.emit("error",$);this[c0](V)})}[c0]($){if(this.statCache.set(this.absolute,$),this.stat=$,!$.isFile())$.size=0;this.type=V7($),this.emit("stat",$),this[v4]()}[v4](){switch(this.type){case"File":return this[z4]();case"Directory":return this[Y4]();case"SymbolicLink":return this[r8]();default:return this.end()}}[E0]($){return s8($,this.type==="Directory",this.portable)}[o]($){return x4($,this.prefix)}[v0](){if(!this.stat)throw Error("cannot write header before stat");if(this.type==="Directory"&&this.portable)this.noMtime=!0;if(this.onWriteEntry?.(this),this.header=new y({path:this[o](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[o](this.linkpath):this.linkpath,mode:this[E0](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:this.type==="Unsupported"?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 v$({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[o](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[o](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());let $=this.header?.block;if(!$)throw Error("failed to encode header");super.write($)}[Y4](){if(!this.stat)throw Error("cannot create directory entry without stat");if(this.path.slice(-1)!=="/")this.path+="/";this.stat.size=0,this[v0](),this.end()}[r8](){a.readlink(this.absolute,($,V)=>{if($)return this.emit("error",$);this[$9](V)})}[$9]($){this.linkpath=z($),this[v0](),this.end()}[W4]($){if(!this.stat)throw Error("cannot create link entry without stat");this.type="Link",this.linkpath=z(H4.relative(this.cwd,$)),this.stat.size=0,this[v0](),this.end()}[z4](){if(!this.stat)throw Error("cannot create file entry without stat");if(this.stat.nlink>1){let $=`${this.stat.dev}:${this.stat.ino}`,V=this.linkCache.get($);if(V?.indexOf(this.cwd)===0)return this[W4](V);this.linkCache.set($,this.absolute)}if(this[v0](),this.stat.size===0)return this.end();this[V9]()}[V9](){a.open(this.absolute,"r",($,V)=>{if($)return this.emit("error",$);this[Q9](V)})}[Q9]($){if(this.fd=$,this.#$)return this[L$]();if(!this.stat)throw Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let V=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(V),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[h0]()}[h0](){let{fd:$,buf:V,offset:Q,length:X,pos:J}=this;if($===void 0||V===void 0)throw Error("cannot read file without first opening");a.read($,V,Q,X,J,(Z,q)=>{if(Z)return this[L$](()=>this.emit("error",Z));this[e8](q)})}[L$]($=()=>{}){if(this.fd!==void 0)a.close(this.fd,$)}[e8]($){if($<=0&&this.remain>0){let X=Object.assign(Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[L$](()=>this.emit("error",X))}if($>this.remain){let X=Object.assign(Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[L$](()=>this.emit("error",X))}if(!this.buf)throw Error("should have created buffer prior to reading");if($===this.remain)for(let X=$;X<this.length&&$<this.blockRemain;X++)this.buf[X+this.offset]=0,$++,this.remain++;let V=this.offset===0&&$===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+$);if(!this.write(V))this[X9](()=>this[n8]());else this[n8]()}[X9]($){this.once("drain",$)}write($,V,Q){if(typeof V==="function")Q=V,V=void 0;if(typeof $==="string")$=Buffer.from($,typeof V==="string"?V:"utf8");if(this.blockRemain<$.length){let X=Object.assign(Error("writing more data than expected"),{path:this.absolute});return this.emit("error",X)}return this.remain-=$.length,this.blockRemain-=$.length,this.pos+=$.length,this.offset+=$.length,super.write($,null,Q)}[n8](){if(!this.remain){if(this.blockRemain)super.write(Buffer.alloc(this.blockRemain));return this[L$](($)=>$?this.emit("error",$):this.end())}if(!this.buf)throw Error("buffer lost somehow in ONDRAIN");if(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[h0]()}}class J9 extends f0{sync=!0;[t8](){this[c0](a.lstatSync(this.absolute))}[r8](){this[$9](a.readlinkSync(this.absolute))}[V9](){this[Q9](a.openSync(this.absolute,"r"))}[h0](){let $=!0;try{let{fd:V,buf:Q,offset:X,length:J,pos:Z}=this;if(V===void 0||Q===void 0)throw Error("fd and buf must be set in READ method");let q=a.readSync(V,Q,X,J,Z);this[e8](q),$=!1}finally{if($)try{this[L$](()=>{})}catch(V){}}}[X9]($){$()}[L$]($=()=>{}){if(this.fd!==void 0)a.closeSync(this.fd);$()}}class Z9 extends D{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($,V,Q={}){return T$(this,$,V,Q)}constructor($,V={}){let Q=J0(V);super();this.preservePaths=!!Q.preservePaths,this.portable=!!Q.portable,this.strict=!!Q.strict,this.noPax=!!Q.noPax,this.noMtime=!!Q.noMtime,this.onWriteEntry=Q.onWriteEntry,this.readEntry=$;let{type:X}=$;if(X==="Unsupported")throw Error("writing entry that should be ignored");if(this.type=X,this.type==="Directory"&&this.portable)this.noMtime=!0;if(this.prefix=Q.prefix,this.path=z($.path),this.mode=$.mode!==void 0?this[E0]($.mode):void 0,this.uid=this.portable?void 0:$.uid,this.gid=this.portable?void 0:$.gid,this.uname=this.portable?void 0:$.uname,this.gname=this.portable?void 0:$.gname,this.size=$.size,this.mtime=this.noMtime?void 0:Q.mtime||$.mtime,this.atime=this.portable?void 0:$.atime,this.ctime=this.portable?void 0:$.ctime,this.linkpath=$.linkpath!==void 0?z($.linkpath):void 0,typeof Q.onwarn==="function")this.on("warn",Q.onwarn);let J=!1;if(!this.preservePaths){let[q,K]=H0(this.path);if(q&&typeof K==="string")this.path=K,J=q}if(this.remain=$.size,this.blockRemain=$.startBlockSize,this.onWriteEntry?.(this),this.header=new y({path:this[o](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[o](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}),J)this.warn("TAR_ENTRY_INFO",`stripping ${J} from absolute path`,{entry:this,path:J+this.path});if(this.header.encode()&&!this.noPax)super.write(new v$({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[o](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[o](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());let Z=this.header?.block;if(!Z)throw Error("failed to encode header");super.write(Z),$.pipe(this)}[o]($){return x4($,this.prefix)}[E0]($){return s8($,this.type==="Directory",this.portable)}write($,V,Q){if(typeof V==="function")Q=V,V=void 0;if(typeof $==="string")$=Buffer.from($,typeof V==="string"?V:"utf8");let X=$.length;if(X>this.blockRemain)throw Error("writing more to entry than is appropriate");return this.blockRemain-=X,super.write($,Q)}end($,V,Q){if(this.blockRemain)super.write(Buffer.alloc(this.blockRemain));if(typeof $==="function")Q=$,V=void 0,$=void 0;if(typeof V==="function")Q=V,V=void 0;if(typeof $==="string")$=Buffer.from($,V??"utf8");if(Q)this.once("finish",Q);return $?super.end($,Q):super.end(Q),this}}var V7=($)=>$.isFile()?"File":$.isDirectory()?"Directory":$.isSymbolicLink()?"SymbolicLink":"Unsupported";class P${tail;head;length=0;static create($=[]){return new P$($)}constructor($=[]){for(let V of $)this.push(V)}*[Symbol.iterator](){for(let $=this.head;$;$=$.next)yield $.value}removeNode($){if($.list!==this)throw Error("removing node which does not belong to this list");let{next:V,prev:Q}=$;if(V)V.prev=Q;if(Q)Q.next=V;if($===this.head)this.head=V;if($===this.tail)this.tail=Q;return this.length--,$.next=void 0,$.prev=void 0,$.list=void 0,V}unshiftNode($){if($===this.head)return;if($.list)$.list.removeNode($);let V=this.head;if($.list=this,$.next=V,V)V.prev=$;if(this.head=$,!this.tail)this.tail=$;this.length++}pushNode($){if($===this.tail)return;if($.list)$.list.removeNode($);let V=this.tail;if($.list=this,$.prev=V,V)V.next=$;if(this.tail=$,!this.head)this.head=$;this.length++}push(...$){for(let V=0,Q=$.length;V<Q;V++)X7(this,$[V]);return this.length}unshift(...$){for(var V=0,Q=$.length;V<Q;V++)J7(this,$[V]);return this.length}pop(){if(!this.tail)return;let $=this.tail.value,V=this.tail;if(this.tail=this.tail.prev,this.tail)this.tail.next=void 0;else this.head=void 0;return V.list=void 0,this.length--,$}shift(){if(!this.head)return;let $=this.head.value,V=this.head;if(this.head=this.head.next,this.head)this.head.prev=void 0;else this.tail=void 0;return V.list=void 0,this.length--,$}forEach($,V){V=V||this;for(let Q=this.head,X=0;Q;X++)$.call(V,Q.value,X,this),Q=Q.next}forEachReverse($,V){V=V||this;for(let Q=this.tail,X=this.length-1;Q;X--)$.call(V,Q.value,X,this),Q=Q.prev}get($){let V=0,Q=this.head;for(;!!Q&&V<$;V++)Q=Q.next;if(V===$&&!!Q)return Q.value}getReverse($){let V=0,Q=this.tail;for(;!!Q&&V<$;V++)Q=Q.prev;if(V===$&&!!Q)return Q.value}map($,V){V=V||this;let Q=new P$;for(let X=this.head;X;)Q.push($.call(V,X.value,this)),X=X.next;return Q}mapReverse($,V){V=V||this;var Q=new P$;for(let X=this.tail;X;)Q.push($.call(V,X.value,this)),X=X.prev;return Q}reduce($,V){let Q,X=this.head;if(arguments.length>1)Q=V;else if(this.head)X=this.head.next,Q=this.head.value;else throw TypeError("Reduce of empty list with no initial value");for(var J=0;X;J++)Q=$(Q,X.value,J),X=X.next;return Q}reduceReverse($,V){let Q,X=this.tail;if(arguments.length>1)Q=V;else if(this.tail)X=this.tail.prev,Q=this.tail.value;else throw TypeError("Reduce of empty list with no initial value");for(let J=this.length-1;X;J--)Q=$(Q,X.value,J),X=X.prev;return Q}toArray(){let $=Array(this.length);for(let V=0,Q=this.head;Q;V++)$[V]=Q.value,Q=Q.next;return $}toArrayReverse(){let $=Array(this.length);for(let V=0,Q=this.tail;Q;V++)$[V]=Q.value,Q=Q.prev;return $}slice($=0,V=this.length){if(V<0)V+=this.length;if($<0)$+=this.length;let Q=new P$;if(V<$||V<0)return Q;if($<0)$=0;if(V>this.length)V=this.length;let X=this.head,J=0;for(J=0;!!X&&J<$;J++)X=X.next;for(;!!X&&J<V;J++,X=X.next)Q.push(X.value);return Q}sliceReverse($=0,V=this.length){if(V<0)V+=this.length;if($<0)$+=this.length;let Q=new P$;if(V<$||V<0)return Q;if($<0)$=0;if(V>this.length)V=this.length;let X=this.length,J=this.tail;for(;!!J&&X>V;X--)J=J.prev;for(;!!J&&X>$;X--,J=J.prev)Q.push(J.value);return Q}splice($,V=0,...Q){if($>this.length)$=this.length-1;if($<0)$=this.length+$;let X=this.head;for(let Z=0;!!X&&Z<$;Z++)X=X.next;let J=[];for(let Z=0;!!X&&Z<V;Z++)J.push(X.value),X=this.removeNode(X);if(!X)X=this.tail;else if(X!==this.tail)X=X.prev;for(let Z of Q)X=Q7(this,X,Z);return J}reverse(){let $=this.head,V=this.tail;for(let Q=$;Q;Q=Q.prev){let X=Q.prev;Q.prev=Q.next,Q.next=X}return this.head=V,this.tail=$,this}}function Q7($,V,Q){let X=V,J=V?V.next:$.head,Z=new i0(Q,X,J,$);if(Z.next===void 0)$.tail=Z;if(Z.prev===void 0)$.head=Z;return $.length++,Z}function X7($,V){if($.tail=new i0(V,$.tail,void 0,$),!$.head)$.head=$.tail;$.length++}function J7($,V){if($.head=new i0(V,void 0,$.head,$),!$.tail)$.tail=$.head;$.length++}class i0{list;next;prev;value;constructor($,V,Q,X){if(this.list=X,this.value=$,V)V.next=this,this.prev=V;else this.prev=void 0;if(Q)Q.prev=this,this.next=Q;else this.next=void 0}}import w4 from"path";class H9{path;absolute;entry;stat;readdir;pending=!1;ignore=!1;piped=!1;constructor($,V){this.path=$||"./",this.absolute=V}}var B4=Buffer.alloc(1024),d0=Symbol("onStat"),z0=Symbol("ended"),E=Symbol("queue"),d$=Symbol("current"),D$=Symbol("process"),Y0=Symbol("processing"),L4=Symbol("processJob"),f=Symbol("jobs"),q9=Symbol("jobDone"),p0=Symbol("addFSEntry"),P4=Symbol("addTarEntry"),v9=Symbol("stat"),z9=Symbol("readdir"),s0=Symbol("onreaddir"),a0=Symbol("pipe"),M4=Symbol("entry"),K9=Symbol("entryOpt"),o0=Symbol("writeEntryClass"),C4=Symbol("write"),G9=Symbol("ondrain");class N$ extends D{opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[o0];onWriteEntry;[E];[f]=0;[Y0]=!1;[z0]=!1;constructor($={}){super();if(this.opt=$,this.file=$.file||"",this.cwd=$.cwd||process.cwd(),this.maxReadSize=$.maxReadSize,this.preservePaths=!!$.preservePaths,this.strict=!!$.strict,this.noPax=!!$.noPax,this.prefix=z($.prefix||""),this.linkCache=$.linkCache||new Map,this.statCache=$.statCache||new Map,this.readdirCache=$.readdirCache||new Map,this.onWriteEntry=$.onWriteEntry,this[o0]=f0,typeof $.onwarn==="function")this.on("warn",$.onwarn);if(this.portable=!!$.portable,$.gzip||$.brotli||$.zstd){if(($.gzip?1:0)+($.brotli?1:0)+($.zstd?1:0)>1)throw TypeError("gzip, brotli, zstd are mutually exclusive");if($.gzip){if(typeof $.gzip!=="object")$.gzip={};if(this.portable)$.gzip.portable=!0;this.zip=new m8($.gzip)}if($.brotli){if(typeof $.brotli!=="object")$.brotli={};this.zip=new N8($.brotli)}if($.zstd){if(typeof $.zstd!=="object")$.zstd={};this.zip=new y8($.zstd)}if(!this.zip)throw Error("impossible");let V=this.zip;V.on("data",(Q)=>super.write(Q)),V.on("end",()=>super.end()),V.on("drain",()=>this[G9]()),this.on("resume",()=>V.resume())}else this.on("drain",this[G9]);if(this.noDirRecurse=!!$.noDirRecurse,this.follow=!!$.follow,this.noMtime=!!$.noMtime,$.mtime)this.mtime=$.mtime;this.filter=typeof $.filter==="function"?$.filter:()=>!0,this[E]=new P$,this[f]=0,this.jobs=Number($.jobs)||4,this[Y0]=!1,this[z0]=!1}[C4]($){return super.write($)}add($){return this.write($),this}end($,V,Q){if(typeof $==="function")Q=$,$=void 0;if(typeof V==="function")Q=V,V=void 0;if($)this.add($);if(this[z0]=!0,this[D$](),Q)Q();return this}write($){if(this[z0])throw Error("write after end");if($ instanceof q0)this[P4]($);else this[p0]($);return this.flowing}[P4]($){let V=z(w4.resolve(this.cwd,$.path));if(!this.filter($.path,$))$.resume();else{let Q=new H9($.path,V);Q.entry=new Z9($,this[K9](Q)),Q.entry.on("end",()=>this[q9](Q)),this[f]+=1,this[E].push(Q)}this[D$]()}[p0]($){let V=z(w4.resolve(this.cwd,$));this[E].push(new H9($,V)),this[D$]()}[v9]($){$.pending=!0,this[f]+=1;let V=this.follow?"stat":"lstat";n0[V]($.absolute,(Q,X)=>{if($.pending=!1,this[f]-=1,Q)this.emit("error",Q);else this[d0]($,X)})}[d0]($,V){if(this.statCache.set($.absolute,V),$.stat=V,!this.filter($.path,V))$.ignore=!0;this[D$]()}[z9]($){$.pending=!0,this[f]+=1,n0.readdir($.absolute,(V,Q)=>{if($.pending=!1,this[f]-=1,V)return this.emit("error",V);this[s0]($,Q)})}[s0]($,V){this.readdirCache.set($.absolute,V),$.readdir=V,this[D$]()}[D$](){if(this[Y0])return;this[Y0]=!0;for(let $=this[E].head;!!$&&this[f]<this.jobs;$=$.next)if(this[L4]($.value),$.value.ignore){let V=$.next;this[E].removeNode($),$.next=V}if(this[Y0]=!1,this[z0]&&!this[E].length&&this[f]===0)if(this.zip)this.zip.end(B4);else super.write(B4),super.end()}get[d$](){return this[E]&&this[E].head&&this[E].head.value}[q9]($){this[E].shift(),this[f]-=1,this[D$]()}[L4]($){if($.pending)return;if($.entry){if($===this[d$]&&!$.piped)this[a0]($);return}if(!$.stat){let V=this.statCache.get($.absolute);if(V)this[d0]($,V);else this[v9]($)}if(!$.stat)return;if($.ignore)return;if(!this.noDirRecurse&&$.stat.isDirectory()&&!$.readdir){let V=this.readdirCache.get($.absolute);if(V)this[s0]($,V);else this[z9]($);if(!$.readdir)return}if($.entry=this[M4]($),!$.entry){$.ignore=!0;return}if($===this[d$]&&!$.piped)this[a0]($)}[K9]($){return{onwarn:(V,Q,X)=>this.warn(V,Q,X),noPax:this.noPax,cwd:this.cwd,absolute:$.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}}[M4]($){this[f]+=1;try{return new this[o0]($.path,this[K9]($)).on("end",()=>this[q9]($)).on("error",(Q)=>this.emit("error",Q))}catch(V){this.emit("error",V)}}[G9](){if(this[d$]&&this[d$].entry)this[d$].entry.resume()}[a0]($){if($.piped=!0,$.readdir)$.readdir.forEach((X)=>{let J=$.path,Z=J==="./"?"":J.replace(/\/*$/,"/");this[p0](Z+X)});let V=$.entry,Q=this.zip;if(!V)throw Error("cannot pipe without source");if(Q)V.on("data",(X)=>{if(!Q.write(X))V.pause()});else V.on("data",(X)=>{if(!super.write(X))V.pause()})}pause(){if(this.zip)this.zip.pause();return super.pause()}warn($,V,Q={}){T$(this,$,V,Q)}}class p$ extends N${sync=!0;constructor($){super($);this[o0]=J9}pause(){}resume(){}[v9]($){let V=this.follow?"statSync":"lstatSync";this[d0]($,n0[V]($.absolute))}[z9]($){this[s0]($,n0.readdirSync($.absolute))}[a0]($){let V=$.entry,Q=this.zip;if($.readdir)$.readdir.forEach((X)=>{let J=$.path,Z=J==="./"?"":J.replace(/\/*$/,"/");this[p0](Z+X)});if(!V)throw Error("Cannot pipe without source");if(Q)V.on("data",(X)=>{Q.write(X)});else V.on("data",(X)=>{super[C4](X)})}}var Z7=($,V)=>{let Q=new p$($),X=new X0($.file,{mode:$.mode||438});Q.pipe(X),U4(Q,V)},q7=($,V)=>{let Q=new N$($),X=new K$($.file,{mode:$.mode||438});Q.pipe(X);let J=new Promise((Z,q)=>{X.on("error",q),X.on("close",Z),Q.on("error",q)});return j4(Q,V),J},U4=($,V)=>{V.forEach((Q)=>{if(Q.charAt(0)==="@")S$({file:A4.resolve($.cwd,Q.slice(1)),sync:!0,noResume:!0,onReadEntry:(X)=>$.add(X)});else $.add(Q)}),$.end()},j4=async($,V)=>{for(let Q=0;Q<V.length;Q++){let X=String(V[Q]);if(X.charAt(0)==="@")await S$({file:A4.resolve(String($.cwd),X.slice(1)),noResume:!0,onReadEntry:(J)=>{$.add(J)}});else $.add(X)}$.end()},K7=($,V)=>{let Q=new p$($);return U4(Q,V),Q},G7=($,V)=>{let Q=new N$($);return j4(Q,V),Q},F4=p(Z7,q7,K7,G7,($,V)=>{if(!V?.length)throw TypeError("no paths specified to add to archive")});import c4 from"fs";import I7 from"assert";import{randomBytes as h4}from"crypto";import Y from"fs";import Q$ from"path";import I4 from"fs";var H7=process.env.__FAKE_PLATFORM__||process.platform,v7=H7==="win32",{O_CREAT:z7,O_TRUNC:Y7,O_WRONLY:W7}=I4.constants,_4=Number(process.env.__FAKE_FS_O_FILENAME__)||I4.constants.UV_FS_O_FILEMAP||0,x7=v7&&!!_4,B7=524288,L7=_4|Y7|z7|W7,Y9=!x7?()=>"w":($)=>$<B7?L7:"w";import t0 from"fs";import W0 from"path";var W9=($,V,Q)=>{try{return t0.lchownSync($,V,Q)}catch(X){if(X?.code!=="ENOENT")throw X}},r0=($,V,Q,X)=>{t0.lchown($,V,Q,(J)=>{X(J&&J?.code!=="ENOENT"?J:null)})},P7=($,V,Q,X,J)=>{if(V.isDirectory())x9(W0.resolve($,V.name),Q,X,(Z)=>{if(Z)return J(Z);let q=W0.resolve($,V.name);r0(q,Q,X,J)});else{let Z=W0.resolve($,V.name);r0(Z,Q,X,J)}},x9=($,V,Q,X)=>{t0.readdir($,{withFileTypes:!0},(J,Z)=>{if(J){if(J.code==="ENOENT")return X();else if(J.code!=="ENOTDIR"&&J.code!=="ENOTSUP")return X(J)}if(J||!Z.length)return r0($,V,Q,X);let q=Z.length,K=null,G=(H)=>{if(K)return;if(H)return X(K=H);if(--q===0)return r0($,V,Q,X)};for(let H of Z)P7($,H,V,Q,G)})},M7=($,V,Q,X)=>{if(V.isDirectory())B9(W0.resolve($,V.name),Q,X);W9(W0.resolve($,V.name),Q,X)},B9=($,V,Q)=>{let X;try{X=t0.readdirSync($,{withFileTypes:!0})}catch(J){let Z=J;if(Z?.code==="ENOENT")return;else if(Z?.code==="ENOTDIR"||Z?.code==="ENOTSUP")return W9($,V,Q);else throw Z}for(let J of X)M7($,J,V,Q);return W9($,V,Q)};import N from"fs";import w7 from"fs/promises";import V8 from"path";class e0 extends Error{path;code;syscall="chdir";constructor($,V){super(`${V}: Cannot cd into '${$}'`);this.path=$,this.code=V}get name(){return"CwdError"}}class $8 extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor($,V){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link");this.symlink=$,this.path=V}get name(){return"SymlinkError"}}var C7=($,V)=>{N.stat($,(Q,X)=>{if(Q||!X.isDirectory())Q=new e0($,Q?.code||"ENOTDIR");V(Q)})},T4=($,V,Q)=>{$=z($);let X=V.umask??18,J=V.mode|448,Z=(J&X)!==0,q=V.uid,K=V.gid,G=typeof q==="number"&&typeof K==="number"&&(q!==V.processUid||K!==V.processGid),H=V.preserve,v=V.unlink,W=z(V.cwd),F=(P,j)=>{if(P)Q(P);else if(j&&G)x9(j,q,K,(O9)=>F(O9));else if(Z)N.chmod($,J,Q);else Q()};if($===W)return C7($,F);if(H)return w7.mkdir($,{mode:J,recursive:!0}).then((P)=>F(null,P??void 0),F);let T=z(V8.relative(W,$)).split("/");L9(W,T,J,v,W,void 0,F)},L9=($,V,Q,X,J,Z,q)=>{if(!V.length)return q(null,Z);let K=V.shift(),G=z(V8.resolve($+"/"+K));N.mkdir(G,Q,O4(G,V,Q,X,J,Z,q))},O4=($,V,Q,X,J,Z,q)=>(K)=>{if(K)N.lstat($,(G,H)=>{if(G)G.path=G.path&&z(G.path),q(G);else if(H.isDirectory())L9($,V,Q,X,J,Z,q);else if(X)N.unlink($,(v)=>{if(v)return q(v);N.mkdir($,Q,O4($,V,Q,X,J,Z,q))});else if(H.isSymbolicLink())return q(new $8($,$+"/"+V.join("/")));else q(K)});else Z=Z||$,L9($,V,Q,X,J,Z,q)},A7=($)=>{let V=!1,Q=void 0;try{V=N.statSync($).isDirectory()}catch(X){Q=X?.code}finally{if(!V)throw new e0($,Q??"ENOTDIR")}},g4=($,V)=>{$=z($);let Q=V.umask??18,X=V.mode|448,J=(X&Q)!==0,Z=V.uid,q=V.gid,K=typeof Z==="number"&&typeof q==="number"&&(Z!==V.processUid||q!==V.processGid),G=V.preserve,H=V.unlink,v=z(V.cwd),W=(P)=>{if(P&&K)B9(P,Z,q);if(J)N.chmodSync($,X)};if($===v)return A7(v),W();if(G)return W(N.mkdirSync($,{mode:X,recursive:!0})??void 0);let m=z(V8.relative(v,$)).split("/"),T=void 0;for(let P=m.shift(),j=v;P&&(j+="/"+P);P=m.shift()){j=z(V8.resolve(j));try{N.mkdirSync(j,X),T=T||j}catch(O9){let g9=N.lstatSync(j);if(g9.isDirectory())continue;else if(H){N.unlinkSync(j),N.mkdirSync(j,X),T=T||j;continue}else if(g9.isSymbolicLink())return new $8(j,j+"/"+m.join("/"))}}return W(T)};import{join as S4}from"path";var P9=Object.create(null);var s$=new Set,m4=($)=>{if(!s$.has($))P9[$]=$.normalize("NFD");else s$.delete($);s$.add($);let V=P9[$],Q=s$.size-1e4;if(Q>1000){for(let X of s$)if(s$.delete(X),delete P9[X],--Q<=0)break}return V};var U7=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,j7=U7==="win32",F7=($)=>{return $.split("/").slice(0,-1).reduce((Q,X)=>{let J=Q[Q.length-1];if(J!==void 0)X=S4(J,X);return Q.push(X||"/"),Q},[])};class M9{#$=new Map;#Q=new Map;#X=new Set;reserve($,V){$=j7?["win32 parallelization disabled"]:$.map((X)=>{return B$(S4(m4(X))).toLowerCase()});let Q=new Set($.map((X)=>F7(X)).reduce((X,J)=>X.concat(J)));this.#Q.set(V,{dirs:Q,paths:$});for(let X of $){let J=this.#$.get(X);if(!J)this.#$.set(X,[V]);else J.push(V)}for(let X of Q){let J=this.#$.get(X);if(!J)this.#$.set(X,[new Set([V])]);else{let Z=J[J.length-1];if(Z instanceof Set)Z.add(V);else J.push(new Set([V]))}}return this.#J(V)}#Z($){let V=this.#Q.get($);if(!V)throw Error("function does not have any path reservations");return{paths:V.paths.map((Q)=>this.#$.get(Q)),dirs:[...V.dirs].map((Q)=>this.#$.get(Q))}}check($){let{paths:V,dirs:Q}=this.#Z($);return V.every((X)=>X&&X[0]===$)&&Q.every((X)=>X&&X[0]instanceof Set&&X[0].has($))}#J($){if(this.#X.has($)||!this.check($))return!1;return this.#X.add($),$(()=>this.#V($)),!0}#V($){if(!this.#X.has($))return!1;let V=this.#Q.get($);if(!V)throw Error("invalid reservation");let{paths:Q,dirs:X}=V,J=new Set;for(let Z of Q){let q=this.#$.get(Z);if(!q||q?.[0]!==$)continue;let K=q[1];if(!K){this.#$.delete(Z);continue}if(q.shift(),typeof K==="function")J.add(K);else for(let G of K)J.add(G)}for(let Z of X){let q=this.#$.get(Z),K=q?.[0];if(!q||!(K instanceof Set))continue;if(K.size===1&&q.length===1){this.#$.delete(Z);continue}else if(K.size===1){q.shift();let G=q[0];if(typeof G==="function")J.add(G)}else K.delete($)}return this.#X.delete($),J.forEach((Z)=>this.#J(Z)),!0}}var D4=Symbol("onEntry"),A9=Symbol("checkFs"),N4=Symbol("checkFs2"),U9=Symbol("isReusable"),b=Symbol("makeFs"),j9=Symbol("file"),F9=Symbol("directory"),J8=Symbol("link"),R4=Symbol("symlink"),k4=Symbol("hardlink"),y4=Symbol("unsupported"),l4=Symbol("checkPath"),M$=Symbol("mkdir"),_=Symbol("onError"),Q8=Symbol("pending"),b4=Symbol("pend"),a$=Symbol("unpend"),w9=Symbol("ended"),C9=Symbol("maybeClose"),I9=Symbol("skip"),x0=Symbol("doChown"),B0=Symbol("uid"),L0=Symbol("gid"),P0=Symbol("checkedCwd"),_7=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,M0=_7==="win32",T7=1024,O7=($,V)=>{if(!M0)return Y.unlink($,V);let Q=$+".DELETE."+h4(16).toString("hex");Y.rename($,Q,(X)=>{if(X)return V(X);Y.unlink(Q,V)})},g7=($)=>{if(!M0)return Y.unlinkSync($);let V=$+".DELETE."+h4(16).toString("hex");Y.renameSync($,V),Y.unlinkSync(V)},u4=($,V,Q)=>$!==void 0&&$===$>>>0?$:V!==void 0&&V===V>>>0?V:Q;class w0 extends x${[w9]=!1;[P0]=!1;[Q8]=0;reservations=new M9;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($={}){$.ondone=()=>{this[w9]=!0,this[C9]()};super($);if(this.transform=$.transform,this.chmod=!!$.chmod,typeof $.uid==="number"||typeof $.gid==="number"){if(typeof $.uid!=="number"||typeof $.gid!=="number")throw TypeError("cannot set owner without number uid and gid");if($.preserveOwner)throw TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=$.uid,this.gid=$.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;if($.preserveOwner===void 0&&typeof $.uid!=="number")this.preserveOwner=!!(process.getuid&&process.getuid()===0);else this.preserveOwner=!!$.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=typeof $.maxDepth==="number"?$.maxDepth:T7,this.forceChown=$.forceChown===!0,this.win32=!!$.win32||M0,this.newer=!!$.newer,this.keep=!!$.keep,this.noMtime=!!$.noMtime,this.preservePaths=!!$.preservePaths,this.unlink=!!$.unlink,this.cwd=z(Q$.resolve($.cwd||process.cwd())),this.strip=Number($.strip)||0,this.processUmask=!this.chmod?0:typeof $.processUmask==="number"?$.processUmask:process.umask(),this.umask=typeof $.umask==="number"?$.umask:this.processUmask,this.dmode=$.dmode||511&~this.umask,this.fmode=$.fmode||438&~this.umask,this.on("entry",(V)=>this[D4](V))}warn($,V,Q={}){if($==="TAR_BAD_ARCHIVE"||$==="TAR_ABORT")Q.recoverable=!1;return super.warn($,V,Q)}[C9](){if(this[w9]&&this[Q8]===0)this.emit("prefinish"),this.emit("finish"),this.emit("end")}[l4]($){let V=z($.path),Q=V.split("/");if(this.strip){if(Q.length<this.strip)return!1;if($.type==="Link"){let X=z(String($.linkpath)).split("/");if(X.length>=this.strip)$.linkpath=X.slice(this.strip).join("/");else return!1}Q.splice(0,this.strip),$.path=Q.join("/")}if(isFinite(this.maxDepth)&&Q.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:$,path:V,depth:Q.length,maxDepth:this.maxDepth}),!1;if(!this.preservePaths){if(Q.includes("..")||M0&&/^[a-z]:\.\.$/i.test(Q[0]??""))return this.warn("TAR_ENTRY_ERROR","path contains '..'",{entry:$,path:V}),!1;let[X,J]=H0(V);if(X)$.path=String(J),this.warn("TAR_ENTRY_INFO",`stripping ${X} from absolute path`,{entry:$,path:V})}if(Q$.isAbsolute($.path))$.absolute=z(Q$.resolve($.path));else $.absolute=z(Q$.resolve(this.cwd,$.path));if(!this.preservePaths&&typeof $.absolute==="string"&&$.absolute.indexOf(this.cwd+"/")!==0&&$.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:$,path:z($.path),resolvedPath:$.absolute,cwd:this.cwd}),!1;if($.absolute===this.cwd&&$.type!=="Directory"&&$.type!=="GNUDumpDir")return!1;if(this.win32){let{root:X}=Q$.win32.parse(String($.absolute));$.absolute=X+o8(String($.absolute).slice(X.length));let{root:J}=Q$.win32.parse($.path);$.path=J+o8($.path.slice(J.length))}return!0}[D4]($){if(!this[l4]($))return $.resume();switch(I7.equal(typeof $.absolute,"string"),$.type){case"Directory":case"GNUDumpDir":if($.mode)$.mode=$.mode|448;case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[A9]($);case"CharacterDevice":case"BlockDevice":case"FIFO":default:return this[y4]($)}}[_]($,V){if($.name==="CwdError")this.emit("error",$);else this.warn("TAR_ENTRY_ERROR",$,{entry:V}),this[a$](),V.resume()}[M$]($,V,Q){T4(z($),{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:V},Q)}[x0]($){return this.forceChown||this.preserveOwner&&(typeof $.uid==="number"&&$.uid!==this.processUid||typeof $.gid==="number"&&$.gid!==this.processGid)||typeof this.uid==="number"&&this.uid!==this.processUid||typeof this.gid==="number"&&this.gid!==this.processGid}[B0]($){return u4(this.uid,$.uid,this.processUid)}[L0]($){return u4(this.gid,$.gid,this.processGid)}[j9]($,V){let Q=typeof $.mode==="number"?$.mode&4095:this.fmode,X=new K$(String($.absolute),{flags:Y9($.size),mode:Q,autoClose:!1});X.on("error",(K)=>{if(X.fd)Y.close(X.fd,()=>{});X.write=()=>!0,this[_](K,$),V()});let J=1,Z=(K)=>{if(K){if(X.fd)Y.close(X.fd,()=>{});this[_](K,$),V();return}if(--J===0){if(X.fd!==void 0)Y.close(X.fd,(G)=>{if(G)this[_](G,$);else this[a$]();V()})}};X.on("finish",()=>{let K=String($.absolute),G=X.fd;if(typeof G==="number"&&$.mtime&&!this.noMtime){J++;let H=$.atime||new Date,v=$.mtime;Y.futimes(G,H,v,(W)=>W?Y.utimes(K,H,v,(F)=>Z(F&&W)):Z())}if(typeof G==="number"&&this[x0]($)){J++;let H=this[B0]($),v=this[L0]($);if(typeof H==="number"&&typeof v==="number")Y.fchown(G,H,v,(W)=>W?Y.chown(K,H,v,(F)=>Z(F&&W)):Z())}Z()});let q=this.transform?this.transform($)||$:$;if(q!==$)q.on("error",(K)=>{this[_](K,$),V()}),$.pipe(q);q.pipe(X)}[F9]($,V){let Q=typeof $.mode==="number"?$.mode&4095:this.dmode;this[M$](String($.absolute),Q,(X)=>{if(X){this[_](X,$),V();return}let J=1,Z=()=>{if(--J===0)V(),this[a$](),$.resume()};if($.mtime&&!this.noMtime)J++,Y.utimes(String($.absolute),$.atime||new Date,$.mtime,Z);if(this[x0]($))J++,Y.chown(String($.absolute),Number(this[B0]($)),Number(this[L0]($)),Z);Z()})}[y4]($){$.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${$.type}`,{entry:$}),$.resume()}[R4]($,V){this[J8]($,String($.linkpath),"symlink",V)}[k4]($,V){let Q=z(Q$.resolve(this.cwd,String($.linkpath)));this[J8]($,Q,"link",V)}[b4](){this[Q8]++}[a$](){this[Q8]--,this[C9]()}[I9]($){this[a$](),$.resume()}[U9]($,V){return $.type==="File"&&!this.unlink&&V.isFile()&&V.nlink<=1&&!M0}[A9]($){this[b4]();let V=[$.path];if($.linkpath)V.push($.linkpath);this.reservations.reserve(V,(Q)=>this[N4]($,Q))}[N4]($,V){let Q=(q)=>{V(q)},X=()=>{this[M$](this.cwd,this.dmode,(q)=>{if(q){this[_](q,$),Q();return}this[P0]=!0,J()})},J=()=>{if($.absolute!==this.cwd){let q=z(Q$.dirname(String($.absolute)));if(q!==this.cwd)return this[M$](q,this.dmode,(K)=>{if(K){this[_](K,$),Q();return}Z()})}Z()},Z=()=>{Y.lstat(String($.absolute),(q,K)=>{if(K&&(this.keep||this.newer&&K.mtime>($.mtime??K.mtime))){this[I9]($),Q();return}if(q||this[U9]($,K))return this[b](null,$,Q);if(K.isDirectory()){if($.type==="Directory"){let G=this.chmod&&$.mode&&(K.mode&4095)!==$.mode,H=(v)=>this[b](v??null,$,Q);if(!G)return H();return Y.chmod(String($.absolute),Number($.mode),H)}if($.absolute!==this.cwd)return Y.rmdir(String($.absolute),(G)=>this[b](G??null,$,Q))}if($.absolute===this.cwd)return this[b](null,$,Q);O7(String($.absolute),(G)=>this[b](G??null,$,Q))})};if(this[P0])J();else X()}[b]($,V,Q){if($){this[_]($,V),Q();return}switch(V.type){case"File":case"OldFile":case"ContiguousFile":return this[j9](V,Q);case"Link":return this[k4](V,Q);case"SymbolicLink":return this[R4](V,Q);case"Directory":case"GNUDumpDir":return this[F9](V,Q)}}[J8]($,V,Q,X){Y[Q](V,String($.absolute),(J)=>{if(J)this[_](J,$);else this[a$](),$.resume();X()})}}var X8=($)=>{try{return[null,$()]}catch(V){return[V,null]}};class Z8 extends w0{sync=!0;[b]($,V){return super[b]($,V,()=>{})}[A9]($){if(!this[P0]){let J=this[M$](this.cwd,this.dmode);if(J)return this[_](J,$);this[P0]=!0}if($.absolute!==this.cwd){let J=z(Q$.dirname(String($.absolute)));if(J!==this.cwd){let Z=this[M$](J,this.dmode);if(Z)return this[_](Z,$)}}let[V,Q]=X8(()=>Y.lstatSync(String($.absolute)));if(Q&&(this.keep||this.newer&&Q.mtime>($.mtime??Q.mtime)))return this[I9]($);if(V||this[U9]($,Q))return this[b](null,$);if(Q.isDirectory()){if($.type==="Directory"){let Z=this.chmod&&$.mode&&(Q.mode&4095)!==$.mode,[q]=Z?X8(()=>{Y.chmodSync(String($.absolute),Number($.mode))}):[];return this[b](q,$)}let[J]=X8(()=>Y.rmdirSync(String($.absolute)));this[b](J,$)}let[X]=$.absolute===this.cwd?[]:X8(()=>g7(String($.absolute)));this[b](X,$)}[j9]($,V){let Q=typeof $.mode==="number"?$.mode&4095:this.fmode,X=(q)=>{let K;try{Y.closeSync(J)}catch(G){K=G}if(q||K)this[_](q||K,$);V()},J;try{J=Y.openSync(String($.absolute),Y9($.size),Q)}catch(q){return X(q)}let Z=this.transform?this.transform($)||$:$;if(Z!==$)Z.on("error",(q)=>this[_](q,$)),$.pipe(Z);Z.on("data",(q)=>{try{Y.writeSync(J,q,0,q.length)}catch(K){X(K)}}),Z.on("end",()=>{let q=null;if($.mtime&&!this.noMtime){let K=$.atime||new Date,G=$.mtime;try{Y.futimesSync(J,K,G)}catch(H){try{Y.utimesSync(String($.absolute),K,G)}catch(v){q=H}}}if(this[x0]($)){let K=this[B0]($),G=this[L0]($);try{Y.fchownSync(J,Number(K),Number(G))}catch(H){try{Y.chownSync(String($.absolute),Number(K),Number(G))}catch(v){q=q||H}}}X(q)})}[F9]($,V){let Q=typeof $.mode==="number"?$.mode&4095:this.dmode,X=this[M$](String($.absolute),Q);if(X){this[_](X,$),V();return}if($.mtime&&!this.noMtime)try{Y.utimesSync(String($.absolute),$.atime||new Date,$.mtime)}catch(J){}if(this[x0]($))try{Y.chownSync(String($.absolute),Number(this[B0]($)),Number(this[L0]($)))}catch(J){}V(),$.resume()}[M$]($,V){try{return g4(z($),{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:V})}catch(Q){return Q}}[J8]($,V,Q,X){let J=`${Q}Sync`;try{Y[J](V,String($.absolute)),X(),$.resume()}catch(Z){return this[_](Z,$)}}}var m7=($)=>{let V=new Z8($),Q=$.file,X=c4.statSync(Q),J=$.maxReadSize||16777216;new F8(Q,{readSize:J,size:X.size}).pipe(V)},S7=($,V)=>{let Q=new w0($),X=$.maxReadSize||16777216,J=$.file;return new Promise((q,K)=>{Q.on("error",K),Q.on("close",q),c4.stat(J,(G,H)=>{if(G)K(G);else{let v=new c$(J,{readSize:X,size:H.size});v.on("error",K),v.pipe(Q)}})})},_9=p(m7,S7,($)=>new Z8($),($)=>new w0($),($,V)=>{if(V?.length)p8($,V)});import R from"fs";import E4 from"path";var D7=($,V)=>{let Q=new p$($),X=!0,J,Z;try{try{J=R.openSync($.file,"r+")}catch(G){if(G?.code==="ENOENT")J=R.openSync($.file,"w+");else throw G}let q=R.fstatSync(J),K=Buffer.alloc(512);$:for(Z=0;Z<q.size;Z+=512){for(let v=0,W=0;v<512;v+=W){if(W=R.readSync(J,K,v,K.length-v,Z+v),Z===0&&K[0]===31&&K[1]===139)throw Error("cannot append to compressed archives");if(!W)break $}let G=new y(K);if(!G.cksumValid)break;let H=512*Math.ceil((G.size||0)/512);if(Z+H+512>q.size)break;if(Z+=H,$.mtimeCache&&G.mtime)$.mtimeCache.set(String(G.path),G.mtime)}X=!1,N7($,Q,Z,J,V)}finally{if(X)try{R.closeSync(J)}catch(q){}}},N7=($,V,Q,X,J)=>{let Z=new X0($.file,{fd:X,start:Q});V.pipe(Z),k7(V,J)},R7=($,V)=>{V=Array.from(V);let Q=new N$($),X=(Z,q,K)=>{let G=(m,T)=>{if(m)R.close(Z,(P)=>K(m));else K(null,T)},H=0;if(q===0)return G(null,0);let v=0,W=Buffer.alloc(512),F=(m,T)=>{if(m||typeof T>"u")return G(m);if(v+=T,v<512&&T)return R.read(Z,W,v,W.length-v,H+v,F);if(H===0&&W[0]===31&&W[1]===139)return G(Error("cannot append to compressed archives"));if(v<512)return G(null,H);let P=new y(W);if(!P.cksumValid)return G(null,H);let j=512*Math.ceil((P.size??0)/512);if(H+j+512>q)return G(null,H);if(H+=j+512,H>=q)return G(null,H);if($.mtimeCache&&P.mtime)$.mtimeCache.set(String(P.path),P.mtime);v=0,R.read(Z,W,0,512,H,F)};R.read(Z,W,0,512,H,F)};return new Promise((Z,q)=>{Q.on("error",q);let K="r+",G=(H,v)=>{if(H&&H.code==="ENOENT"&&K==="r+")return K="w+",R.open($.file,K,G);if(H||!v)return q(H);R.fstat(v,(W,F)=>{if(W)return R.close(v,()=>q(W));X(v,F.size,(m,T)=>{if(m)return q(m);let P=new K$($.file,{fd:v,start:T});Q.pipe(P),P.on("error",q),P.on("close",Z),y7(Q,V)})})};R.open($.file,K,G)})},k7=($,V)=>{V.forEach((Q)=>{if(Q.charAt(0)==="@")S$({file:E4.resolve($.cwd,Q.slice(1)),sync:!0,noResume:!0,onReadEntry:(X)=>$.add(X)});else $.add(Q)}),$.end()},y7=async($,V)=>{for(let Q=0;Q<V.length;Q++){let X=String(V[Q]);if(X.charAt(0)==="@")await S$({file:E4.resolve(String($.cwd),X.slice(1)),noResume:!0,onReadEntry:(J)=>$.add(J)});else $.add(X)}$.end()},R$=p(D7,R7,()=>{throw TypeError("file is required")},()=>{throw TypeError("file is required")},($,V)=>{if(!p9($))throw TypeError("file is required");if($.gzip||$.brotli||$.zstd||$.file.endsWith(".br")||$.file.endsWith(".tbr"))throw TypeError("cannot append to compressed archives");if(!V?.length)throw TypeError("no paths specified to add/replace")});var l7=p(R$.syncFile,R$.asyncFile,R$.syncNoFile,R$.asyncNoFile,($,V=[])=>{R$.validate?.($,V),b7($)}),b7=($)=>{let V=$.filter;if(!$.mtimeCache)$.mtimeCache=new Map;$.filter=V?(Q,X)=>V(Q,X)&&!(($.mtimeCache?.get(Q)??X.mtime??0)>(X.mtime??0)):(Q,X)=>!(($.mtimeCache?.get(Q)??X.mtime??0)>(X.mtime??0))};function T9($,V){w$(A0(V)),_9({file:$,cwd:V,sync:!0})}function f4($){return/^[a-z0-9][a-z0-9-]*$/.test($)}function i4($){return/^[a-z0-9]+(-[a-z0-9]+)*$/.test($)}function d4($){return/^\d+\.\d+\.\d+$/.test($)}function p4($){if(!$)return!1;if(typeof $!=="object")return!1;if(!f4($.namespace))return console.error("Invalid namespace:",$.namespace),!1;if(!i4($.tag))return console.error("Invalid tag:",$.tag),!1;if(!d4($.version))return console.error("Invalid version:",$.version),!1;if(typeof $.htmlFile!=="string"||$.htmlFile.trim()==="")return console.error("Invalid htmlFile:",$.htmlFile),!1;if(typeof $.cssFile!=="string"||$.cssFile.trim()==="")return console.error("Invalid cssFile:",$.cssFile),!1;if(typeof $.jsFile!=="string"||$.jsFile.trim()==="")return console.error("Invalid jsFile:",$.jsFile),!1;if(typeof $.previewFile!=="string"||$.previewFile.trim()==="")return console.error("Invalid previewFile:",$.previewFile),!1;return!0}class B{static cwd="";static components="";static port=8080;static initialize(){B.cwd=process.cwd(),B.components=process.env.DATA_PATH||q8(B.cwd,"data","repository","components"),B.port=process.env.API_PORT?parseInt(process.env.API_PORT,10):8080,console.log("Config initialized:"),console.log(`- cwd: ${B.cwd}`),console.log(`- components: ${B.components}`),console.log(`- port: ${B.port}`)}}async function s4($){let V=$.path.replace("/component/","");if(!await o$(`${B.components}/${V}`))return new Response("File not found",{status:404});return new Response(S9(`${B.components}/${V}`))}async function a4($){let V=await $.body.bytes();if(!V)return new Response("No body provided",{status:400});let Q=crypto.randomUUID();if(await D9(`${B.cwd}/tmp/${Q}/archive.tar.gz`,V),w$(`${B.cwd}/tmp/${Q}/extracted/`),T9(`${B.cwd}/tmp/${Q}/archive.tar.gz`,`${B.cwd}/tmp/${Q}/extracted/`),!await o$(`${B.cwd}/tmp/${Q}/extracted/manifest.json`))return new Response("No manifest.json found in archive",{status:400});let X=await N9(`${B.cwd}/tmp/${Q}/extracted/manifest.json`);if(!p4(X))return new Response("Invalid manifest.json",{status:400});if(await o$(`${B.components}/${X.namespace}/${X.tag}/${X.version}/`))return new Response("Component version already exists",{status:409});return K8(`${B.cwd}/tmp/${Q}/extracted/`,`${B.components}/${X.namespace}/${X.tag}/${X.version}/`),k9(`${B.cwd}/tmp/${Q}/archive.tar.gz`,`${B.components}/${X.namespace}/${X.tag}/${X.version}/archive.tar.gz`),G8(`${B.cwd}/tmp/${Q}/`),new Response}function o4(){B.initialize();let $=new H8({port:B.port});$.post("/component",a4),$.get("/component/**",s4),$.start()}o4();
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@befive/wc-repository",
3
+ "version": "1.0.0",
4
+ "description": "Repository for web components",
5
+ "author": "Matthias Bernouy",
6
+ "license": "MIT",
7
+ "bin": {
8
+ "wc-repository": "./bin.js"
9
+ },
10
+ "files": [
11
+ "bin.js",
12
+ "package.json",
13
+ "README.md"
14
+ ]
15
+ }