just-bash 2.14.0 → 2.14.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.
@@ -1,4 +1,4 @@
1
- import{B as Xr,C as Yr,D as fe,E as Xe,F as se,G as Ae,H as Ut,I as Qr,J as L,K as Jr,L as en,M as Ce,N as Rs,O as Ht,P as H,a as Br,b as Cs,c as jr,d as Bt,e as ee,f as B,g as ue,h as ne,i as _e,j as je,k as Ns,l as jt,m as Ur,n as Os,o as Hr,p as ve,q as Re,r as Zr,s as qr,t as xs,u as Ts,v as Ue,w as Gr,x as Kr,y as Se,z as Ds}from"./chunks/chunk-FEIOJCZD.js";import{a as x,b as R,c as rt,d as Be,e as Ke,f as nt,g as De,h as Mt,i as Wt,j as zt,k as Vr,l as Vt}from"./chunks/chunk-XHM67O4N.js";import{c as _s}from"./chunks/chunk-CWQS3NFK.js";import{a as Tt,b as Dt}from"./chunks/chunk-A5O5YHGN.js";import{a as ks}from"./chunks/chunk-IPJHKYVM.js";import{a as Ve,b as we,c as Et}from"./chunks/chunk-OJDRYQWQ.js";import{a as bt,b as zr}from"./chunks/chunk-24IMIIXA.js";import{a as Me,b as pe}from"./chunks/chunk-5QMZ5MUS.js";import{a as vt}from"./chunks/chunk-YNYSPYQ5.js";import{a as me,b as ye,c as ce,d as ge,e as Mr,f as j,g as Ge,h as Rt,i as It,j as Wr,k as J,l as Lt,m as We,n as Ft,o as $e}from"./chunks/chunk-GFQRA5P5.js";import"./chunks/chunk-NUFRM6SI.js";import{a as ze}from"./chunks/chunk-3THT3N7L.js";import{a as Te}from"./chunks/chunk-44UOCSGV.js";import"./chunks/chunk-DXB73IDG.js";var Ye=[{name:"echo",load:async()=>(await import("./chunks/echo-O45JWWI2.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-RDUMLXKC.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-CX64KX2P.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-KSXFZCWH.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-TDEMSB6C.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-XTQXT7RK.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DX2IJOQ4.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-RTZG23RL.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-XOYR4ABJ.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-Z6MORUFL.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-4TRFBYAT.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-SYMGL4JA.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-D4OZ7N27.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-MI4GCHJF.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-HT2B6D2J.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-S5ULNTJU.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-TQB3VNOX.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-BT5A227F.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-FOQSCCX3.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-VFTTATXJ.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-POPGKRAI.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-DCNRDA7U.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-SUNANL47.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-5SLSESQG.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-OPC3VAGB.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-7N6AFSDS.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-2HXZRDSW.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-XOSYPP45.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-U5YJDM32.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-LDSORVYE.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-DTNXU4LQ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-RGTMIGZM.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-7PLOGTPD.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-SITCSYCZ.js")).split},{name:"column",load:async()=>(await import("./chunks/column-WLPMMSTS.js")).column},{name:"join",load:async()=>(await import("./chunks/join-GG2LDHE5.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-O7VXZDCO.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-TPUOAIUQ.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-AA2KJYZQ.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-LEMTZZFS.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-LYXBS7DC.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-WO2ENHXQ.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-5EPCWSXR.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-5EPCWSXR.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-JE7RI5QX.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-JE7RI5QX.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-J4QRNGRO.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-I6EZUCYF.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-WHJNXCHG.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-WHJNXCHG.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-5CZ5X4YR.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-IJWYRKFO.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-IJWYRKFO.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-ODXZBPLY.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-4YMZCVJ5.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-HJF2MPDN.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-DD7FVA2V.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-VZFPZFWA.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-VRKMCG72.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-DEUO3QV2.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-RN5ZUASB.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-5T3UU5KE.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-INMIK4DX.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-VJPNLNU6.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-PI32XWXY.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-ZIGAJ4YS.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-TFCECAGV.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-VVWX7SA5.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-XZHEH76L.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-SJGXQ4T2.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-BK6HG2DE.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-DGKU3D2X.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-VJEF2UR5.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ye.push({name:"tar",load:async()=>(await import("./chunks/tar-232RCEFK.js")).tarCommand}),Ye.push({name:"yq",load:async()=>(await import("./chunks/yq-MJMAR36V.js")).yqCommand}),Ye.push({name:"xan",load:async()=>(await import("./chunks/xan-BXDXYEIB.js")).xanCommand}),Ye.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-56UMWEY3.js")).sqlite3Command}));var Zt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Zt.push({name:"python3",load:async()=>(await import("./chunks/python3-SG3DOKBZ.js")).python3Command}),Zt.push({name:"python",load:async()=>(await import("./chunks/python3-SG3DOKBZ.js")).pythonCommand}));var qt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(qt.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-4CW5N6RM.js")).jsExecCommand}),qt.push({name:"node",load:async()=>(await import("./chunks/js-exec-4CW5N6RM.js")).nodeStubCommand}));var sn=[{name:"curl",load:async()=>(await import("./chunks/curl-COE4TZE6.js")).curlCommand}],tn=new Map;function Gt(e){return{name:e.name,async execute(t,s){let r=tn.get(e.name);if(r||(r=await pe.runTrustedAsync(()=>e.load()),tn.set(e.name,r)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:n}=await import("./chunks/flag-coverage-LMTH7T5F.js");n(s.coverage,e.name,t)}return r.execute(t,s)}}}function qi(){return Ye.map(e=>e.name)}function Gi(){return sn.map(e=>e.name)}function rn(e){return(e?Ye.filter(s=>e.includes(s.name)):Ye).map(Gt)}function nn(){return sn.map(Gt)}function Ki(){return Zt.map(e=>e.name)}function on(){return Zt.map(Gt)}function Xi(){return qt.map(e=>e.name)}function an(){return qt.map(Gt)}function ln(e){return"load"in e&&typeof e.load=="function"}function Yi(e,t){return{name:e,trusted:!0,execute:t}}function cn(e){let t=null;return{name:e.name,trusted:!0,async execute(s,r){return t||(t=await e.load()),t.execute(s,r)}}}var Qi=new TextEncoder,Ji=new TextDecoder;function Ie(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let r=0;r<e.length;r+=2)s[r/2]=parseInt(e.slice(r,r+2),16);return s}if(t==="binary"||t==="latin1"){if(e.length<=65536)return Uint8Array.from(e,n=>n.charCodeAt(0));let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}return Qi.encode(e)}function it(e,t){if(t==="base64"){if(typeof Buffer<"u")return Buffer.from(e).toString("base64");let s=65536,r="";for(let n=0;n<e.length;n+=s){let i=e.subarray(n,n+s);r+=String.fromCharCode(...i)}return btoa(r)}if(t==="hex")return Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join("");if(t==="binary"||t==="latin1"){if(typeof Buffer<"u")return Buffer.from(e).toString(t);let s=65536;if(e.length<=s)return String.fromCharCode(...e);let r="";for(let n=0;n<e.length;n+=s){let i=e.subarray(n,n+s);r+=String.fromCharCode(...i)}return r}return Ji.decode(e)}function be(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var ot=new TextEncoder;function eo(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Le=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,r]of Object.entries(t))typeof r=="function"?this.writeFileLazy(s,r):eo(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}ensureParentDirs(t){let s=rt(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,r,n){R(t,"write");let i=x(t);this.ensureParentDirs(i);let o=be(r),a=Ie(s,o);this.data.set(i,{type:"file",content:a,mode:n?.mode??420,mtime:n?.mtime??new Date})}writeFileLazy(t,s,r){R(t,"write");let n=x(t);this.ensureParentDirs(n),this.data.set(n,{type:"file",lazy:s,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,s){let r=await s.lazy(),i={type:"file",content:typeof r=="string"?ot.encode(r):r,mode:s.mode,mtime:s.mtime};return this.data.set(t,i),i}async readFile(t,s){let r=await this.readFileBuffer(t),n=be(s);return it(r,n)}async readFileBuffer(t){R(t,"open");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let n=await this.materializeLazy(s,r);return n.content instanceof Uint8Array?n.content:ot.encode(n.content)}return r.content instanceof Uint8Array?r.content:ot.encode(r.content)}async writeFile(t,s,r){this.writeFileSync(t,s,r)}async appendFile(t,s,r){R(t,"append");let n=x(t),i=this.data.get(n);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=be(r),a=Ie(s,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(n,l));let c="content"in l&&l.content instanceof Uint8Array?l.content:ot.encode("content"in l?l.content:""),u=new Uint8Array(c.length+a.length);u.set(c),u.set(a,c.length),this.data.set(n,{type:"file",content:u,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,s,r)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){R(t,"stat");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=ot.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(t){R(t,"lstat");let s=this.resolveIntermediateSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=ot.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveIntermediateSymlinks(t){let s=x(t);if(s==="/")return"/";let r=s.slice(1).split("/");if(r.length<=1)return s;let n="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];n=`${n}/${a}`;let l=this.data.get(n),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(n),n=nt(n,l.target),l=this.data.get(n),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${n}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let s=x(t);if(s==="/")return"/";let r=s.slice(1).split("/"),n="",i=new Set;for(let o of r){n=`${n}/${o}`;let a=this.data.get(n),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(n),n=nt(n,a.target),a=this.data.get(n),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return n}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){R(t,"mkdir");let r=x(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let n=rt(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){R(t,"scandir");let s=x(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Set;for(;r&&r.type==="symlink";){if(n.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(s),s=nt(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,s){R(t,"rm");let r=x(t),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(n.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=Ke(r,o);await this.rm(a,s)}}}this.data.delete(r)}async cp(t,s,r){R(t,"cp"),R(s,"cp");let n=x(t),i=x(s),o=this.data.get(n);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")if(this.ensureParentDirs(i),"content"in o){let a=o.content instanceof Uint8Array?new Uint8Array(o.content):o.content;this.data.set(i,{...o,content:a})}else this.data.set(i,{...o});else if(o.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(n);for(let l of a){let c=Ke(n,l),u=Ke(i,l);await this.cp(c,u,r)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){return Be(t,s)}async chmod(t,s){R(t,"chmod");let r=x(t),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);n.mode=s}async symlink(t,s){R(s,"symlink");let r=x(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){R(t,"link"),R(s,"link");let r=x(t),n=x(s),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let o=i;"lazy"in o&&(o=await this.materializeLazy(r,o)),this.ensureParentDirs(n),this.data.set(n,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(t){R(t,"readlink");let s=x(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){R(t,"realpath");let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,r){R(t,"utimes");let n=x(t),i=this.resolvePathWithSymlinks(n),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=r}};function to(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function so(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function ro(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function no(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Br}
1
+ import{B as Xr,C as Yr,D as fe,E as Xe,F as se,G as Ae,H as Ut,I as Qr,J as L,K as Jr,L as en,M as Ce,N as Rs,O as Ht,P as H,a as Br,b as Cs,c as jr,d as Bt,e as ee,f as B,g as ue,h as ne,i as _e,j as je,k as Ns,l as jt,m as Ur,n as Os,o as Hr,p as ve,q as Re,r as Zr,s as qr,t as xs,u as Ts,v as Ue,w as Gr,x as Kr,y as Se,z as Ds}from"./chunks/chunk-FEIOJCZD.js";import{a as x,b as R,c as rt,d as Be,e as Ke,f as nt,g as De,h as Mt,i as Wt,j as zt,k as Vr,l as Vt}from"./chunks/chunk-XHM67O4N.js";import{c as _s}from"./chunks/chunk-CWQS3NFK.js";import{a as Tt,b as Dt}from"./chunks/chunk-A5O5YHGN.js";import{a as ks}from"./chunks/chunk-IPJHKYVM.js";import{a as Ve,b as we,c as Et}from"./chunks/chunk-OJDRYQWQ.js";import{a as bt,b as zr}from"./chunks/chunk-24IMIIXA.js";import{a as Me,b as pe}from"./chunks/chunk-5QMZ5MUS.js";import{a as vt}from"./chunks/chunk-YNYSPYQ5.js";import{a as me,b as ye,c as ce,d as ge,e as Mr,f as j,g as Ge,h as Rt,i as It,j as Wr,k as J,l as Lt,m as We,n as Ft,o as $e}from"./chunks/chunk-GFQRA5P5.js";import"./chunks/chunk-NUFRM6SI.js";import{a as ze}from"./chunks/chunk-3THT3N7L.js";import{a as Te}from"./chunks/chunk-44UOCSGV.js";import"./chunks/chunk-DXB73IDG.js";var Ye=[{name:"echo",load:async()=>(await import("./chunks/echo-O45JWWI2.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-RDUMLXKC.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-CX64KX2P.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-KSXFZCWH.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-TDEMSB6C.js")).mkdirCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-XTQXT7RK.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-DX2IJOQ4.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-RTZG23RL.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-XOYR4ABJ.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-Z6MORUFL.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-4TRFBYAT.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-SYMGL4JA.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-D4OZ7N27.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-MI4GCHJF.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-HT2B6D2J.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-S5ULNTJU.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-TQB3VNOX.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-BT5A227F.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-3AIAIJVR.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-FOQSCCX3.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-VFTTATXJ.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-POPGKRAI.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-DCNRDA7U.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-SUNANL47.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-5SLSESQG.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-OPC3VAGB.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-7N6AFSDS.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-2HXZRDSW.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-XOSYPP45.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-U5YJDM32.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-LDSORVYE.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-DTNXU4LQ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-RGTMIGZM.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-7PLOGTPD.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-SITCSYCZ.js")).split},{name:"column",load:async()=>(await import("./chunks/column-WLPMMSTS.js")).column},{name:"join",load:async()=>(await import("./chunks/join-GG2LDHE5.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-O7VXZDCO.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-TPUOAIUQ.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-AA2KJYZQ.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-LEMTZZFS.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-LYXBS7DC.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-WO2ENHXQ.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-5EPCWSXR.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-5EPCWSXR.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-JE7RI5QX.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-JE7RI5QX.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-J4QRNGRO.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-I6EZUCYF.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-WHJNXCHG.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-WHJNXCHG.js")).falseCommand},{name:"clear",load:async()=>(await import("./chunks/clear-5CZ5X4YR.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-IJWYRKFO.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-IJWYRKFO.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-ODXZBPLY.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-4YMZCVJ5.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-HJF2MPDN.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-DD7FVA2V.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-VZFPZFWA.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-VRKMCG72.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-DEUO3QV2.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-RN5ZUASB.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-5T3UU5KE.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-INMIK4DX.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-VJPNLNU6.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-PI32XWXY.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-ZIGAJ4YS.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-TFCECAGV.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-VVWX7SA5.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-XZHEH76L.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-SJGXQ4T2.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-BK6HG2DE.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-DGKU3D2X.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-VJEF2UR5.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-AQXSGOVS.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Ye.push({name:"tar",load:async()=>(await import("./chunks/tar-ANUBEFJY.js")).tarCommand}),Ye.push({name:"yq",load:async()=>(await import("./chunks/yq-MJMAR36V.js")).yqCommand}),Ye.push({name:"xan",load:async()=>(await import("./chunks/xan-BXDXYEIB.js")).xanCommand}),Ye.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-56UMWEY3.js")).sqlite3Command}));var Zt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Zt.push({name:"python3",load:async()=>(await import("./chunks/python3-SG3DOKBZ.js")).python3Command}),Zt.push({name:"python",load:async()=>(await import("./chunks/python3-SG3DOKBZ.js")).pythonCommand}));var qt=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(qt.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-4CW5N6RM.js")).jsExecCommand}),qt.push({name:"node",load:async()=>(await import("./chunks/js-exec-4CW5N6RM.js")).nodeStubCommand}));var sn=[{name:"curl",load:async()=>(await import("./chunks/curl-COE4TZE6.js")).curlCommand}],tn=new Map;function Gt(e){return{name:e.name,async execute(t,s){let r=tn.get(e.name);if(r||(r=await pe.runTrustedAsync(()=>e.load()),tn.set(e.name,r)),s.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:n}=await import("./chunks/flag-coverage-QT4N2Z44.js");n(s.coverage,e.name,t)}return r.execute(t,s)}}}function qi(){return Ye.map(e=>e.name)}function Gi(){return sn.map(e=>e.name)}function rn(e){return(e?Ye.filter(s=>e.includes(s.name)):Ye).map(Gt)}function nn(){return sn.map(Gt)}function Ki(){return Zt.map(e=>e.name)}function on(){return Zt.map(Gt)}function Xi(){return qt.map(e=>e.name)}function an(){return qt.map(Gt)}function ln(e){return"load"in e&&typeof e.load=="function"}function Yi(e,t){return{name:e,trusted:!0,execute:t}}function cn(e){let t=null;return{name:e.name,trusted:!0,async execute(s,r){return t||(t=await e.load()),t.execute(s,r)}}}var Qi=new TextEncoder,Ji=new TextDecoder;function Ie(e,t){if(e instanceof Uint8Array)return e;if(t==="base64")return Uint8Array.from(atob(e),s=>s.charCodeAt(0));if(t==="hex"){let s=new Uint8Array(e.length/2);for(let r=0;r<e.length;r+=2)s[r/2]=parseInt(e.slice(r,r+2),16);return s}if(t==="binary"||t==="latin1"){if(e.length<=65536)return Uint8Array.from(e,n=>n.charCodeAt(0));let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e.charCodeAt(n);return r}return Qi.encode(e)}function it(e,t){if(t==="base64"){if(typeof Buffer<"u")return Buffer.from(e).toString("base64");let s=65536,r="";for(let n=0;n<e.length;n+=s){let i=e.subarray(n,n+s);r+=String.fromCharCode(...i)}return btoa(r)}if(t==="hex")return Array.from(e).map(s=>s.toString(16).padStart(2,"0")).join("");if(t==="binary"||t==="latin1"){if(typeof Buffer<"u")return Buffer.from(e).toString(t);let s=65536;if(e.length<=s)return String.fromCharCode(...e);let r="";for(let n=0;n<e.length;n+=s){let i=e.subarray(n,n+s);r+=String.fromCharCode(...i)}return r}return Ji.decode(e)}function be(e){if(e!=null)return typeof e=="string"?e:e.encoding??void 0}var ot=new TextEncoder;function eo(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var Le=class{data=new Map;constructor(t){if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[s,r]of Object.entries(t))typeof r=="function"?this.writeFileLazy(s,r):eo(r)?this.writeFileSync(s,r.content,void 0,{mode:r.mode,mtime:r.mtime}):this.writeFileSync(s,r)}ensureParentDirs(t){let s=rt(t);s!=="/"&&(this.data.has(s)||(this.ensureParentDirs(s),this.data.set(s,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,s,r,n){R(t,"write");let i=x(t);this.ensureParentDirs(i);let o=be(r),a=Ie(s,o);this.data.set(i,{type:"file",content:a,mode:n?.mode??420,mtime:n?.mtime??new Date})}writeFileLazy(t,s,r){R(t,"write");let n=x(t);this.ensureParentDirs(n),this.data.set(n,{type:"file",lazy:s,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,s){let r=await s.lazy(),i={type:"file",content:typeof r=="string"?ot.encode(r):r,mode:s.mode,mtime:s.mtime};return this.data.set(t,i),i}async readFile(t,s){let r=await this.readFileBuffer(t),n=be(s);return it(r,n)}async readFileBuffer(t){R(t,"open");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let n=await this.materializeLazy(s,r);return n.content instanceof Uint8Array?n.content:ot.encode(n.content)}return r.content instanceof Uint8Array?r.content:ot.encode(r.content)}async writeFile(t,s,r){this.writeFileSync(t,s,r)}async appendFile(t,s,r){R(t,"append");let n=x(t),i=this.data.get(n);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=be(r),a=Ie(s,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(n,l));let c="content"in l&&l.content instanceof Uint8Array?l.content:ot.encode("content"in l?l.content:""),u=new Uint8Array(c.length+a.length);u.set(c),u.set(a,c.length),this.data.set(n,{type:"file",content:u,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,s,r)}async exists(t){if(t.includes("\0"))return!1;try{let s=this.resolvePathWithSymlinks(t);return this.data.has(s)}catch{return!1}}async stat(t){R(t,"stat");let s=this.resolvePathWithSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=ot.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}async lstat(t){R(t,"lstat");let s=this.resolveIntermediateSymlinks(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(s,r));let n=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?n=r.content.length:n=ot.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:n,mtime:r.mtime||new Date}}resolveIntermediateSymlinks(t){let s=x(t);if(s==="/")return"/";let r=s.slice(1).split("/");if(r.length<=1)return s;let n="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];n=`${n}/${a}`;let l=this.data.get(n),c=0,u=40;for(;l&&l.type==="symlink"&&c<u;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(n),n=nt(n,l.target),l=this.data.get(n),c++}if(c>=u)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${n}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let s=x(t);if(s==="/")return"/";let r=s.slice(1).split("/"),n="",i=new Set;for(let o of r){n=`${n}/${o}`;let a=this.data.get(n),l=0,c=40;for(;a&&a.type==="symlink"&&l<c;){if(i.has(n))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(n),n=nt(n,a.target),a=this.data.get(n),l++}if(l>=c)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return n}async mkdir(t,s){this.mkdirSync(t,s)}mkdirSync(t,s){R(t,"mkdir");let r=x(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!s?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let n=rt(r);if(n!=="/"&&!this.data.has(n))if(s?.recursive)this.mkdirSync(n,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){R(t,"scandir");let s=x(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let n=new Set;for(;r&&r.type==="symlink";){if(n.has(s))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);n.add(s),s=nt(s,r.target),r=this.data.get(s)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=s==="/"?"/":`${s}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==s&&a.startsWith(i)){let c=a.slice(i.length),u=c.split("/")[0];u&&!c.includes("/",u.length)&&!o.has(u)&&o.set(u,{name:u,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,s){R(t,"rm");let r=x(t),n=this.data.get(r);if(!n){if(s?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(n.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!s?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=Ke(r,o);await this.rm(a,s)}}}this.data.delete(r)}async cp(t,s,r){R(t,"cp"),R(s,"cp");let n=x(t),i=x(s),o=this.data.get(n);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")if(this.ensureParentDirs(i),"content"in o){let a=o.content instanceof Uint8Array?new Uint8Array(o.content):o.content;this.data.set(i,{...o,content:a})}else this.data.set(i,{...o});else if(o.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(n);for(let l of a){let c=Ke(n,l),u=Ke(i,l);await this.cp(c,u,r)}}}async mv(t,s){await this.cp(t,s,{recursive:!0}),await this.rm(t,{recursive:!0})}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,s){return Be(t,s)}async chmod(t,s){R(t,"chmod");let r=x(t),n=this.data.get(r);if(!n)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);n.mode=s}async symlink(t,s){R(s,"symlink");let r=x(s);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${s}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,s){R(t,"link"),R(s,"link");let r=x(t),n=x(s),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(n))throw new Error(`EEXIST: file already exists, link '${s}'`);let o=i;"lazy"in o&&(o=await this.materializeLazy(r,o)),this.ensureParentDirs(n),this.data.set(n,{type:"file",content:o.content,mode:o.mode,mtime:o.mtime})}async readlink(t){R(t,"readlink");let s=x(t),r=this.data.get(s);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){R(t,"realpath");let s=this.resolvePathWithSymlinks(t);if(!this.data.has(s))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return s}async utimes(t,s,r){R(t,"utimes");let n=x(t),i=this.resolvePathWithSymlinks(n),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=r}};function to(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function so(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function ro(e){e.mkdirSync("/dev",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function no(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Br}
2
2
  `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
3
3
  `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>Cs(t)):e.writeFileSync("/proc/self/status",Cs(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function un(e,t,s={pid:1,ppid:0,uid:1e3,gid:1e3}){to(e)&&(so(e,t),ro(e),no(e,s))}var io=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],oo=["braceexpand","hashall","interactive-comments"];function Ls(e){let t=[],s=[...oo.map(r=>({name:r,enabled:!0})),...io.map(r=>({name:r,enabled:e[r]}))].sort((r,n)=>r.name.localeCompare(n.name));for(let r of s)r.enabled&&t.push(r.name);return t.join(":")}function lt(e){e.state.env.set("SHELLOPTS",Ls(e.state.options))}var ao=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Fs(e){let t=[];for(let s of ao)e[s]&&t.push(s);return t.join(":")}function Ms(e){e.state.env.set("BASHOPTS",Fs(e.state.shoptOptions))}var lo="BASH_ALIAS_";function fn(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function dn(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function hn(e,t){return e.env.get(`${lo}${t}`)}function Ws(e,t,s){if(!t.name||!fn(t.name))return t;let r=dn(t.name);if(!r)return t;let n=hn(e,r);if(!n||s.has(r))return t;try{s.add(r);let i=new B,o=n,a=n.endsWith(" ");if(!a)for(let f of t.args){let d=mn(f);o+=` ${d}`}let l;try{l=i.parse(o)}catch(f){if(f instanceof Bt)throw f;return t}if(l.statements.length!==1||l.statements[0].pipelines.length!==1||l.statements[0].pipelines[0].commands.length!==1)return pn(t,n);let c=l.statements[0].pipelines[0].commands[0];if(c.type!=="SimpleCommand")return pn(t,n);let u={...c,assignments:[...t.assignments,...c.assignments],redirections:[...c.redirections,...t.redirections],line:t.line};if(a&&t.args.length>0&&(u={...u,args:[...u.args,...t.args]},u.args.length>0)){let f=u.args[0];if(fn(f)){let d=dn(f);if(d&&hn(e,d)){let p={type:"SimpleCommand",name:f,args:u.args.slice(1),assignments:[],redirections:[]},m=Ws(e,p,s);m!==p&&(u={...u,name:m.name,args:[...m.args]})}}}return u}catch(i){throw s.delete(r),i}}function pn(e,t){let s=t;for(let o of e.args){let a=mn(o);s+=` ${a}`}let r=new B,n=r.parseWordFromString("eval",!1,!1),i=r.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:n,args:[i],assignments:e.assignments,redirections:e.redirections,line:e.line}}function mn(e){let t="";for(let s of e.parts)switch(s.type){case"Literal":t+=s.value.replace(/([\s"'$`\\*?[\]{}()<>|&;#!])/g,"\\$1");break;case"SingleQuoted":t+=`'${s.value}'`;break;case"DoubleQuoted":t+=`"${s.parts.map(r=>r.type==="Literal"?r.value:`$${r.type}`).join("")}"`;break;case"ParameterExpansion":t+=`\${${s.parameter}}`;break;case"CommandSubstitution":t+="$(...)";break;case"ArithmeticExpansion":t+=`$((${s.expression}))`;break;case"Glob":t+=s.pattern;break;default:break}return t}async function yn(e,t){let s=t.parts.map(u=>u.type==="Literal"?u.value:"\0").join(""),r=s.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);if(!r||!s.endsWith(")"))return null;let n=r[1],i=[],o=!1,a="",l=!1;for(let u of t.parts)if(u.type==="Literal"){let f=u.value;if(!o){let d=f.indexOf("=(");d!==-1&&(o=!0,f=f.slice(d+2))}if(o){f.endsWith(")")&&(f=f.slice(0,-1));let d=f.split(/(\s+)/);for(let p of d)/^\s+$/.test(p)?(a||l)&&(i.push(a),a="",l=!1):p&&(a+=p)}}else if(o)if(u.type==="BraceExpansion")if(/^\[.+\]=/.test(a))a+=jt({type:"Word",parts:[u]});else{(a||l)&&(i.push(a),a="",l=!1);let d=await Ce(e,{type:"Word",parts:[u]});i.push(...d.values)}else{(u.type==="SingleQuoted"||u.type==="DoubleQuoted"||u.type==="Escaped")&&(l=!0);let f=await L(e,{type:"Word",parts:[u]});a+=f}(a||l)&&i.push(a);let c=i.map(u=>/^\[.+\]=/.test(u)?u:u===""?"''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(u)&&!u.startsWith("'")&&!u.startsWith('"')?`'${u.replace(/'/g,"'\\''")}'`:u);return`${n}=(${c.join(" ")})`}async function gn(e,t){let s=-1,r=-1,n=!1;for(let h=0;h<t.parts.length;h++){let y=t.parts[h];if(y.type==="Literal"){let b=y.value.indexOf("+=");if(b!==-1){let A=y.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(A)){s=h,r=b,n=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(A)){s=h,r=b,n=!0;break}}let v=y.value.indexOf("=");if(v!==-1&&(v===0||y.value[v-1]!=="+")){let A=y.value.slice(0,v);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(A)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(A)){s=h,r=v;break}}}}if(s===-1)return null;let i=t.parts.slice(0,s),o=t.parts[s];if(o.type!=="Literal")return null;let a=n?2:1,l=o.value.slice(0,r),c=o.value.slice(r+a),u=t.parts.slice(s+1),f="";for(let h of i)f+=await L(e,{type:"Word",parts:[h]});f+=l;let d={type:"Word",parts:c!==""?[{type:"Literal",value:c},...u]:u},p=d.parts.length>0?await L(e,d):"";return`${f}${n?"+=":"="}${p}`}var co=["tar","yq","xan","sqlite3","python3","python"];function wn(e){return co.includes(e)}var W=Object.freeze({stdout:"",stderr:"",exitCode:0});function z(e=""){return{stdout:e,stderr:"",exitCode:0}}function P(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function _(e,t,s){return{stdout:e,stderr:t,exitCode:s}}function Q(e){return{stdout:"",stderr:"",exitCode:e?0:1}}function Ne(e,t,s="",r=""){throw new J(e,t,s,r)}function le(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new J(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function zs(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new We;return W}if(t.length>1)throw new j(1,"",`bash: break: too many arguments
4
4
  `);let s=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new j(128,"",`bash: break: ${t[0]}: numeric argument required
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Pure JavaScript bzip2 compressor.
3
+ *
4
+ * Implements the bzip2 compression algorithm (public domain, Julian Seward 1996).
5
+ * Pipeline: RLE1 → BWT → MTF → RLE2 (RUNA/RUNB) → Huffman → bitstream output.
6
+ *
7
+ * This exists because no permissively-licensed JS bzip2 compressor is available
8
+ * on npm. Decompression uses the MIT-licensed `seek-bzip` package instead.
9
+ */
10
+ /**
11
+ * Compress data using bzip2 algorithm.
12
+ * @param data - Input data to compress
13
+ * @param blockSizeLevel - Block size level 1-9 (x 100KB), default 9
14
+ * @param maxSize - Maximum input size in bytes (default 10MB)
15
+ * @returns Compressed bzip2 data
16
+ */
17
+ export declare function bzip2Compress(data: Uint8Array, blockSizeLevel?: number, maxSize?: number): Uint8Array;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-bash",
3
- "version": "2.14.0",
3
+ "version": "2.14.1",
4
4
  "description": "A simulated bash environment with virtual filesystem",
5
5
  "repository": {
6
6
  "type": "git",
@@ -73,7 +73,7 @@
73
73
  "vitest": "^4.0.16"
74
74
  },
75
75
  "dependencies": {
76
- "compressjs": "^1.0.3",
76
+ "seek-bzip": "^2.0.0",
77
77
  "diff": "^8.0.2",
78
78
  "fast-xml-parser": "^5.3.3",
79
79
  "file-type": "^21.2.0",
@@ -98,11 +98,11 @@
98
98
  "build": "rm -rf dist && tsc && pnpm build:lib && pnpm build:lib:cjs && pnpm build:browser && pnpm build:cli && pnpm build:shell && pnpm build:worker && pnpm build:clean && cp dist/index.d.ts dist/index.d.cts && sed '1,/^-->/d' AGENTS.npm.md > dist/AGENTS.md",
99
99
  "build:clean": "find dist -name '*.test.js' -delete && find dist -name '*.test.d.ts' -delete",
100
100
  "build:worker": "esbuild src/commands/python3/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/python3/worker.js --external:../../../vendor/cpython-emscripten/* && cp src/commands/python3/worker.js dist/commands/python3/worker.js && mkdir -p dist/bin/chunks && cp src/commands/python3/worker.js dist/bin/chunks/worker.js && mkdir -p dist/bundle/chunks && cp src/commands/python3/worker.js dist/bundle/chunks/worker.js && esbuild src/commands/js-exec/worker.ts --bundle --platform=node --format=esm --outfile=src/commands/js-exec/worker.js --external:quickjs-emscripten && cp src/commands/js-exec/worker.js dist/commands/js-exec/worker.js && cp src/commands/js-exec/worker.js dist/bin/chunks/js-exec-worker.js && cp src/commands/js-exec/worker.js dist/bundle/chunks/js-exec-worker.js",
101
- "build:lib": "esbuild dist/index.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bundle --chunk-names=chunks/[name]-[hash] --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
102
- "build:lib:cjs": "esbuild dist/index.js --bundle --platform=node --format=cjs --minify --outfile=dist/bundle/index.cjs --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
103
- "build:browser": "esbuild dist/browser.js --bundle --platform=browser --format=esm --minify --outfile=dist/bundle/browser.js --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:node:zlib --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs --define:__BROWSER__=true --alias:node:dns=./src/shims/browser-unsupported.js",
104
- "build:cli": "esbuild dist/cli/just-bash.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node' --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
105
- "build:shell": "esbuild dist/cli/shell.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin/shell --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node' --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:compressjs",
101
+ "build:lib": "esbuild dist/index.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bundle --chunk-names=chunks/[name]-[hash] --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:seek-bzip",
102
+ "build:lib:cjs": "esbuild dist/index.js --bundle --platform=node --format=cjs --minify --outfile=dist/bundle/index.cjs --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:seek-bzip",
103
+ "build:browser": "esbuild dist/browser.js --bundle --platform=browser --format=esm --minify --outfile=dist/bundle/browser.js --external:diff --external:minimatch --external:sprintf-js --external:turndown --external:node:zlib --external:@mongodb-js/zstd --external:node-liblzma --external:seek-bzip --define:__BROWSER__=true --alias:node:dns=./src/shims/browser-unsupported.js",
104
+ "build:cli": "esbuild dist/cli/just-bash.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node' --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:seek-bzip",
105
+ "build:shell": "esbuild dist/cli/shell.js --bundle --splitting --platform=node --format=esm --minify --outdir=dist/bin/shell --entry-names=[name] --chunk-names=chunks/[name]-[hash] --banner:js='#!/usr/bin/env node' --external:sql.js --external:quickjs-emscripten --external:@mongodb-js/zstd --external:node-liblzma --external:seek-bzip",
106
106
  "validate": "pnpm lint && pnpm knip && pnpm typecheck && pnpm build && pnpm check:worker-sync && pnpm test:run && pnpm test:wasm && pnpm test:dist && pnpm test:examples",
107
107
  "test:examples": "cd examples/cjs-consumer && pnpm install --no-frozen-lockfile && npx tsc --noEmit",
108
108
  "typecheck": "tsc --noEmit",
@@ -1,63 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as oe}from"./chunk-YMMJLYIX.js";import{b as G}from"./chunk-YU6OGPZR.js";import{a as I}from"./chunk-SE4C7FJY.js";import{a as se,b as ae,c as H}from"./chunk-GTNBSMZR.js";import Ue from"compressjs";var j="file",ue="link",fe="symlink",Z="directory",Be={file:"0",link:"1",symlink:"2","character-device":"3","block-device":"4",directory:"5",fifo:"6","pax-header":"x","pax-global-header":"g","gnu-long-name":"L","gnu-long-link-name":"K"},Ne={0:j,1:ue,2:fe,3:"character-device",4:"block-device",5:Z,6:"fifo",x:"pax-header",g:"pax-global-header",L:"gnu-long-name",K:"gnu-long-link-name"},De=new Uint8Array(512),$=new Uint8Array(0),F=new TextEncoder,de=new TextDecoder;function v(e,t,n,r){r&&F.encodeInto(r,e.subarray(t,t+n))}function z(e,t,n,r){if(r===void 0)return;let i=r.toString(8).padStart(n-1,"0");F.encodeInto(i,e.subarray(t,t+n-1))}function C(e,t,n){let r=e.indexOf(0,t),i=r===-1||r>t+n?t+n:r;return de.decode(e.subarray(t,i))}function q(e,t,n){let r=0,i=t+n;for(let s=t;s<i;s++){let o=e[s];if(o===0)break;o!==32&&(r=r*8+(o-48))}return r}function R(e,t,n){if(e[t]&128){let r=0;r=e[t]&127;for(let i=1;i<n;i++)r=r*256+e[t+i];if(!Number.isSafeInteger(r))throw new Error("TAR number too large");return r}return q(e,t,n)}var b=e=>e.type===Z||e.type===fe||e.type===ue;async function me(e){if(e==null)return $;if(e instanceof Uint8Array)return e;if(typeof e=="string")return F.encode(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Blob)return new Uint8Array(await e.arrayBuffer());throw new TypeError("Unsupported content type for entry body.")}function pe(e,t){let{strip:n,filter:r,map:i}=t;if(!n&&!r&&!i)return e;let s={...e};if(n&&n>0){let a=s.name.split("/").filter(Boolean);if(n>=a.length)return null;let c=a.slice(n).join("/");if(s.name=s.type===Z&&!c.endsWith("/")?`${c}/`:c,s.linkname?.startsWith("/")){let l=s.linkname.split("/").filter(Boolean);s.linkname=n>=l.length?"/":`/${l.slice(n).join("/")}`}}if(r?.(s)===!1)return null;let o=i?i(s):s;return o&&(!o.name||!o.name.trim()||o.name==="."||o.name==="/")?null:o}var X=32,Le=48;function Pe(e){let t=q(e,148,8),n=0;for(let r=0;r<e.length;r++)r>=148&&r<156?n+=X:n+=e[r];return t===n}function Ke(e){e.fill(X,148,156);let t=0;for(let n of e)t+=n;for(let n=153;n>=148;n--)e[n]=(t&7)+Le,t>>=3;e[154]=0,e[155]=X}function Ge(e){let t={};e.name.length>100&&he(e.name)===null&&(t.path=e.name),e.linkname&&e.linkname.length>100&&(t.linkpath=e.linkname),e.uname&&e.uname.length>32&&(t.uname=e.uname),e.gname&&e.gname.length>32&&(t.gname=e.gname),e.uid!=null&&e.uid>2097151&&(t.uid=String(e.uid)),e.gid!=null&&e.gid>2097151&&(t.gid=String(e.gid)),e.size!=null&&e.size>8589934591&&(t.size=String(e.size)),e.pax&&Object.assign(t,e.pax);let n=Object.entries(t);if(n.length===0)return null;let r=F.encode(n.map(([i,s])=>{let o=`${i}=${s}
3
- `,a=F.encode(o).length+1,c=a+String(a).length;return c=a+String(c).length,`${c} ${o}`}).join(""));return{paxHeader:ge({name:de.decode(F.encode(`PaxHeader/${e.name}`).slice(0,100)),size:r.length,type:"pax-header",mode:420,mtime:e.mtime,uname:e.uname,gname:e.gname,uid:e.uid,gid:e.gid}),paxBody:r}}function he(e){if(e.length<=100)return null;let t=e.length-100-1,n=e.lastIndexOf("/",155);return n>0&&n>=t?{prefix:e.slice(0,n),name:e.slice(n+1)}:null}function ge(e){let t=new Uint8Array(512),n=b(e)?0:e.size??0,r=e.name,i="";if(!e.pax?.path){let s=he(r);s&&(r=s.name,i=s.prefix)}return v(t,0,100,r),z(t,100,8,e.mode??(e.type===Z?493:420)),z(t,108,8,e.uid??0),z(t,116,8,e.gid??0),z(t,124,12,n),z(t,136,12,Math.floor((e.mtime?.getTime()??Date.now())/1e3)),v(t,156,1,Be[e.type??j]),v(t,157,100,e.linkname),v(t,257,6,"ustar\0"),v(t,263,2,"00"),v(t,265,32,e.uname),v(t,297,32,e.gname),v(t,345,155,i),Ke(t),t}function He(e,t){if(t&&!Pe(e))throw new Error("Invalid tar header checksum.");let n=C(e,156,1),r={name:C(e,0,100),mode:q(e,100,8),uid:R(e,108,8),gid:R(e,116,8),size:R(e,124,12),mtime:new Date(R(e,136,12)*1e3),type:Ne[n]||j,linkname:C(e,157,100)},i=C(e,257,6);return i.trim()==="ustar"&&(r.uname=C(e,265,32),r.gname=C(e,297,32)),i==="ustar"&&(r.prefix=C(e,345,155)),r}var We={path:["name",e=>e],linkpath:["linkname",e=>e],size:["size",e=>parseInt(e,10)],mtime:["mtime",parseFloat],uid:["uid",e=>parseInt(e,10)],gid:["gid",e=>parseInt(e,10)],uname:["uname",e=>e],gname:["gname",e=>e]};function Xe(e){let t=new TextDecoder("utf-8"),n={},r={},i=0;for(;i<e.length;){let s=e.indexOf(32,i);if(s===-1)break;let o=parseInt(t.decode(e.subarray(i,s)),10);if(Number.isNaN(o)||o===0)break;let a=i+o,[c,l]=t.decode(e.subarray(s+1,a-1)).split("=",2);if(c&&l!==void 0){r[c]=l;let f=We[c];if(f){let[u,g]=f,p=g(l);(typeof p=="string"||!Number.isNaN(p))&&(n[u]=p)}}i=a}return Object.keys(r).length>0&&(n.pax=r),n}function ce(e,t){t.name!==void 0&&(e.name=t.name),t.linkname!==void 0&&(e.linkname=t.linkname),t.size!==void 0&&(e.size=t.size),t.mtime!==void 0&&(e.mtime=new Date(t.mtime*1e3)),t.uid!==void 0&&(e.uid=t.uid),t.gid!==void 0&&(e.gid=t.gid),t.uname!==void 0&&(e.uname=t.uname),t.gname!==void 0&&(e.gname=t.gname),t.pax&&(e.pax=Object.assign({},e.pax??{},t.pax))}function je(e){switch(e){case"pax-global-header":case"pax-header":return Xe;case"gnu-long-name":return t=>({name:C(t,0,t.length)});case"gnu-long-link-name":return t=>({linkname:C(t,0,t.length)});default:return}}function qe(e){let t=ge(e),n=Ge(e);if(!n)return[t];let r=-n.paxBody.length&511,i=r>0?[De.subarray(0,r)]:[];return[n.paxHeader,n.paxBody,...i,t]}var Ye=new Uint8Array(512*2);function Se(e,t,n){let r=null,i=0,s=!1;return{add(o){if(s){let a=new Error("No new tar entries after finalize.");throw t(a),a}if(r!==null){let a=new Error("Previous entry must be completed before adding a new one");throw t(a),a}try{let a=b(o)?0:o.size??0,c=qe({...o,size:a});for(let l of c)e(l);r={...o,size:a},i=0}catch(a){t(a)}},write(o){if(!r){let c=new Error("No active tar entry.");throw t(c),c}if(s){let c=new Error("Cannot write data after finalize.");throw t(c),c}let a=i+o.length;if(a>r.size){let c=new Error(`"${r.name}" exceeds given size of ${r.size} bytes.`);throw t(c),c}try{i=a,e(o)}catch(c){t(c)}},endEntry(){if(!r){let o=new Error("No active entry to end.");throw t(o),o}if(s){let o=new Error("Cannot end entry after finalize.");throw t(o),o}try{if(i!==r.size){let a=new Error(`Size mismatch for "${r.name}".`);throw t(a),a}let o=-r.size&511;o>0&&e(new Uint8Array(o)),r=null,i=0}catch(o){throw t(o),o}},finalize(){if(s){let o=new Error("Archive has already been finalized");throw t(o),o}if(r!==null){let o=new Error("Cannot finalize while an entry is still active");throw t(o),o}try{e(Ye),s=!0,n&&n()}catch(o){t(o)}}}}var O=256;function Ve(){let e=new Array(O),t=e.length-1,n=0,r=0,i=0,s=a=>{let c=e[n];a===c.length?(e[n]=$,n=n+1&t):e[n]=c.subarray(a),i-=a,i===0&&e.length>O&&(e=new Array(O),t=O-1,n=0,r=0)};function o(a,c){if(c){let p=0,d=Math.min(a,i);for(;d>0;){let h=e[n],m=Math.min(d,h.length),E=m===h.length?h:h.subarray(0,m);if(s(m),d-=m,p+=m,!c(E))break}return p}if(i<a)return null;if(a===0)return $;let l=e[n];if(l.length>=a){let p=l.length===a?l:l.subarray(0,a);return s(a),p}let f=new Uint8Array(a),u=0,g=a;for(;g>0;){let p=e[n],d=Math.min(g,p.length);f.set(d===p.length?p:p.subarray(0,d),u),u+=d,g-=d,s(d)}return f}return{push:a=>{if(a.length===0)return;let c=r+1&t;if(c===n){let l=e.length,f=l*2,u=new Array(f),g=r-n+l&l-1;if(n<r)for(let p=0;p<g;p++)u[p]=e[n+p];else if(g>0){let p=l-n;for(let d=0;d<p;d++)u[d]=e[n+d];for(let d=0;d<r;d++)u[p+d]=e[d]}e=u,t=f-1,n=0,r=g,c=r+1&t}e[r]=a,r=c,i+=a.length},available:()=>i,peek:a=>{if(i<a)return null;if(a===0)return $;let c=e[n];if(c.length>=a)return c.length===a?c:c.subarray(0,a);let l=new Uint8Array(a),f=0,u=n;for(;f<a;){let g=e[u],p=Math.min(a-f,g.length);p===g.length?l.set(g,f):l.set(g.subarray(0,p),f),f+=p,u=u+1&t}return l},discard:a=>{if(a>i)throw new Error("Too many bytes consumed");if(a===0)return;let c=a;for(;c>0;){let l=e[n],f=Math.min(c,l.length);s(f),c-=f}},pull:o}}var W=0,k=1,M=new Error("Tar archive is truncated.");function Ee(e={}){let t=e.strict??!1,{available:n,peek:r,push:i,discard:s,pull:o}=Ve(),a=W,c=!1,l=!1,f=!1,u=null,g={},p={},d={isEntryActive:()=>a===k,isBodyComplete:()=>!u||u.remaining===0,write(h){if(c)throw new Error("Archive already ended.");i(h)},end(){c=!0},readHeader(){if(a!==W)throw new Error("Cannot read header while an entry is active");if(!l)for(;!l;){if(n()<512){if(c){if(n()>0&&t)throw M;l=!0;return}return null}let h=r(512);if(le(h)){if(n()<512*2){if(c){if(t)throw M;l=!0;return}return null}if(le(r(512*2).subarray(512))){s(512*2),l=!0,f=!0;return}if(t)throw new Error("Invalid tar header.");s(512);continue}let m;try{m=He(h,t)}catch(A){if(t)throw A;s(512);continue}let E=je(m.type);if(E){let A=m.size+511&-512;if(n()<512+A){if(c&&t)throw M;return null}s(512);let w=E(o(A).subarray(0,m.size)),_=m.type==="pax-global-header"?g:p;for(let T in w)_[T]=w[T];continue}s(512);let S=m;return m.prefix&&(S.name=`${m.prefix}/${S.name}`),ce(S,g),ce(S,p),p={},u={header:S,remaining:S.size,padding:-S.size&511},a=k,S}},streamBody(h){if(a!==k||!u||u.remaining===0)return 0;let m=Math.min(u.remaining,n());if(m===0)return 0;let E=o(m,h);return u.remaining-=E,E},skipPadding(){if(a!==k||!u)return!0;if(u.remaining>0)throw new Error("Body not fully consumed");return n()<u.padding?!1:(s(u.padding),u=null,a=W,!0)},skipEntry(){if(a!==k||!u)return!0;let h=Math.min(u.remaining,n());return h>0&&(s(h),u.remaining-=h),u.remaining>0?!1:d.skipPadding()},validateEOF(){if(t){if(!f)throw M;if(n()>0&&o(n()).some(h=>h!==0))throw new Error("Invalid EOF.")}}};return d}function le(e){if(e.byteOffset%8===0){let t=new BigUint64Array(e.buffer,e.byteOffset,e.length/8);for(let n=0;n<t.length;n++)if(t[n]!==0n)return!1;return!0}for(let t=0;t<e.length;t++)if(e[t]!==0)return!1;return!0}function we(){return new CompressionStream("gzip")}function Ae(){return new DecompressionStream("gzip")}function Je(){let e,t;return{readable:new ReadableStream({start(n){e=n,t=Se(n.enqueue.bind(n),n.error.bind(n),n.close.bind(n))}}),controller:{add(n){let r=b(n),i={...n};return r&&(i.size=0),t.add(i),r&&t.endEntry(),new WritableStream({write(s){t.write(s)},close(){r||t.endEntry()},abort(s){e.error(s)}})},finalize(){t.finalize()},error(n){e.error(n)}}}}async function _e(e){let t=[],n=e.getReader(),r=0;try{for(;;){let{done:o,value:a}=await n.read();if(o)break;t.push(a),r+=a.length}let i=new Uint8Array(r),s=0;for(let o of t)i.set(o,s),s+=o.length;return i}finally{n.releaseLock()}}var ye=e=>e.pipeTo(new WritableStream);function Qe(e={}){let t=Ee(e),n=null,r=!1,i=s=>{if(!r){r=!0;try{for(;;)if(t.isEntryActive()){if(n){if(t.streamBody(o=>(n.enqueue(o),!0))===0&&!t.isBodyComplete())break}else if(!t.skipEntry())break;if(t.isBodyComplete()){try{n?.close()}catch{}if(n=null,!t.skipPadding())break}}else{let o=t.readHeader();if(o==null)break;s.enqueue({header:o,body:new ReadableStream({start(a){o.size===0?a.close():n=a},pull:()=>i(s),cancel(){n=null,i(s)}})})}}catch(o){try{n?.error(o)}catch{}throw n=null,o}finally{r=!1}}};return new TransformStream({transform(s,o){try{t.write(s),i(o)}catch(a){try{n?.error(a)}catch{}throw a}},flush(s){try{if(t.end(),i(s),t.validateEOF(),t.isEntryActive()&&!t.isBodyComplete())try{n?.close()}catch{}}catch(o){try{n?.error(o)}catch{}throw o}}},void 0,{highWaterMark:1})}async function Te(e){let{readable:t,controller:n}=Je();return await(async()=>{for(let r of e){let i=n.add(r.header),s="body"in r?r.body:r.data;if(!s){await i.close();continue}if(s instanceof ReadableStream)await s.pipeTo(i);else if(s instanceof Blob)await s.stream().pipeTo(i);else try{let o=await me(s);if(o.length>0){let a=i.getWriter();await a.write(o),await a.close()}else await i.close()}catch{throw new TypeError(`Unsupported content type for entry "${r.header.name}".`)}}})().then(()=>n.finalize()).catch(r=>n.error(r)),new Uint8Array(await _e(t))}async function Ce(e,t={}){let n=e instanceof ReadableStream?e:new ReadableStream({start(s){s.enqueue(e instanceof Uint8Array?e:new Uint8Array(e)),s.close()}}),r=[],i=n.pipeThrough(Qe(t));for await(let s of i){let o;try{o=pe(s.header,t)}catch(a){throw await s.body.cancel(),a}if(o===null){await ye(s.body);continue}b(o)?(await ye(s.body),r.push({header:o})):r.push({header:o,data:await _e(s.body)})}return r}var B=null,N=null;async function Ie(){if(B)return B;if(N)throw N;try{return B=await G.runTrustedAsync(()=>import("node-liblzma")),B}catch{throw N=new Error("xz compression requires node-liblzma which failed to load. Install liblzma-dev (apt) or xz (brew) and reinstall dependencies."),N}}var D=null,L=null;async function Fe(){if(D)return D;if(L)throw L;try{return D=await G.runTrustedAsync(()=>import("@mongodb-js/zstd")),D}catch{throw L=new Error("zstd compression requires @mongodb-js/zstd which is not installed. Install it with: npm install @mongodb-js/zstd"),L}}var y=100*1024*1024,xe=512,ve=1e4;function et(e){let t="file";e.isDirectory?t="directory":e.isSymlink&&(t="symlink");let n=e.name;e.isDirectory&&!n.endsWith("/")&&(n+="/");let r;e.content!==void 0&&(typeof e.content=="string"?r=new TextEncoder().encode(e.content):r=e.content);let i=e.isDirectory||e.isSymlink?0:r?.length??0;return{header:{name:n,mode:e.mode??(e.isDirectory?493:420),uid:e.uid??0,gid:e.gid??0,size:i,mtime:e.mtime??new Date,type:t,linkname:e.linkTarget??"",uname:"user",gname:"user"},body:r}}async function U(e){let t=e.map(et);return Te(t)}async function ze(e){let t=await U(e),i=new ReadableStream({start(l){l.enqueue(t),l.close()}}).pipeThrough(we()).getReader(),s=[];for(;;){let{done:l,value:f}=await i.read();if(l)break;s.push(f)}let o=s.reduce((l,f)=>l+f.length,0),a=new Uint8Array(o),c=0;for(let l of s)a.set(l,c),c+=l.length;return a}async function x(e){if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};if(e.length<xe||e.length%xe!==0)return{entries:[],error:"Invalid tar archive format"};try{let t=await Ce(e),n=[];for(let r of t){if(n.length>=ve)return{entries:n,error:`Too many entries (max ${ve})`};let i="file";switch(r.header.type){case"directory":i="directory";break;case"symlink":i="symlink";break;case"link":i="hardlink";break;case"file":i="file";break;default:i="other"}n.push({name:r.header.name,mode:r.header.mode??420,uid:r.header.uid??0,gid:r.header.gid??0,size:r.header.size,mtime:r.header.mtime??new Date,type:i,linkTarget:r.header.linkname||void 0,content:r.data??new Uint8Array(0)})}return{entries:n}}catch(t){let n=t instanceof Error?t.message:"Unknown error";return{entries:[],error:n}}}async function Y(e){if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let r=new ReadableStream({start(c){c.enqueue(e),c.close()}}).pipeThrough(Ae()).getReader(),i=[],s=0;for(;;){let{done:c,value:l}=await r.read();if(c)break;if(s+=l.length,s>y)return await r.cancel(),{entries:[],error:`Decompressed archive too large (max ${y} bytes)`};i.push(l)}let o=new Uint8Array(s),a=0;for(let c of i)o.set(c,a),a+=c.length;return x(o)}catch(t){let n=t instanceof Error?t.message:"Unknown error";return{entries:[],error:`Decompression failed: ${n}`}}}function V(e){return e.length>=2&&e[0]===31&&e[1]===139}function J(e){return e.length>=3&&e[0]===66&&e[1]===90&&e[2]===104}function Q(e){return e.length>=6&&e[0]===253&&e[1]===55&&e[2]===122&&e[3]===88&&e[4]===90&&e[5]===0}async function tt(e){let n=Ue.Bzip2.decompressFile(Array.from(e));return new Uint8Array(n)}async function rt(e){let t=Ue.Bzip2,n=[];return t.compressFile(Array.from(e),n,9),new Uint8Array(n)}async function nt(e){let n=(await Ie()).unxzSync(Buffer.from(e));return new Uint8Array(n)}async function it(e){let n=(await Ie()).xzSync(Buffer.from(e));return new Uint8Array(n)}async function ke(e){let t=await U(e);return rt(t)}async function be(e,t){if(!t?.allowNativeCodecs)throw new Error("xz compression is disabled by default (native codec risk). Pass { allowNativeCodecs: true } to opt in.");let n=await U(e);return it(n)}async function ee(e){if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let t=await tt(e);return t.length>y?{entries:[],error:`Decompressed archive too large (max ${y} bytes)`}:x(t)}catch(t){let n=t instanceof Error?t.message:"Unknown error";return{entries:[],error:n}}}async function te(e,t){if(!t?.allowNativeCodecs)return{entries:[],error:"xz decompression is disabled by default (native codec risk). Pass { allowNativeCodecs: true } to opt in, or decompress the archive externally before extraction."};if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let n=await nt(e);return n.length>y?{entries:[],error:`Decompressed archive too large (max ${y} bytes)`}:x(n)}catch(n){let r=n instanceof Error?n.message:"Unknown error";return{entries:[],error:r}}}function re(e){return e.length>=4&&e[0]===40&&e[1]===181&&e[2]===47&&e[3]===253}async function st(e){let n=await(await Fe()).compress(Buffer.from(e),3);return new Uint8Array(n)}async function at(e){let n=await(await Fe()).decompress(Buffer.from(e));return new Uint8Array(n)}async function Re(e,t){if(!t?.allowNativeCodecs)throw new Error("zstd compression is disabled by default (native codec risk). Pass { allowNativeCodecs: true } to opt in.");let n=await U(e);return st(n)}async function ne(e,t){if(!t?.allowNativeCodecs)return{entries:[],error:"zstd decompression is disabled by default (native codec risk). Pass { allowNativeCodecs: true } to opt in, or decompress the archive externally before extraction."};if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let n=await at(e);return n.length>y?{entries:[],error:`Decompressed archive too large (max ${y} bytes)`}:x(n)}catch(n){let r=n instanceof Error?n.message:"Unknown error";return{entries:[],error:r}}}function Oe(e){let t={create:!1,append:!1,update:!1,extract:!1,list:!1,file:"",autoCompress:!1,gzip:!1,bzip2:!1,xz:!1,zstd:!1,verbose:!1,toStdout:!1,keepOldFiles:!1,touch:!1,directory:"",preserve:!1,absoluteNames:!1,strip:0,exclude:[],filesFrom:"",excludeFrom:"",wildcards:!1},n=[],r=0;for(;r<e.length;){let i=e[r];if(i.startsWith("-")&&!i.startsWith("--")&&i.length>2){if(/^-\d+$/.test(i)){n.push(i),r++;continue}for(let s=1;s<i.length;s++){let o=i[s];switch(o){case"c":t.create=!0;break;case"r":t.append=!0;break;case"u":t.update=!0;break;case"x":t.extract=!0;break;case"t":t.list=!0;break;case"a":t.autoCompress=!0;break;case"z":t.gzip=!0;break;case"j":t.bzip2=!0;break;case"J":t.xz=!0;break;case"v":t.verbose=!0;break;case"O":t.toStdout=!0;break;case"k":t.keepOldFiles=!0;break;case"m":t.touch=!0;break;case"p":t.preserve=!0;break;case"P":t.absoluteNames=!0;break;case"f":if(s<i.length-1)t.file=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'f'
4
- `,exitCode:2}};t.file=e[r]}break;case"C":if(s<i.length-1)t.directory=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'C'
5
- `,exitCode:2}};t.directory=e[r]}break;case"T":if(s<i.length-1)t.filesFrom=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'T'
6
- `,exitCode:2}};t.filesFrom=e[r]}break;case"X":if(s<i.length-1)t.excludeFrom=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'X'
7
- `,exitCode:2}};t.excludeFrom=e[r]}break;default:return{ok:!1,error:H("tar",`-${o}`)}}}r++;continue}if(i==="-c"||i==="--create")t.create=!0;else if(i==="-r"||i==="--append")t.append=!0;else if(i==="-u"||i==="--update")t.update=!0;else if(i==="-x"||i==="--extract"||i==="--get")t.extract=!0;else if(i==="-t"||i==="--list")t.list=!0;else if(i==="-a"||i==="--auto-compress")t.autoCompress=!0;else if(i==="-z"||i==="--gzip"||i==="--gunzip")t.gzip=!0;else if(i==="-j"||i==="--bzip2")t.bzip2=!0;else if(i==="-J"||i==="--xz")t.xz=!0;else if(i==="--zstd")t.zstd=!0;else if(i==="-v"||i==="--verbose")t.verbose=!0;else if(i==="-O"||i==="--to-stdout")t.toStdout=!0;else if(i==="-k"||i==="--keep-old-files")t.keepOldFiles=!0;else if(i==="-m"||i==="--touch")t.touch=!0;else if(i==="--wildcards")t.wildcards=!0;else if(i==="-p"||i==="--preserve"||i==="--preserve-permissions")t.preserve=!0;else if(i==="-P"||i==="--absolute-names")t.absoluteNames=!0;else if(i==="-f"||i==="--file"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'f'
8
- `,exitCode:2}};t.file=e[r]}else if(i.startsWith("--file="))t.file=i.substring(7);else if(i==="-C"||i==="--directory"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'C'
9
- `,exitCode:2}};t.directory=e[r]}else if(i.startsWith("--directory="))t.directory=i.substring(12);else if(i.startsWith("--strip-components=")||i.startsWith("--strip=")){let s=i.includes("--strip-components=")?i.substring(19):i.substring(8),o=parseInt(s,10);if(Number.isNaN(o)||o<0)return{ok:!1,error:{stdout:"",stderr:`tar: invalid number for --strip: '${s}'
10
- `,exitCode:2}};t.strip=o}else if(i.startsWith("--exclude="))t.exclude.push(i.substring(10));else if(i==="--exclude"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option '--exclude' requires an argument
11
- `,exitCode:2}};t.exclude.push(e[r])}else if(i==="-T"||i==="--files-from"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'T'
12
- `,exitCode:2}};t.filesFrom=e[r]}else if(i.startsWith("--files-from="))t.filesFrom=i.substring(13);else if(i==="-X"||i==="--exclude-from"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'X'
13
- `,exitCode:2}};t.excludeFrom=e[r]}else if(i.startsWith("--exclude-from="))t.excludeFrom=i.substring(15);else if(i==="--"){n.push(...e.slice(r+1));break}else{if(i.startsWith("-"))return{ok:!1,error:H("tar",i)};n.push(i)}r++}return{ok:!0,options:t,files:n}}var Me=100,ot={name:"tar",summary:"manipulate tape archives",usage:"tar [options] [file...]",description:["Create, extract, or list contents of tar archives.","","One of -c, -r, -u, -x, or -t is required to specify the operation."],options:["-c, --create create a new archive","-r, --append append files to the end of an archive","-u, --update only append files newer than copy in archive","-x, --extract extract files from an archive","-t, --list list contents of an archive","-f, --file=ARCHIVE use archive file ARCHIVE","-a, --auto-compress use archive suffix to determine compression","-z, --gzip filter archive through gzip","-j, --bzip2 filter archive through bzip2","-J, --xz filter archive through xz","--zstd filter archive through zstd","-v, --verbose verbosely list files processed","-O, --to-stdout extract files to standard output","-k, --keep-old-files don't replace existing files when extracting","-m, --touch don't extract file modified time","-C, --directory=DIR change to directory DIR before performing operations","-p, --preserve preserve permissions","-P, --absolute-names do not strip leading '/' or block '..' paths","-T, --files-from=FILE read files to extract/create from FILE","-X, --exclude-from=FILE read exclude patterns from FILE","--strip=N strip N leading path components on extraction","--exclude=PATTERN exclude files matching PATTERN","--wildcards use wildcards for pattern matching"," --help display this help and exit"],examples:["tar -cvf archive.tar file1 file2 Create archive from files","tar -czvf archive.tar.gz dir/ Create gzip-compressed archive","tar -cjvf archive.tar.bz2 dir/ Create bzip2-compressed archive","tar -rf archive.tar newfile.txt Append file to archive","tar -uf archive.tar dir/ Update archive with newer files","tar -xvf archive.tar Extract archive","tar -xvf archive.tar -C /tmp Extract to /tmp","tar -tvf archive.tar List archive contents","tar -xzf archive.tar.gz Extract gzip archive","tar -xf archive.tar file1.txt Extract specific file","tar -xOf archive.tar file.txt Extract file to stdout","tar -xf archive.tar --wildcards '*.txt' Extract matching files"]};function ie(e,t){let n=e.includes("/")?e.substring(e.lastIndexOf("/")+1):e;for(let r of t){let i=r.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"<<<GLOBSTAR>>>").replace(/\*/g,"[^/]*").replace(/<<<GLOBSTAR>>>/g,".*").replace(/\?/g,".");if(I(`^${i}$`).test(e)||I(`^${i}/`).test(e)||!r.includes("/")&&I(`^${i}$`).test(n))return!0}return!1}function P(e,t){let n=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"<<<GLOBSTAR>>>").replace(/\*/g,"[^/]*").replace(/<<<GLOBSTAR>>>/g,".*").replace(/\?/g,"."),r=e.includes("/")?e.substring(e.lastIndexOf("/")+1):e;return I(`^${n}$`).test(e)||I(`^${n}$`).test(r)}function $e(e,t){if(t<=0)return e;let n=e.split("/").filter(r=>r!=="");return n.length<=t?"":n.slice(t).join("/")}function Ze(e){return e.split("/").some(t=>t==="..")}function ct(e,t){if(t)return{safePath:e};let n=e.replace(/^\/+/,"");return n.length===0?{safePath:""}:Ze(n)?{error:"Path contains '..'"}:{safePath:n}}function lt(e){let n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][e.getMonth()],r=e.getDate().toString().padStart(2," "),i=e.getHours().toString().padStart(2,"0"),s=e.getMinutes().toString().padStart(2,"0");return`${n} ${r} ${i}:${s}`}async function K(e,t,n,r){let i=[],s=[],o=e.fs.resolvePath(t,n);try{let a=await e.fs.stat(o);if(ie(n,r))return{entries:i,errors:s};if(a.isDirectory){i.push({name:n,isDirectory:!0,mode:a.mode,mtime:a.mtime});let c=await e.fs.readdir(o);for(let l=0;l<c.length;l+=Me){let f=c.slice(l,l+Me),u=await Promise.all(f.map(g=>K(e,t,n?`${n}/${g}`:g,r)));for(let g of u)i.push(...g.entries),s.push(...g.errors)}}else if(a.isFile){let c=await e.fs.readFileBuffer(o);i.push({name:n,content:c,mode:a.mode,mtime:a.mtime})}else if(a.isSymbolicLink){let c=await e.fs.readlink(o);i.push({name:n,isSymlink:!0,linkTarget:c,mode:a.mode,mtime:a.mtime})}}catch(a){let c=a instanceof Error?a.message:"unknown error";s.push(`tar: ${n}: ${c}`)}return{entries:i,errors:s}}async function ut(e,t,n){if(n.length===0)return{stdout:"",stderr:`tar: Cowardly refusing to create an empty archive
14
- `,exitCode:2};let r=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,i=[],s=[],o="";for(let f of n){let{entries:u,errors:g}=await K(e,r,f,t.exclude);if(i.push(...u),s.push(...g),t.verbose)for(let p of u)o+=`${p.name}${p.isDirectory?"/":""}
15
- `}if(i.length===0&&s.length>0)return{stdout:"",stderr:`${s.join(`
16
- `)}
17
- `,exitCode:2};let a;try{t.gzip?a=await ze(i):t.bzip2?a=await ke(i):t.xz?a=await be(i):t.zstd?a=await Re(i):a=await U(i)}catch(f){return{stdout:"",stderr:`tar: error creating archive: ${f instanceof Error?f.message:"unknown error"}
18
- `,exitCode:2}}let c="";if(t.file&&t.file!=="-"){let f=e.fs.resolvePath(e.cwd,t.file);try{await e.fs.writeFile(f,a)}catch(u){let g=u instanceof Error?u.message:"unknown error";return{stdout:"",stderr:`tar: ${t.file}: ${g}
19
- `,exitCode:2}}}else c=Buffer.from(a).toString("latin1");let l=o;return s.length>0&&(l+=`${s.join(`
20
- `)}
21
- `),{stdout:c,stderr:l,exitCode:s.length>0?2:0}}async function ft(e,t,n){if(!t.file||t.file==="-")return{stdout:"",stderr:`tar: Cannot append to stdin/stdout
22
- `,exitCode:2};if(n.length===0)return{stdout:"",stderr:`tar: Cowardly refusing to append nothing to archive
23
- `,exitCode:2};let r=e.fs.resolvePath(e.cwd,t.file),i;try{i=await e.fs.readFileBuffer(r)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
24
- `,exitCode:2}}let s=await x(i);if(s.error)return{stdout:"",stderr:`tar: ${s.error}
25
- `,exitCode:2};let o=s.entries.map(d=>({name:d.name,content:d.content,mode:d.mode,mtime:d.mtime,isDirectory:d.type==="directory",isSymlink:d.type==="symlink",linkTarget:d.linkTarget,uid:d.uid,gid:d.gid})),a=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,c=[],l=[],f="";for(let d of n){let{entries:h,errors:m}=await K(e,a,d,t.exclude);if(c.push(...h),l.push(...m),t.verbose)for(let E of h)f+=`${E.name}${E.isDirectory?"/":""}
26
- `}let u=[...o,...c],g;try{g=await U(u)}catch(d){return{stdout:"",stderr:`tar: error creating archive: ${d instanceof Error?d.message:"unknown error"}
27
- `,exitCode:2}}try{await e.fs.writeFile(r,g)}catch(d){let h=d instanceof Error?d.message:"unknown error";return{stdout:"",stderr:`tar: ${t.file}: ${h}
28
- `,exitCode:2}}let p=f;return l.length>0&&(p+=`${l.join(`
29
- `)}
30
- `),{stdout:"",stderr:p,exitCode:l.length>0?2:0}}async function dt(e,t,n){if(!t.file||t.file==="-")return{stdout:"",stderr:`tar: Cannot update stdin/stdout
31
- `,exitCode:2};if(n.length===0)return{stdout:"",stderr:`tar: Cowardly refusing to update with nothing
32
- `,exitCode:2};let r=e.fs.resolvePath(e.cwd,t.file),i;try{i=await e.fs.readFileBuffer(r)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
33
- `,exitCode:2}}let s=await x(i);if(s.error)return{stdout:"",stderr:`tar: ${s.error}
34
- `,exitCode:2};let o=new Map;for(let m of s.entries)o.set(m.name,m.mtime);let a=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,c=[],l=[],f="";for(let m of n){let{entries:E,errors:S}=await K(e,a,m,t.exclude);l.push(...S);for(let A of E){let w=o.get(A.name);(!w||A.mtime&&A.mtime.getTime()>w.getTime())&&(c.push(A),t.verbose&&(f+=`${A.name}${A.isDirectory?"/":""}
35
- `))}}if(c.length===0){let m="";return l.length>0&&(m=`${l.join(`
36
- `)}
37
- `),{stdout:"",stderr:m,exitCode:l.length>0?2:0}}let u=new Set(c.map(m=>m.name)),p=[...s.entries.filter(m=>!u.has(m.name)).map(m=>({name:m.name,content:m.content,mode:m.mode,mtime:m.mtime,isDirectory:m.type==="directory",isSymlink:m.type==="symlink",linkTarget:m.linkTarget,uid:m.uid,gid:m.gid})),...c],d;try{d=await U(p)}catch(m){return{stdout:"",stderr:`tar: error creating archive: ${m instanceof Error?m.message:"unknown error"}
38
- `,exitCode:2}}try{await e.fs.writeFile(r,d)}catch(m){let E=m instanceof Error?m.message:"unknown error";return{stdout:"",stderr:`tar: ${t.file}: ${E}
39
- `,exitCode:2}}let h=f;return l.length>0&&(h+=`${l.join(`
40
- `)}
41
- `),{stdout:"",stderr:h,exitCode:l.length>0?2:0}}async function mt(e,t,n){let r;if(t.file&&t.file!=="-"){let h=e.fs.resolvePath(e.cwd,t.file);try{r=await e.fs.readFileBuffer(h)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
42
- `,exitCode:2}}}else r=Uint8Array.from(e.stdin,h=>h.charCodeAt(0));let i,s=t.gzip||V(r),o=t.bzip2||J(r),a=t.xz||Q(r),c=t.zstd||re(r);if(s?i=await Y(r):o?i=await ee(r):a?i=await te(r):c?i=await ne(r):i=await x(r),i.error)return{stdout:"",stderr:`tar: ${i.error}
43
- `,exitCode:2};let l=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,f=t.absoluteNames?n:n.map(h=>h.replace(/^\/+/,"")).filter(h=>h.length>0),u="",g="",p=[];if(t.directory&&!t.toStdout)try{await e.fs.mkdir(l,{recursive:!0})}catch{}for(let h of i.entries){let m=$e(h.name,t.strip);if(!m)continue;let E=ct(m,t.absoluteNames);if(E.error){p.push(`tar: ${m}: ${E.error}`);continue}let S=E.safePath??"";if(!S)continue;let A=S.endsWith("/")?S.slice(0,-1):S;if(f.length>0){let _;if(t.wildcards?_=f.some(T=>P(S,T)||P(A,T)||S.startsWith(`${T}/`)):_=f.some(T=>S===T||S.startsWith(`${T}/`)||A===T),!_)continue}if(ie(S,t.exclude))continue;let w=e.fs.resolvePath(l,S);try{if(h.type==="directory"){if(t.toStdout)continue;await e.fs.mkdir(w,{recursive:!0}),t.verbose&&(u+=`${S}
44
- `)}else if(h.type==="file"){if(t.toStdout){g+=new TextDecoder().decode(h.content),t.verbose&&(u+=`${S}
45
- `);continue}if(t.keepOldFiles)try{await e.fs.stat(w),t.verbose&&(u+=`${S}: not overwritten, file exists
46
- `);continue}catch{}let _=w.substring(0,w.lastIndexOf("/"));if(_)try{await e.fs.mkdir(_,{recursive:!0})}catch{}if(await e.fs.writeFile(w,h.content),t.preserve&&h.mode)try{await e.fs.chmod(w,h.mode)}catch{}t.verbose&&(u+=`${S}
47
- `)}else if(h.type==="symlink"&&h.linkTarget){if(t.toStdout)continue;if(!t.absoluteNames&&(h.linkTarget.startsWith("/")||Ze(h.linkTarget))){p.push(`tar: ${S}: unsafe symlink target`);continue}if(t.keepOldFiles)try{await e.fs.stat(w),t.verbose&&(u+=`${S}: not overwritten, file exists
48
- `);continue}catch{}let _=w.substring(0,w.lastIndexOf("/"));if(_)try{await e.fs.mkdir(_,{recursive:!0})}catch{}try{await e.fs.symlink(h.linkTarget,w)}catch{}t.verbose&&(u+=`${S}
49
- `)}}catch(_){let T=_ instanceof Error?_.message:"unknown error";p.push(`tar: ${S}: ${T}`)}}let d=u;return p.length>0&&(d+=`${p.join(`
50
- `)}
51
- `),{stdout:g,stderr:d,exitCode:p.length>0?2:0}}async function pt(e,t,n){let r;if(t.file&&t.file!=="-"){let f=e.fs.resolvePath(e.cwd,t.file);try{r=await e.fs.readFileBuffer(f)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
52
- `,exitCode:2}}}else r=Uint8Array.from(e.stdin,f=>f.charCodeAt(0));let i,s=t.gzip||V(r),o=t.bzip2||J(r),a=t.xz||Q(r),c=t.zstd||re(r);if(s?i=await Y(r):o?i=await ee(r):a?i=await te(r):c?i=await ne(r):i=await x(r),i.error)return{stdout:"",stderr:`tar: ${i.error}
53
- `,exitCode:2};let l="";for(let f of i.entries){let u=$e(f.name,t.strip);if(!u)continue;let g=u.endsWith("/")?u.slice(0,-1):u;if(n.length>0){let p;if(t.wildcards?p=n.some(d=>P(u,d)||P(g,d)||u.startsWith(`${d}/`)):p=n.some(d=>u===d||u.startsWith(`${d}/`)||g===d),!p)continue}if(!ie(u,t.exclude))if(t.verbose){let p=f.type==="directory",d=oe(f.mode,p),h=`${f.uid}/${f.gid}`,m=f.size.toString().padStart(8," "),E=lt(f.mtime),S=`${d} ${h.padEnd(10)} ${m} ${E} ${u}`;f.type==="symlink"&&f.linkTarget&&(S+=` -> ${f.linkTarget}`),l+=`${S}
54
- `}else l+=`${u}
55
- `}return{stdout:l,stderr:"",exitCode:0}}var Ft={name:"tar",async execute(e,t){if(ae(e))return se(ot);let n=Oe(e);if(!n.ok)return n.error;let{options:r,files:i}=n,s=[r.create,r.append,r.update,r.extract,r.list].filter(Boolean).length;if(s===0)return{stdout:"",stderr:`tar: You must specify one of -c, -r, -u, -x, or -t
56
- `,exitCode:2};if(s>1)return{stdout:"",stderr:`tar: You may not specify more than one of -c, -r, -u, -x, or -t
57
- `,exitCode:2};if(r.autoCompress&&r.file&&r.create){let c=r.file.toLowerCase();c.endsWith(".tar.gz")||c.endsWith(".tgz")?r.gzip=!0:c.endsWith(".tar.bz2")||c.endsWith(".tbz2")?r.bzip2=!0:c.endsWith(".tar.xz")||c.endsWith(".txz")?r.xz=!0:(c.endsWith(".tar.zst")||c.endsWith(".tzst"))&&(r.zstd=!0)}let o=[r.gzip,r.bzip2,r.xz,r.zstd].filter(Boolean).length;if(o>1)return{stdout:"",stderr:`tar: You may not specify more than one compression option
58
- `,exitCode:2};if((r.append||r.update)&&o>0)return{stdout:"",stderr:`tar: Cannot append/update compressed archives - decompress first
59
- `,exitCode:2};let a=i;if(r.filesFrom){let c=t.fs.resolvePath(t.cwd,r.filesFrom);try{let f=(await t.fs.readFile(c)).split(`
60
- `).map(u=>u.trim()).filter(u=>u.length>0&&!u.startsWith("#"));a=[...i,...f]}catch{return{stdout:"",stderr:`tar: ${r.filesFrom}: Cannot open: No such file or directory
61
- `,exitCode:2}}}if(r.excludeFrom){let c=t.fs.resolvePath(t.cwd,r.excludeFrom);try{let f=(await t.fs.readFile(c)).split(`
62
- `).map(u=>u.trim()).filter(u=>u.length>0&&!u.startsWith("#"));r.exclude.push(...f)}catch{return{stdout:"",stderr:`tar: ${r.excludeFrom}: Cannot open: No such file or directory
63
- `,exitCode:2}}}return r.create?ut(t,r,a):r.append?ft(t,r,a):r.update?dt(t,r,a):r.extract?mt(t,r,a):pt(t,r,a)}},zt={name:"tar",flags:[{flag:"-c",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-t",type:"boolean"},{flag:"-f",type:"value",valueHint:"path"},{flag:"-z",type:"boolean"},{flag:"-j",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-C",type:"value",valueHint:"path"},{flag:"--strip-components",type:"value",valueHint:"number"},{flag:"--exclude",type:"value",valueHint:"pattern"}],needsArgs:!0};export{Ft as a,zt as b};
@@ -1,63 +0,0 @@
1
- #!/usr/bin/env node
2
- import{a as oe}from"./chunk-YMMJLYIX.js";import{b as G}from"./chunk-YU6OGPZR.js";import{a as I}from"./chunk-SE4C7FJY.js";import{a as se,b as ae,c as H}from"./chunk-GTNBSMZR.js";import Ue from"compressjs";var j="file",ue="link",fe="symlink",Z="directory",Be={file:"0",link:"1",symlink:"2","character-device":"3","block-device":"4",directory:"5",fifo:"6","pax-header":"x","pax-global-header":"g","gnu-long-name":"L","gnu-long-link-name":"K"},Ne={0:j,1:ue,2:fe,3:"character-device",4:"block-device",5:Z,6:"fifo",x:"pax-header",g:"pax-global-header",L:"gnu-long-name",K:"gnu-long-link-name"},De=new Uint8Array(512),$=new Uint8Array(0),F=new TextEncoder,de=new TextDecoder;function v(e,t,n,r){r&&F.encodeInto(r,e.subarray(t,t+n))}function z(e,t,n,r){if(r===void 0)return;let i=r.toString(8).padStart(n-1,"0");F.encodeInto(i,e.subarray(t,t+n-1))}function C(e,t,n){let r=e.indexOf(0,t),i=r===-1||r>t+n?t+n:r;return de.decode(e.subarray(t,i))}function q(e,t,n){let r=0,i=t+n;for(let s=t;s<i;s++){let o=e[s];if(o===0)break;o!==32&&(r=r*8+(o-48))}return r}function R(e,t,n){if(e[t]&128){let r=0;r=e[t]&127;for(let i=1;i<n;i++)r=r*256+e[t+i];if(!Number.isSafeInteger(r))throw new Error("TAR number too large");return r}return q(e,t,n)}var b=e=>e.type===Z||e.type===fe||e.type===ue;async function me(e){if(e==null)return $;if(e instanceof Uint8Array)return e;if(typeof e=="string")return F.encode(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Blob)return new Uint8Array(await e.arrayBuffer());throw new TypeError("Unsupported content type for entry body.")}function pe(e,t){let{strip:n,filter:r,map:i}=t;if(!n&&!r&&!i)return e;let s={...e};if(n&&n>0){let a=s.name.split("/").filter(Boolean);if(n>=a.length)return null;let c=a.slice(n).join("/");if(s.name=s.type===Z&&!c.endsWith("/")?`${c}/`:c,s.linkname?.startsWith("/")){let l=s.linkname.split("/").filter(Boolean);s.linkname=n>=l.length?"/":`/${l.slice(n).join("/")}`}}if(r?.(s)===!1)return null;let o=i?i(s):s;return o&&(!o.name||!o.name.trim()||o.name==="."||o.name==="/")?null:o}var X=32,Le=48;function Pe(e){let t=q(e,148,8),n=0;for(let r=0;r<e.length;r++)r>=148&&r<156?n+=X:n+=e[r];return t===n}function Ke(e){e.fill(X,148,156);let t=0;for(let n of e)t+=n;for(let n=153;n>=148;n--)e[n]=(t&7)+Le,t>>=3;e[154]=0,e[155]=X}function Ge(e){let t={};e.name.length>100&&he(e.name)===null&&(t.path=e.name),e.linkname&&e.linkname.length>100&&(t.linkpath=e.linkname),e.uname&&e.uname.length>32&&(t.uname=e.uname),e.gname&&e.gname.length>32&&(t.gname=e.gname),e.uid!=null&&e.uid>2097151&&(t.uid=String(e.uid)),e.gid!=null&&e.gid>2097151&&(t.gid=String(e.gid)),e.size!=null&&e.size>8589934591&&(t.size=String(e.size)),e.pax&&Object.assign(t,e.pax);let n=Object.entries(t);if(n.length===0)return null;let r=F.encode(n.map(([i,s])=>{let o=`${i}=${s}
3
- `,a=F.encode(o).length+1,c=a+String(a).length;return c=a+String(c).length,`${c} ${o}`}).join(""));return{paxHeader:ge({name:de.decode(F.encode(`PaxHeader/${e.name}`).slice(0,100)),size:r.length,type:"pax-header",mode:420,mtime:e.mtime,uname:e.uname,gname:e.gname,uid:e.uid,gid:e.gid}),paxBody:r}}function he(e){if(e.length<=100)return null;let t=e.length-100-1,n=e.lastIndexOf("/",155);return n>0&&n>=t?{prefix:e.slice(0,n),name:e.slice(n+1)}:null}function ge(e){let t=new Uint8Array(512),n=b(e)?0:e.size??0,r=e.name,i="";if(!e.pax?.path){let s=he(r);s&&(r=s.name,i=s.prefix)}return v(t,0,100,r),z(t,100,8,e.mode??(e.type===Z?493:420)),z(t,108,8,e.uid??0),z(t,116,8,e.gid??0),z(t,124,12,n),z(t,136,12,Math.floor((e.mtime?.getTime()??Date.now())/1e3)),v(t,156,1,Be[e.type??j]),v(t,157,100,e.linkname),v(t,257,6,"ustar\0"),v(t,263,2,"00"),v(t,265,32,e.uname),v(t,297,32,e.gname),v(t,345,155,i),Ke(t),t}function He(e,t){if(t&&!Pe(e))throw new Error("Invalid tar header checksum.");let n=C(e,156,1),r={name:C(e,0,100),mode:q(e,100,8),uid:R(e,108,8),gid:R(e,116,8),size:R(e,124,12),mtime:new Date(R(e,136,12)*1e3),type:Ne[n]||j,linkname:C(e,157,100)},i=C(e,257,6);return i.trim()==="ustar"&&(r.uname=C(e,265,32),r.gname=C(e,297,32)),i==="ustar"&&(r.prefix=C(e,345,155)),r}var We={path:["name",e=>e],linkpath:["linkname",e=>e],size:["size",e=>parseInt(e,10)],mtime:["mtime",parseFloat],uid:["uid",e=>parseInt(e,10)],gid:["gid",e=>parseInt(e,10)],uname:["uname",e=>e],gname:["gname",e=>e]};function Xe(e){let t=new TextDecoder("utf-8"),n={},r={},i=0;for(;i<e.length;){let s=e.indexOf(32,i);if(s===-1)break;let o=parseInt(t.decode(e.subarray(i,s)),10);if(Number.isNaN(o)||o===0)break;let a=i+o,[c,l]=t.decode(e.subarray(s+1,a-1)).split("=",2);if(c&&l!==void 0){r[c]=l;let f=We[c];if(f){let[u,g]=f,p=g(l);(typeof p=="string"||!Number.isNaN(p))&&(n[u]=p)}}i=a}return Object.keys(r).length>0&&(n.pax=r),n}function ce(e,t){t.name!==void 0&&(e.name=t.name),t.linkname!==void 0&&(e.linkname=t.linkname),t.size!==void 0&&(e.size=t.size),t.mtime!==void 0&&(e.mtime=new Date(t.mtime*1e3)),t.uid!==void 0&&(e.uid=t.uid),t.gid!==void 0&&(e.gid=t.gid),t.uname!==void 0&&(e.uname=t.uname),t.gname!==void 0&&(e.gname=t.gname),t.pax&&(e.pax=Object.assign({},e.pax??{},t.pax))}function je(e){switch(e){case"pax-global-header":case"pax-header":return Xe;case"gnu-long-name":return t=>({name:C(t,0,t.length)});case"gnu-long-link-name":return t=>({linkname:C(t,0,t.length)});default:return}}function qe(e){let t=ge(e),n=Ge(e);if(!n)return[t];let r=-n.paxBody.length&511,i=r>0?[De.subarray(0,r)]:[];return[n.paxHeader,n.paxBody,...i,t]}var Ye=new Uint8Array(512*2);function Se(e,t,n){let r=null,i=0,s=!1;return{add(o){if(s){let a=new Error("No new tar entries after finalize.");throw t(a),a}if(r!==null){let a=new Error("Previous entry must be completed before adding a new one");throw t(a),a}try{let a=b(o)?0:o.size??0,c=qe({...o,size:a});for(let l of c)e(l);r={...o,size:a},i=0}catch(a){t(a)}},write(o){if(!r){let c=new Error("No active tar entry.");throw t(c),c}if(s){let c=new Error("Cannot write data after finalize.");throw t(c),c}let a=i+o.length;if(a>r.size){let c=new Error(`"${r.name}" exceeds given size of ${r.size} bytes.`);throw t(c),c}try{i=a,e(o)}catch(c){t(c)}},endEntry(){if(!r){let o=new Error("No active entry to end.");throw t(o),o}if(s){let o=new Error("Cannot end entry after finalize.");throw t(o),o}try{if(i!==r.size){let a=new Error(`Size mismatch for "${r.name}".`);throw t(a),a}let o=-r.size&511;o>0&&e(new Uint8Array(o)),r=null,i=0}catch(o){throw t(o),o}},finalize(){if(s){let o=new Error("Archive has already been finalized");throw t(o),o}if(r!==null){let o=new Error("Cannot finalize while an entry is still active");throw t(o),o}try{e(Ye),s=!0,n&&n()}catch(o){t(o)}}}}var O=256;function Ve(){let e=new Array(O),t=e.length-1,n=0,r=0,i=0,s=a=>{let c=e[n];a===c.length?(e[n]=$,n=n+1&t):e[n]=c.subarray(a),i-=a,i===0&&e.length>O&&(e=new Array(O),t=O-1,n=0,r=0)};function o(a,c){if(c){let p=0,d=Math.min(a,i);for(;d>0;){let h=e[n],m=Math.min(d,h.length),E=m===h.length?h:h.subarray(0,m);if(s(m),d-=m,p+=m,!c(E))break}return p}if(i<a)return null;if(a===0)return $;let l=e[n];if(l.length>=a){let p=l.length===a?l:l.subarray(0,a);return s(a),p}let f=new Uint8Array(a),u=0,g=a;for(;g>0;){let p=e[n],d=Math.min(g,p.length);f.set(d===p.length?p:p.subarray(0,d),u),u+=d,g-=d,s(d)}return f}return{push:a=>{if(a.length===0)return;let c=r+1&t;if(c===n){let l=e.length,f=l*2,u=new Array(f),g=r-n+l&l-1;if(n<r)for(let p=0;p<g;p++)u[p]=e[n+p];else if(g>0){let p=l-n;for(let d=0;d<p;d++)u[d]=e[n+d];for(let d=0;d<r;d++)u[p+d]=e[d]}e=u,t=f-1,n=0,r=g,c=r+1&t}e[r]=a,r=c,i+=a.length},available:()=>i,peek:a=>{if(i<a)return null;if(a===0)return $;let c=e[n];if(c.length>=a)return c.length===a?c:c.subarray(0,a);let l=new Uint8Array(a),f=0,u=n;for(;f<a;){let g=e[u],p=Math.min(a-f,g.length);p===g.length?l.set(g,f):l.set(g.subarray(0,p),f),f+=p,u=u+1&t}return l},discard:a=>{if(a>i)throw new Error("Too many bytes consumed");if(a===0)return;let c=a;for(;c>0;){let l=e[n],f=Math.min(c,l.length);s(f),c-=f}},pull:o}}var W=0,k=1,M=new Error("Tar archive is truncated.");function Ee(e={}){let t=e.strict??!1,{available:n,peek:r,push:i,discard:s,pull:o}=Ve(),a=W,c=!1,l=!1,f=!1,u=null,g={},p={},d={isEntryActive:()=>a===k,isBodyComplete:()=>!u||u.remaining===0,write(h){if(c)throw new Error("Archive already ended.");i(h)},end(){c=!0},readHeader(){if(a!==W)throw new Error("Cannot read header while an entry is active");if(!l)for(;!l;){if(n()<512){if(c){if(n()>0&&t)throw M;l=!0;return}return null}let h=r(512);if(le(h)){if(n()<512*2){if(c){if(t)throw M;l=!0;return}return null}if(le(r(512*2).subarray(512))){s(512*2),l=!0,f=!0;return}if(t)throw new Error("Invalid tar header.");s(512);continue}let m;try{m=He(h,t)}catch(A){if(t)throw A;s(512);continue}let E=je(m.type);if(E){let A=m.size+511&-512;if(n()<512+A){if(c&&t)throw M;return null}s(512);let w=E(o(A).subarray(0,m.size)),_=m.type==="pax-global-header"?g:p;for(let T in w)_[T]=w[T];continue}s(512);let S=m;return m.prefix&&(S.name=`${m.prefix}/${S.name}`),ce(S,g),ce(S,p),p={},u={header:S,remaining:S.size,padding:-S.size&511},a=k,S}},streamBody(h){if(a!==k||!u||u.remaining===0)return 0;let m=Math.min(u.remaining,n());if(m===0)return 0;let E=o(m,h);return u.remaining-=E,E},skipPadding(){if(a!==k||!u)return!0;if(u.remaining>0)throw new Error("Body not fully consumed");return n()<u.padding?!1:(s(u.padding),u=null,a=W,!0)},skipEntry(){if(a!==k||!u)return!0;let h=Math.min(u.remaining,n());return h>0&&(s(h),u.remaining-=h),u.remaining>0?!1:d.skipPadding()},validateEOF(){if(t){if(!f)throw M;if(n()>0&&o(n()).some(h=>h!==0))throw new Error("Invalid EOF.")}}};return d}function le(e){if(e.byteOffset%8===0){let t=new BigUint64Array(e.buffer,e.byteOffset,e.length/8);for(let n=0;n<t.length;n++)if(t[n]!==0n)return!1;return!0}for(let t=0;t<e.length;t++)if(e[t]!==0)return!1;return!0}function we(){return new CompressionStream("gzip")}function Ae(){return new DecompressionStream("gzip")}function Je(){let e,t;return{readable:new ReadableStream({start(n){e=n,t=Se(n.enqueue.bind(n),n.error.bind(n),n.close.bind(n))}}),controller:{add(n){let r=b(n),i={...n};return r&&(i.size=0),t.add(i),r&&t.endEntry(),new WritableStream({write(s){t.write(s)},close(){r||t.endEntry()},abort(s){e.error(s)}})},finalize(){t.finalize()},error(n){e.error(n)}}}}async function _e(e){let t=[],n=e.getReader(),r=0;try{for(;;){let{done:o,value:a}=await n.read();if(o)break;t.push(a),r+=a.length}let i=new Uint8Array(r),s=0;for(let o of t)i.set(o,s),s+=o.length;return i}finally{n.releaseLock()}}var ye=e=>e.pipeTo(new WritableStream);function Qe(e={}){let t=Ee(e),n=null,r=!1,i=s=>{if(!r){r=!0;try{for(;;)if(t.isEntryActive()){if(n){if(t.streamBody(o=>(n.enqueue(o),!0))===0&&!t.isBodyComplete())break}else if(!t.skipEntry())break;if(t.isBodyComplete()){try{n?.close()}catch{}if(n=null,!t.skipPadding())break}}else{let o=t.readHeader();if(o==null)break;s.enqueue({header:o,body:new ReadableStream({start(a){o.size===0?a.close():n=a},pull:()=>i(s),cancel(){n=null,i(s)}})})}}catch(o){try{n?.error(o)}catch{}throw n=null,o}finally{r=!1}}};return new TransformStream({transform(s,o){try{t.write(s),i(o)}catch(a){try{n?.error(a)}catch{}throw a}},flush(s){try{if(t.end(),i(s),t.validateEOF(),t.isEntryActive()&&!t.isBodyComplete())try{n?.close()}catch{}}catch(o){try{n?.error(o)}catch{}throw o}}},void 0,{highWaterMark:1})}async function Te(e){let{readable:t,controller:n}=Je();return await(async()=>{for(let r of e){let i=n.add(r.header),s="body"in r?r.body:r.data;if(!s){await i.close();continue}if(s instanceof ReadableStream)await s.pipeTo(i);else if(s instanceof Blob)await s.stream().pipeTo(i);else try{let o=await me(s);if(o.length>0){let a=i.getWriter();await a.write(o),await a.close()}else await i.close()}catch{throw new TypeError(`Unsupported content type for entry "${r.header.name}".`)}}})().then(()=>n.finalize()).catch(r=>n.error(r)),new Uint8Array(await _e(t))}async function Ce(e,t={}){let n=e instanceof ReadableStream?e:new ReadableStream({start(s){s.enqueue(e instanceof Uint8Array?e:new Uint8Array(e)),s.close()}}),r=[],i=n.pipeThrough(Qe(t));for await(let s of i){let o;try{o=pe(s.header,t)}catch(a){throw await s.body.cancel(),a}if(o===null){await ye(s.body);continue}b(o)?(await ye(s.body),r.push({header:o})):r.push({header:o,data:await _e(s.body)})}return r}var B=null,N=null;async function Ie(){if(B)return B;if(N)throw N;try{return B=await G.runTrustedAsync(()=>import("node-liblzma")),B}catch{throw N=new Error("xz compression requires node-liblzma which failed to load. Install liblzma-dev (apt) or xz (brew) and reinstall dependencies."),N}}var D=null,L=null;async function Fe(){if(D)return D;if(L)throw L;try{return D=await G.runTrustedAsync(()=>import("@mongodb-js/zstd")),D}catch{throw L=new Error("zstd compression requires @mongodb-js/zstd which is not installed. Install it with: npm install @mongodb-js/zstd"),L}}var y=100*1024*1024,xe=512,ve=1e4;function et(e){let t="file";e.isDirectory?t="directory":e.isSymlink&&(t="symlink");let n=e.name;e.isDirectory&&!n.endsWith("/")&&(n+="/");let r;e.content!==void 0&&(typeof e.content=="string"?r=new TextEncoder().encode(e.content):r=e.content);let i=e.isDirectory||e.isSymlink?0:r?.length??0;return{header:{name:n,mode:e.mode??(e.isDirectory?493:420),uid:e.uid??0,gid:e.gid??0,size:i,mtime:e.mtime??new Date,type:t,linkname:e.linkTarget??"",uname:"user",gname:"user"},body:r}}async function U(e){let t=e.map(et);return Te(t)}async function ze(e){let t=await U(e),i=new ReadableStream({start(l){l.enqueue(t),l.close()}}).pipeThrough(we()).getReader(),s=[];for(;;){let{done:l,value:f}=await i.read();if(l)break;s.push(f)}let o=s.reduce((l,f)=>l+f.length,0),a=new Uint8Array(o),c=0;for(let l of s)a.set(l,c),c+=l.length;return a}async function x(e){if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};if(e.length<xe||e.length%xe!==0)return{entries:[],error:"Invalid tar archive format"};try{let t=await Ce(e),n=[];for(let r of t){if(n.length>=ve)return{entries:n,error:`Too many entries (max ${ve})`};let i="file";switch(r.header.type){case"directory":i="directory";break;case"symlink":i="symlink";break;case"link":i="hardlink";break;case"file":i="file";break;default:i="other"}n.push({name:r.header.name,mode:r.header.mode??420,uid:r.header.uid??0,gid:r.header.gid??0,size:r.header.size,mtime:r.header.mtime??new Date,type:i,linkTarget:r.header.linkname||void 0,content:r.data??new Uint8Array(0)})}return{entries:n}}catch(t){let n=t instanceof Error?t.message:"Unknown error";return{entries:[],error:n}}}async function Y(e){if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let r=new ReadableStream({start(c){c.enqueue(e),c.close()}}).pipeThrough(Ae()).getReader(),i=[],s=0;for(;;){let{done:c,value:l}=await r.read();if(c)break;if(s+=l.length,s>y)return await r.cancel(),{entries:[],error:`Decompressed archive too large (max ${y} bytes)`};i.push(l)}let o=new Uint8Array(s),a=0;for(let c of i)o.set(c,a),a+=c.length;return x(o)}catch(t){let n=t instanceof Error?t.message:"Unknown error";return{entries:[],error:`Decompression failed: ${n}`}}}function V(e){return e.length>=2&&e[0]===31&&e[1]===139}function J(e){return e.length>=3&&e[0]===66&&e[1]===90&&e[2]===104}function Q(e){return e.length>=6&&e[0]===253&&e[1]===55&&e[2]===122&&e[3]===88&&e[4]===90&&e[5]===0}async function tt(e){let n=Ue.Bzip2.decompressFile(Array.from(e));return new Uint8Array(n)}async function rt(e){let t=Ue.Bzip2,n=[];return t.compressFile(Array.from(e),n,9),new Uint8Array(n)}async function nt(e){let n=(await Ie()).unxzSync(Buffer.from(e));return new Uint8Array(n)}async function it(e){let n=(await Ie()).xzSync(Buffer.from(e));return new Uint8Array(n)}async function ke(e){let t=await U(e);return rt(t)}async function be(e,t){if(!t?.allowNativeCodecs)throw new Error("xz compression is disabled by default (native codec risk). Pass { allowNativeCodecs: true } to opt in.");let n=await U(e);return it(n)}async function ee(e){if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let t=await tt(e);return t.length>y?{entries:[],error:`Decompressed archive too large (max ${y} bytes)`}:x(t)}catch(t){let n=t instanceof Error?t.message:"Unknown error";return{entries:[],error:n}}}async function te(e,t){if(!t?.allowNativeCodecs)return{entries:[],error:"xz decompression is disabled by default (native codec risk). Pass { allowNativeCodecs: true } to opt in, or decompress the archive externally before extraction."};if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let n=await nt(e);return n.length>y?{entries:[],error:`Decompressed archive too large (max ${y} bytes)`}:x(n)}catch(n){let r=n instanceof Error?n.message:"Unknown error";return{entries:[],error:r}}}function re(e){return e.length>=4&&e[0]===40&&e[1]===181&&e[2]===47&&e[3]===253}async function st(e){let n=await(await Fe()).compress(Buffer.from(e),3);return new Uint8Array(n)}async function at(e){let n=await(await Fe()).decompress(Buffer.from(e));return new Uint8Array(n)}async function Re(e,t){if(!t?.allowNativeCodecs)throw new Error("zstd compression is disabled by default (native codec risk). Pass { allowNativeCodecs: true } to opt in.");let n=await U(e);return st(n)}async function ne(e,t){if(!t?.allowNativeCodecs)return{entries:[],error:"zstd decompression is disabled by default (native codec risk). Pass { allowNativeCodecs: true } to opt in, or decompress the archive externally before extraction."};if(e.length>y)return{entries:[],error:`Archive too large (max ${y} bytes)`};try{let n=await at(e);return n.length>y?{entries:[],error:`Decompressed archive too large (max ${y} bytes)`}:x(n)}catch(n){let r=n instanceof Error?n.message:"Unknown error";return{entries:[],error:r}}}function Oe(e){let t={create:!1,append:!1,update:!1,extract:!1,list:!1,file:"",autoCompress:!1,gzip:!1,bzip2:!1,xz:!1,zstd:!1,verbose:!1,toStdout:!1,keepOldFiles:!1,touch:!1,directory:"",preserve:!1,absoluteNames:!1,strip:0,exclude:[],filesFrom:"",excludeFrom:"",wildcards:!1},n=[],r=0;for(;r<e.length;){let i=e[r];if(i.startsWith("-")&&!i.startsWith("--")&&i.length>2){if(/^-\d+$/.test(i)){n.push(i),r++;continue}for(let s=1;s<i.length;s++){let o=i[s];switch(o){case"c":t.create=!0;break;case"r":t.append=!0;break;case"u":t.update=!0;break;case"x":t.extract=!0;break;case"t":t.list=!0;break;case"a":t.autoCompress=!0;break;case"z":t.gzip=!0;break;case"j":t.bzip2=!0;break;case"J":t.xz=!0;break;case"v":t.verbose=!0;break;case"O":t.toStdout=!0;break;case"k":t.keepOldFiles=!0;break;case"m":t.touch=!0;break;case"p":t.preserve=!0;break;case"P":t.absoluteNames=!0;break;case"f":if(s<i.length-1)t.file=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'f'
4
- `,exitCode:2}};t.file=e[r]}break;case"C":if(s<i.length-1)t.directory=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'C'
5
- `,exitCode:2}};t.directory=e[r]}break;case"T":if(s<i.length-1)t.filesFrom=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'T'
6
- `,exitCode:2}};t.filesFrom=e[r]}break;case"X":if(s<i.length-1)t.excludeFrom=i.substring(s+1),s=i.length;else{if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'X'
7
- `,exitCode:2}};t.excludeFrom=e[r]}break;default:return{ok:!1,error:H("tar",`-${o}`)}}}r++;continue}if(i==="-c"||i==="--create")t.create=!0;else if(i==="-r"||i==="--append")t.append=!0;else if(i==="-u"||i==="--update")t.update=!0;else if(i==="-x"||i==="--extract"||i==="--get")t.extract=!0;else if(i==="-t"||i==="--list")t.list=!0;else if(i==="-a"||i==="--auto-compress")t.autoCompress=!0;else if(i==="-z"||i==="--gzip"||i==="--gunzip")t.gzip=!0;else if(i==="-j"||i==="--bzip2")t.bzip2=!0;else if(i==="-J"||i==="--xz")t.xz=!0;else if(i==="--zstd")t.zstd=!0;else if(i==="-v"||i==="--verbose")t.verbose=!0;else if(i==="-O"||i==="--to-stdout")t.toStdout=!0;else if(i==="-k"||i==="--keep-old-files")t.keepOldFiles=!0;else if(i==="-m"||i==="--touch")t.touch=!0;else if(i==="--wildcards")t.wildcards=!0;else if(i==="-p"||i==="--preserve"||i==="--preserve-permissions")t.preserve=!0;else if(i==="-P"||i==="--absolute-names")t.absoluteNames=!0;else if(i==="-f"||i==="--file"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'f'
8
- `,exitCode:2}};t.file=e[r]}else if(i.startsWith("--file="))t.file=i.substring(7);else if(i==="-C"||i==="--directory"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'C'
9
- `,exitCode:2}};t.directory=e[r]}else if(i.startsWith("--directory="))t.directory=i.substring(12);else if(i.startsWith("--strip-components=")||i.startsWith("--strip=")){let s=i.includes("--strip-components=")?i.substring(19):i.substring(8),o=parseInt(s,10);if(Number.isNaN(o)||o<0)return{ok:!1,error:{stdout:"",stderr:`tar: invalid number for --strip: '${s}'
10
- `,exitCode:2}};t.strip=o}else if(i.startsWith("--exclude="))t.exclude.push(i.substring(10));else if(i==="--exclude"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option '--exclude' requires an argument
11
- `,exitCode:2}};t.exclude.push(e[r])}else if(i==="-T"||i==="--files-from"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'T'
12
- `,exitCode:2}};t.filesFrom=e[r]}else if(i.startsWith("--files-from="))t.filesFrom=i.substring(13);else if(i==="-X"||i==="--exclude-from"){if(r++,r>=e.length)return{ok:!1,error:{stdout:"",stderr:`tar: option requires an argument -- 'X'
13
- `,exitCode:2}};t.excludeFrom=e[r]}else if(i.startsWith("--exclude-from="))t.excludeFrom=i.substring(15);else if(i==="--"){n.push(...e.slice(r+1));break}else{if(i.startsWith("-"))return{ok:!1,error:H("tar",i)};n.push(i)}r++}return{ok:!0,options:t,files:n}}var Me=100,ot={name:"tar",summary:"manipulate tape archives",usage:"tar [options] [file...]",description:["Create, extract, or list contents of tar archives.","","One of -c, -r, -u, -x, or -t is required to specify the operation."],options:["-c, --create create a new archive","-r, --append append files to the end of an archive","-u, --update only append files newer than copy in archive","-x, --extract extract files from an archive","-t, --list list contents of an archive","-f, --file=ARCHIVE use archive file ARCHIVE","-a, --auto-compress use archive suffix to determine compression","-z, --gzip filter archive through gzip","-j, --bzip2 filter archive through bzip2","-J, --xz filter archive through xz","--zstd filter archive through zstd","-v, --verbose verbosely list files processed","-O, --to-stdout extract files to standard output","-k, --keep-old-files don't replace existing files when extracting","-m, --touch don't extract file modified time","-C, --directory=DIR change to directory DIR before performing operations","-p, --preserve preserve permissions","-P, --absolute-names do not strip leading '/' or block '..' paths","-T, --files-from=FILE read files to extract/create from FILE","-X, --exclude-from=FILE read exclude patterns from FILE","--strip=N strip N leading path components on extraction","--exclude=PATTERN exclude files matching PATTERN","--wildcards use wildcards for pattern matching"," --help display this help and exit"],examples:["tar -cvf archive.tar file1 file2 Create archive from files","tar -czvf archive.tar.gz dir/ Create gzip-compressed archive","tar -cjvf archive.tar.bz2 dir/ Create bzip2-compressed archive","tar -rf archive.tar newfile.txt Append file to archive","tar -uf archive.tar dir/ Update archive with newer files","tar -xvf archive.tar Extract archive","tar -xvf archive.tar -C /tmp Extract to /tmp","tar -tvf archive.tar List archive contents","tar -xzf archive.tar.gz Extract gzip archive","tar -xf archive.tar file1.txt Extract specific file","tar -xOf archive.tar file.txt Extract file to stdout","tar -xf archive.tar --wildcards '*.txt' Extract matching files"]};function ie(e,t){let n=e.includes("/")?e.substring(e.lastIndexOf("/")+1):e;for(let r of t){let i=r.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"<<<GLOBSTAR>>>").replace(/\*/g,"[^/]*").replace(/<<<GLOBSTAR>>>/g,".*").replace(/\?/g,".");if(I(`^${i}$`).test(e)||I(`^${i}/`).test(e)||!r.includes("/")&&I(`^${i}$`).test(n))return!0}return!1}function P(e,t){let n=t.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*\*/g,"<<<GLOBSTAR>>>").replace(/\*/g,"[^/]*").replace(/<<<GLOBSTAR>>>/g,".*").replace(/\?/g,"."),r=e.includes("/")?e.substring(e.lastIndexOf("/")+1):e;return I(`^${n}$`).test(e)||I(`^${n}$`).test(r)}function $e(e,t){if(t<=0)return e;let n=e.split("/").filter(r=>r!=="");return n.length<=t?"":n.slice(t).join("/")}function Ze(e){return e.split("/").some(t=>t==="..")}function ct(e,t){if(t)return{safePath:e};let n=e.replace(/^\/+/,"");return n.length===0?{safePath:""}:Ze(n)?{error:"Path contains '..'"}:{safePath:n}}function lt(e){let n=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][e.getMonth()],r=e.getDate().toString().padStart(2," "),i=e.getHours().toString().padStart(2,"0"),s=e.getMinutes().toString().padStart(2,"0");return`${n} ${r} ${i}:${s}`}async function K(e,t,n,r){let i=[],s=[],o=e.fs.resolvePath(t,n);try{let a=await e.fs.stat(o);if(ie(n,r))return{entries:i,errors:s};if(a.isDirectory){i.push({name:n,isDirectory:!0,mode:a.mode,mtime:a.mtime});let c=await e.fs.readdir(o);for(let l=0;l<c.length;l+=Me){let f=c.slice(l,l+Me),u=await Promise.all(f.map(g=>K(e,t,n?`${n}/${g}`:g,r)));for(let g of u)i.push(...g.entries),s.push(...g.errors)}}else if(a.isFile){let c=await e.fs.readFileBuffer(o);i.push({name:n,content:c,mode:a.mode,mtime:a.mtime})}else if(a.isSymbolicLink){let c=await e.fs.readlink(o);i.push({name:n,isSymlink:!0,linkTarget:c,mode:a.mode,mtime:a.mtime})}}catch(a){let c=a instanceof Error?a.message:"unknown error";s.push(`tar: ${n}: ${c}`)}return{entries:i,errors:s}}async function ut(e,t,n){if(n.length===0)return{stdout:"",stderr:`tar: Cowardly refusing to create an empty archive
14
- `,exitCode:2};let r=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,i=[],s=[],o="";for(let f of n){let{entries:u,errors:g}=await K(e,r,f,t.exclude);if(i.push(...u),s.push(...g),t.verbose)for(let p of u)o+=`${p.name}${p.isDirectory?"/":""}
15
- `}if(i.length===0&&s.length>0)return{stdout:"",stderr:`${s.join(`
16
- `)}
17
- `,exitCode:2};let a;try{t.gzip?a=await ze(i):t.bzip2?a=await ke(i):t.xz?a=await be(i):t.zstd?a=await Re(i):a=await U(i)}catch(f){return{stdout:"",stderr:`tar: error creating archive: ${f instanceof Error?f.message:"unknown error"}
18
- `,exitCode:2}}let c="";if(t.file&&t.file!=="-"){let f=e.fs.resolvePath(e.cwd,t.file);try{await e.fs.writeFile(f,a)}catch(u){let g=u instanceof Error?u.message:"unknown error";return{stdout:"",stderr:`tar: ${t.file}: ${g}
19
- `,exitCode:2}}}else c=Buffer.from(a).toString("latin1");let l=o;return s.length>0&&(l+=`${s.join(`
20
- `)}
21
- `),{stdout:c,stderr:l,exitCode:s.length>0?2:0}}async function ft(e,t,n){if(!t.file||t.file==="-")return{stdout:"",stderr:`tar: Cannot append to stdin/stdout
22
- `,exitCode:2};if(n.length===0)return{stdout:"",stderr:`tar: Cowardly refusing to append nothing to archive
23
- `,exitCode:2};let r=e.fs.resolvePath(e.cwd,t.file),i;try{i=await e.fs.readFileBuffer(r)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
24
- `,exitCode:2}}let s=await x(i);if(s.error)return{stdout:"",stderr:`tar: ${s.error}
25
- `,exitCode:2};let o=s.entries.map(d=>({name:d.name,content:d.content,mode:d.mode,mtime:d.mtime,isDirectory:d.type==="directory",isSymlink:d.type==="symlink",linkTarget:d.linkTarget,uid:d.uid,gid:d.gid})),a=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,c=[],l=[],f="";for(let d of n){let{entries:h,errors:m}=await K(e,a,d,t.exclude);if(c.push(...h),l.push(...m),t.verbose)for(let E of h)f+=`${E.name}${E.isDirectory?"/":""}
26
- `}let u=[...o,...c],g;try{g=await U(u)}catch(d){return{stdout:"",stderr:`tar: error creating archive: ${d instanceof Error?d.message:"unknown error"}
27
- `,exitCode:2}}try{await e.fs.writeFile(r,g)}catch(d){let h=d instanceof Error?d.message:"unknown error";return{stdout:"",stderr:`tar: ${t.file}: ${h}
28
- `,exitCode:2}}let p=f;return l.length>0&&(p+=`${l.join(`
29
- `)}
30
- `),{stdout:"",stderr:p,exitCode:l.length>0?2:0}}async function dt(e,t,n){if(!t.file||t.file==="-")return{stdout:"",stderr:`tar: Cannot update stdin/stdout
31
- `,exitCode:2};if(n.length===0)return{stdout:"",stderr:`tar: Cowardly refusing to update with nothing
32
- `,exitCode:2};let r=e.fs.resolvePath(e.cwd,t.file),i;try{i=await e.fs.readFileBuffer(r)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
33
- `,exitCode:2}}let s=await x(i);if(s.error)return{stdout:"",stderr:`tar: ${s.error}
34
- `,exitCode:2};let o=new Map;for(let m of s.entries)o.set(m.name,m.mtime);let a=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,c=[],l=[],f="";for(let m of n){let{entries:E,errors:S}=await K(e,a,m,t.exclude);l.push(...S);for(let A of E){let w=o.get(A.name);(!w||A.mtime&&A.mtime.getTime()>w.getTime())&&(c.push(A),t.verbose&&(f+=`${A.name}${A.isDirectory?"/":""}
35
- `))}}if(c.length===0){let m="";return l.length>0&&(m=`${l.join(`
36
- `)}
37
- `),{stdout:"",stderr:m,exitCode:l.length>0?2:0}}let u=new Set(c.map(m=>m.name)),p=[...s.entries.filter(m=>!u.has(m.name)).map(m=>({name:m.name,content:m.content,mode:m.mode,mtime:m.mtime,isDirectory:m.type==="directory",isSymlink:m.type==="symlink",linkTarget:m.linkTarget,uid:m.uid,gid:m.gid})),...c],d;try{d=await U(p)}catch(m){return{stdout:"",stderr:`tar: error creating archive: ${m instanceof Error?m.message:"unknown error"}
38
- `,exitCode:2}}try{await e.fs.writeFile(r,d)}catch(m){let E=m instanceof Error?m.message:"unknown error";return{stdout:"",stderr:`tar: ${t.file}: ${E}
39
- `,exitCode:2}}let h=f;return l.length>0&&(h+=`${l.join(`
40
- `)}
41
- `),{stdout:"",stderr:h,exitCode:l.length>0?2:0}}async function mt(e,t,n){let r;if(t.file&&t.file!=="-"){let h=e.fs.resolvePath(e.cwd,t.file);try{r=await e.fs.readFileBuffer(h)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
42
- `,exitCode:2}}}else r=Uint8Array.from(e.stdin,h=>h.charCodeAt(0));let i,s=t.gzip||V(r),o=t.bzip2||J(r),a=t.xz||Q(r),c=t.zstd||re(r);if(s?i=await Y(r):o?i=await ee(r):a?i=await te(r):c?i=await ne(r):i=await x(r),i.error)return{stdout:"",stderr:`tar: ${i.error}
43
- `,exitCode:2};let l=t.directory?e.fs.resolvePath(e.cwd,t.directory):e.cwd,f=t.absoluteNames?n:n.map(h=>h.replace(/^\/+/,"")).filter(h=>h.length>0),u="",g="",p=[];if(t.directory&&!t.toStdout)try{await e.fs.mkdir(l,{recursive:!0})}catch{}for(let h of i.entries){let m=$e(h.name,t.strip);if(!m)continue;let E=ct(m,t.absoluteNames);if(E.error){p.push(`tar: ${m}: ${E.error}`);continue}let S=E.safePath??"";if(!S)continue;let A=S.endsWith("/")?S.slice(0,-1):S;if(f.length>0){let _;if(t.wildcards?_=f.some(T=>P(S,T)||P(A,T)||S.startsWith(`${T}/`)):_=f.some(T=>S===T||S.startsWith(`${T}/`)||A===T),!_)continue}if(ie(S,t.exclude))continue;let w=e.fs.resolvePath(l,S);try{if(h.type==="directory"){if(t.toStdout)continue;await e.fs.mkdir(w,{recursive:!0}),t.verbose&&(u+=`${S}
44
- `)}else if(h.type==="file"){if(t.toStdout){g+=new TextDecoder().decode(h.content),t.verbose&&(u+=`${S}
45
- `);continue}if(t.keepOldFiles)try{await e.fs.stat(w),t.verbose&&(u+=`${S}: not overwritten, file exists
46
- `);continue}catch{}let _=w.substring(0,w.lastIndexOf("/"));if(_)try{await e.fs.mkdir(_,{recursive:!0})}catch{}if(await e.fs.writeFile(w,h.content),t.preserve&&h.mode)try{await e.fs.chmod(w,h.mode)}catch{}t.verbose&&(u+=`${S}
47
- `)}else if(h.type==="symlink"&&h.linkTarget){if(t.toStdout)continue;if(!t.absoluteNames&&(h.linkTarget.startsWith("/")||Ze(h.linkTarget))){p.push(`tar: ${S}: unsafe symlink target`);continue}if(t.keepOldFiles)try{await e.fs.stat(w),t.verbose&&(u+=`${S}: not overwritten, file exists
48
- `);continue}catch{}let _=w.substring(0,w.lastIndexOf("/"));if(_)try{await e.fs.mkdir(_,{recursive:!0})}catch{}try{await e.fs.symlink(h.linkTarget,w)}catch{}t.verbose&&(u+=`${S}
49
- `)}}catch(_){let T=_ instanceof Error?_.message:"unknown error";p.push(`tar: ${S}: ${T}`)}}let d=u;return p.length>0&&(d+=`${p.join(`
50
- `)}
51
- `),{stdout:g,stderr:d,exitCode:p.length>0?2:0}}async function pt(e,t,n){let r;if(t.file&&t.file!=="-"){let f=e.fs.resolvePath(e.cwd,t.file);try{r=await e.fs.readFileBuffer(f)}catch{return{stdout:"",stderr:`tar: ${t.file}: Cannot open: No such file or directory
52
- `,exitCode:2}}}else r=Uint8Array.from(e.stdin,f=>f.charCodeAt(0));let i,s=t.gzip||V(r),o=t.bzip2||J(r),a=t.xz||Q(r),c=t.zstd||re(r);if(s?i=await Y(r):o?i=await ee(r):a?i=await te(r):c?i=await ne(r):i=await x(r),i.error)return{stdout:"",stderr:`tar: ${i.error}
53
- `,exitCode:2};let l="";for(let f of i.entries){let u=$e(f.name,t.strip);if(!u)continue;let g=u.endsWith("/")?u.slice(0,-1):u;if(n.length>0){let p;if(t.wildcards?p=n.some(d=>P(u,d)||P(g,d)||u.startsWith(`${d}/`)):p=n.some(d=>u===d||u.startsWith(`${d}/`)||g===d),!p)continue}if(!ie(u,t.exclude))if(t.verbose){let p=f.type==="directory",d=oe(f.mode,p),h=`${f.uid}/${f.gid}`,m=f.size.toString().padStart(8," "),E=lt(f.mtime),S=`${d} ${h.padEnd(10)} ${m} ${E} ${u}`;f.type==="symlink"&&f.linkTarget&&(S+=` -> ${f.linkTarget}`),l+=`${S}
54
- `}else l+=`${u}
55
- `}return{stdout:l,stderr:"",exitCode:0}}var Ft={name:"tar",async execute(e,t){if(ae(e))return se(ot);let n=Oe(e);if(!n.ok)return n.error;let{options:r,files:i}=n,s=[r.create,r.append,r.update,r.extract,r.list].filter(Boolean).length;if(s===0)return{stdout:"",stderr:`tar: You must specify one of -c, -r, -u, -x, or -t
56
- `,exitCode:2};if(s>1)return{stdout:"",stderr:`tar: You may not specify more than one of -c, -r, -u, -x, or -t
57
- `,exitCode:2};if(r.autoCompress&&r.file&&r.create){let c=r.file.toLowerCase();c.endsWith(".tar.gz")||c.endsWith(".tgz")?r.gzip=!0:c.endsWith(".tar.bz2")||c.endsWith(".tbz2")?r.bzip2=!0:c.endsWith(".tar.xz")||c.endsWith(".txz")?r.xz=!0:(c.endsWith(".tar.zst")||c.endsWith(".tzst"))&&(r.zstd=!0)}let o=[r.gzip,r.bzip2,r.xz,r.zstd].filter(Boolean).length;if(o>1)return{stdout:"",stderr:`tar: You may not specify more than one compression option
58
- `,exitCode:2};if((r.append||r.update)&&o>0)return{stdout:"",stderr:`tar: Cannot append/update compressed archives - decompress first
59
- `,exitCode:2};let a=i;if(r.filesFrom){let c=t.fs.resolvePath(t.cwd,r.filesFrom);try{let f=(await t.fs.readFile(c)).split(`
60
- `).map(u=>u.trim()).filter(u=>u.length>0&&!u.startsWith("#"));a=[...i,...f]}catch{return{stdout:"",stderr:`tar: ${r.filesFrom}: Cannot open: No such file or directory
61
- `,exitCode:2}}}if(r.excludeFrom){let c=t.fs.resolvePath(t.cwd,r.excludeFrom);try{let f=(await t.fs.readFile(c)).split(`
62
- `).map(u=>u.trim()).filter(u=>u.length>0&&!u.startsWith("#"));r.exclude.push(...f)}catch{return{stdout:"",stderr:`tar: ${r.excludeFrom}: Cannot open: No such file or directory
63
- `,exitCode:2}}}return r.create?ut(t,r,a):r.append?ft(t,r,a):r.update?dt(t,r,a):r.extract?mt(t,r,a):pt(t,r,a)}},zt={name:"tar",flags:[{flag:"-c",type:"boolean"},{flag:"-x",type:"boolean"},{flag:"-t",type:"boolean"},{flag:"-f",type:"value",valueHint:"path"},{flag:"-z",type:"boolean"},{flag:"-j",type:"boolean"},{flag:"-v",type:"boolean"},{flag:"-C",type:"value",valueHint:"path"},{flag:"--strip-components",type:"value",valueHint:"number"},{flag:"--exclude",type:"value",valueHint:"pattern"}],needsArgs:!0};export{Ft as a,zt as b};