import{r as e,t}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as n}from"./chunk-HWKDQ44K-BJxdK4fT.mjs";import{constants as r,gunzipSync as i,gzipSync as a}from"node:zlib";var o={name:`gzip`,summary:`compress or expand files`,usage:`gzip [OPTION]... [FILE]...`,description:`Compress FILEs (by default, in-place).

When no FILE is given, or when FILE is -, read from standard input.

With -d, decompress instead.`,options:[`-c, --stdout      write to standard output, keep original files`,`-d, --decompress  decompress`,`-f, --force       force overwrite of output file`,`-k, --keep        keep (don't delete) input files`,`-l, --list        list compressed file contents`,`-n, --no-name     do not save or restore the original name and timestamp`,`-N, --name        save or restore the original file name and timestamp`,`-q, --quiet       suppress all warnings`,`-r, --recursive   operate recursively on directories`,`-S, --suffix=SUF  use suffix SUF on compressed files (default: .gz)`,`-t, --test        test compressed file integrity`,`-v, --verbose     verbose mode`,`-1, --fast        compress faster`,`-9, --best        compress better`,`    --help        display this help and exit`]},s={name:`gunzip`,summary:`decompress files`,usage:`gunzip [OPTION]... [FILE]...`,description:`Decompress FILEs (by default, in-place).

When no FILE is given, or when FILE is -, read from standard input.`,options:[`-c, --stdout      write to standard output, keep original files`,`-f, --force       force overwrite of output file`,`-k, --keep        keep (don't delete) input files`,`-l, --list        list compressed file contents`,`-n, --no-name     do not restore the original name and timestamp`,`-N, --name        restore the original file name and timestamp`,`-q, --quiet       suppress all warnings`,`-r, --recursive   operate recursively on directories`,`-S, --suffix=SUF  use suffix SUF on compressed files (default: .gz)`,`-t, --test        test compressed file integrity`,`-v, --verbose     verbose mode`,`    --help        display this help and exit`]},c={name:`zcat`,summary:`decompress files to stdout`,usage:`zcat [OPTION]... [FILE]...`,description:`Decompress FILEs to standard output.

When no FILE is given, or when FILE is -, read from standard input.`,options:[`-f, --force       force; read compressed data even from a terminal`,`-l, --list        list compressed file contents`,`-q, --quiet       suppress all warnings`,`-S, --suffix=SUF  use suffix SUF on compressed files (default: .gz)`,`-t, --test        test compressed file integrity`,`-v, --verbose     verbose mode`,`    --help        display this help and exit`]},l={stdout:{short:`c`,long:`stdout`,type:`boolean`},toStdout:{long:`to-stdout`,type:`boolean`},decompress:{short:`d`,long:`decompress`,type:`boolean`},uncompress:{long:`uncompress`,type:`boolean`},force:{short:`f`,long:`force`,type:`boolean`},keep:{short:`k`,long:`keep`,type:`boolean`},list:{short:`l`,long:`list`,type:`boolean`},noName:{short:`n`,long:`no-name`,type:`boolean`},name:{short:`N`,long:`name`,type:`boolean`},quiet:{short:`q`,long:`quiet`,type:`boolean`},recursive:{short:`r`,long:`recursive`,type:`boolean`},suffix:{short:`S`,long:`suffix`,type:`string`,default:`.gz`},test:{short:`t`,long:`test`,type:`boolean`},verbose:{short:`v`,long:`verbose`,type:`boolean`},fast:{short:`1`,long:`fast`,type:`boolean`},level2:{short:`2`,type:`boolean`},level3:{short:`3`,type:`boolean`},level4:{short:`4`,type:`boolean`},level5:{short:`5`,type:`boolean`},level6:{short:`6`,type:`boolean`},level7:{short:`7`,type:`boolean`},level8:{short:`8`,type:`boolean`},best:{short:`9`,long:`best`,type:`boolean`}};function u(e){return e.best?r.Z_BEST_COMPRESSION:e.level8?8:e.level7?7:e.level6?6:e.level5?5:e.level4?4:e.level3?3:e.level2?2:e.fast?r.Z_BEST_SPEED:r.Z_DEFAULT_COMPRESSION}function d(e){if(e.length<10||e[0]!==31||e[1]!==139)return{originalName:null,mtime:null,headerSize:0};let t=e[3],n=e[4]|e[5]<<8|e[6]<<16|e[7]<<24,r=10;if(t&4){if(r+2>e.length)return{originalName:null,mtime:null,headerSize:0};let t=e[r]|e[r+1]<<8;r+=2+t}let i=null;if(t&8){let t=r;for(;r<e.length&&e[r]!==0;)r++;r<e.length&&(i=new TextDecoder().decode(e.slice(t,r)),r++)}if(t&16){for(;r<e.length&&e[r]!==0;)r++;r++}return t&2&&(r+=2),{originalName:i,mtime:n>0?new Date(n*1e3):null,headerSize:r}}function f(e){if(e.length<4)return 0;let t=e.length;return e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24}function p(e){return e.length>=2&&e[0]===31&&e[1]===139}function m(e){return Buffer.from(e).toString(`latin1`)}function h(e){return e.limits?.maxOutputSize??0}function g(e,t){if(t>0){if(f(e)>t)throw Error(`decompressed data exceeds limit (${t} bytes)`);return i(e,{maxOutputLength:t})}return i(e)}async function _(e,t,n,r,i,o){let s=n.suffix,c,l,f,_=h(e);if(t===`-`||t===``)if(f=Uint8Array.from(e.stdin,e=>e.charCodeAt(0)),i){if(!p(f))return n.quiet?{stdout:``,stderr:``,exitCode:1}:{stdout:``,stderr:`${r}: stdin: not in gzip format
`,exitCode:1};try{return{stdout:m(g(f,_)),stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`${r}: stdin: ${e instanceof Error?e.message:`unknown error`}
`,exitCode:1}}}else{let e=u(n);return{stdout:m(a(f,{level:e})),stderr:``,exitCode:0}}c=e.fs.resolvePath(e.cwd,t);try{if((await e.fs.stat(c)).isDirectory)return n.recursive?await v(e,c,n,r,i,o):n.quiet?{stdout:``,stderr:``,exitCode:1}:{stdout:``,stderr:`${r}: ${t}: is a directory -- ignored
`,exitCode:1}}catch{return{stdout:``,stderr:`${r}: ${t}: No such file or directory
`,exitCode:1}}try{f=await e.fs.readFileBuffer(c)}catch{return{stdout:``,stderr:`${r}: ${t}: No such file or directory
`,exitCode:1}}if(i){if(!t.endsWith(s))return n.quiet?{stdout:``,stderr:``,exitCode:1}:{stdout:``,stderr:`${r}: ${t}: unknown suffix -- ignored
`,exitCode:1};if(!p(f))return n.quiet?{stdout:``,stderr:``,exitCode:1}:{stdout:``,stderr:`${r}: ${t}: not in gzip format
`,exitCode:1};let i;try{i=g(f,_)}catch(e){return{stdout:``,stderr:`${r}: ${t}: ${e instanceof Error?e.message:`unknown error`}
`,exitCode:1}}if(o)return{stdout:m(i),stderr:``,exitCode:0};if(n.name){let t=d(f);l=t.originalName?e.fs.resolvePath(e.cwd,t.originalName):c.slice(0,-s.length)}else l=c.slice(0,-s.length);if(!n.force)try{return await e.fs.stat(l),{stdout:``,stderr:`${r}: ${l} already exists; not overwritten
`,exitCode:1}}catch{}return await e.fs.writeFile(l,i),!n.keep&&!o&&await e.fs.rm(c),n.verbose?{stdout:``,stderr:`${t}:	${f.length>0?((1-f.length/i.length)*100).toFixed(1):`0.0`}% -- replaced with ${l.split(`/`).pop()}
`,exitCode:0}:{stdout:``,stderr:``,exitCode:0}}else{if(t.endsWith(s))return n.quiet?{stdout:``,stderr:``,exitCode:1}:{stdout:``,stderr:`${r}: ${t} already has ${s} suffix -- unchanged
`,exitCode:1};let i=u(n),d;try{d=a(f,{level:i})}catch(e){return{stdout:``,stderr:`${r}: ${t}: ${e instanceof Error?e.message:`unknown error`}
`,exitCode:1}}if(o)return{stdout:m(d),stderr:``,exitCode:0};if(l=c+s,!n.force)try{return await e.fs.stat(l),{stdout:``,stderr:`${r}: ${l} already exists; not overwritten
`,exitCode:1}}catch{}return await e.fs.writeFile(l,d),!n.keep&&!o&&await e.fs.rm(c),n.verbose?{stdout:``,stderr:`${t}:	${f.length>0?((1-d.length/f.length)*100).toFixed(1):`0.0`}% -- replaced with ${l.split(`/`).pop()}
`,exitCode:0}:{stdout:``,stderr:``,exitCode:0}}}async function v(e,t,n,r,i,a){let o=await e.fs.readdir(t),s=``,c=``,l=0;for(let u of o){let o=e.fs.resolvePath(t,u),d=await e.fs.stat(o);if(d.isDirectory){let t=await v(e,o,n,r,i,a);s+=t.stdout,c+=t.stderr,t.exitCode!==0&&(l=t.exitCode)}else if(d.isFile){let t=n.suffix;if(i&&!u.endsWith(t)||!i&&u.endsWith(t))continue;let d=await _(e,o.startsWith(`${e.cwd}/`)?o.slice(e.cwd.length+1):o,n,r,i,a);s+=d.stdout,c+=d.stderr,d.exitCode!==0&&(l=d.exitCode)}}return{stdout:s,stderr:c,exitCode:l}}async function y(e,t,n,r){let i;if(t===`-`||t===``)i=Uint8Array.from(e.stdin,e=>e.charCodeAt(0));else{let n=e.fs.resolvePath(e.cwd,t);try{i=await e.fs.readFileBuffer(n)}catch{return{stdout:``,stderr:`${r}: ${t}: No such file or directory
`,exitCode:1}}}if(!p(i))return n.quiet?{stdout:``,stderr:``,exitCode:1}:{stdout:``,stderr:`${r}: ${t}: not in gzip format
`,exitCode:1};let a=i.length,o=f(i),s=o>0?((1-a/o)*100).toFixed(1):`0.0`,c=d(i).originalName||(t===`-`?``:t.replace(/\.gz$/,``));return{stdout:`${a.toString().padStart(10)} ${o.toString().padStart(10)} ${s.padStart(5)}% ${c}
`,stderr:``,exitCode:0}}async function b(e,t,n,r){let i;if(t===`-`||t===``)i=Uint8Array.from(e.stdin,e=>e.charCodeAt(0));else{let n=e.fs.resolvePath(e.cwd,t);try{i=await e.fs.readFileBuffer(n)}catch{return{stdout:``,stderr:`${r}: ${t}: No such file or directory
`,exitCode:1}}}if(!p(i))return n.quiet?{stdout:``,stderr:``,exitCode:1}:{stdout:``,stderr:`${r}: ${t}: not in gzip format
`,exitCode:1};try{return g(i,h(e)),n.verbose?{stdout:``,stderr:`${t}:	OK
`,exitCode:0}:{stdout:``,stderr:``,exitCode:0}}catch(e){return{stdout:``,stderr:`${r}: ${t}: ${e instanceof Error?e.message:`invalid`}
`,exitCode:1}}}async function x(r,i,a){let u=a===`zcat`?c:a===`gunzip`?s:o;if(t(r))return e(u);let d=n(a,r,l);if(!d.ok)return d.error.stderr.includes(`unrecognized option`),d.error;let f=d.result.flags,p=d.result.positional,m=a===`gunzip`||a===`zcat`||f.decompress||f.uncompress,h=a===`zcat`||f.stdout||f.toStdout;if(f.list){p.length===0&&(p=[`-`]);let e=`  compressed uncompressed  ratio uncompressed_name
`,t=``,n=0;for(let r of p){let o=await y(i,r,f,a);e+=o.stdout,t+=o.stderr,o.exitCode!==0&&(n=o.exitCode)}return{stdout:e,stderr:t,exitCode:n}}if(f.test){p.length===0&&(p=[`-`]);let e=``,t=``,n=0;for(let r of p){let o=await b(i,r,f,a);e+=o.stdout,t+=o.stderr,o.exitCode!==0&&(n=o.exitCode)}return{stdout:e,stderr:t,exitCode:n}}p.length===0&&(p=[`-`]);let g=``,v=``,x=0;for(let e of p){let t=await _(i,e,f,a,m,h);g+=t.stdout,v+=t.stderr,t.exitCode!==0&&(x=t.exitCode)}return{stdout:g,stderr:v,exitCode:x}}var S={name:`gzip`,async execute(e,t){return{...await x(e,t,`gzip`),stdoutEncoding:`binary`}}},C={name:`gunzip`,async execute(e,t){return{...await x(e,t,`gunzip`),stdoutEncoding:`binary`}}},w={name:`zcat`,async execute(e,t){return{...await x(e,t,`zcat`),stdoutEncoding:`binary`}}},T={name:`gzip`,flags:[{flag:`-c`,type:`boolean`},{flag:`-d`,type:`boolean`},{flag:`-f`,type:`boolean`},{flag:`-k`,type:`boolean`},{flag:`-l`,type:`boolean`},{flag:`-n`,type:`boolean`},{flag:`-q`,type:`boolean`},{flag:`-r`,type:`boolean`},{flag:`-t`,type:`boolean`},{flag:`-v`,type:`boolean`},{flag:`-1`,type:`boolean`},{flag:`-9`,type:`boolean`}],stdinType:`binary`,needsFiles:!0},E={name:`gunzip`,flags:[{flag:`-c`,type:`boolean`},{flag:`-f`,type:`boolean`},{flag:`-k`,type:`boolean`},{flag:`-q`,type:`boolean`},{flag:`-v`,type:`boolean`}],stdinType:`binary`,needsFiles:!0},D={name:`zcat`,flags:[{flag:`-f`,type:`boolean`},{flag:`-q`,type:`boolean`},{flag:`-v`,type:`boolean`}],stdinType:`binary`,needsFiles:!0};export{w as a,T as i,E as n,D as o,C as r,S as t};
//# sourceMappingURL=chunk-LTZRCH7N-BfgCUlp9.mjs.map