import{r as e,t}from"./chunk-74CEPOFO-V0JXh91S.mjs";import{t as n}from"./chunk-HWKDQ44K-BJxdK4fT.mjs";var r={name:`base64`,summary:`base64 encode/decode data and print to standard output`,usage:`base64 [OPTION]... [FILE]`,options:[`-d, --decode    decode data`,`-w, --wrap=COLS wrap encoded lines after COLS character (default 76, 0 to disable)`,`    --help      display this help and exit`]},i={decode:{short:`d`,long:`decode`,type:`boolean`},wrap:{short:`w`,long:`wrap`,type:`number`,default:76}};async function a(e,t,n){if(t.length===0||t.length===1&&t[0]===`-`)return{ok:!0,data:Uint8Array.from(e.stdin,e=>e.charCodeAt(0))};let r=[];for(let i of t){if(i===`-`){r.push(Uint8Array.from(e.stdin,e=>e.charCodeAt(0)));continue}try{let t=e.fs.resolvePath(e.cwd,i),n=await e.fs.readFileBuffer(t);r.push(n)}catch{return{ok:!1,error:{stdout:``,stderr:`${n}: ${i}: No such file or directory
`,exitCode:1}}}}let i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return{ok:!0,data:a}}var o={name:`base64`,async execute(o,s){if(t(o))return e(r);let c=n(`base64`,o,i);if(!c.ok)return c.error;let l=c.result.flags.decode,u=c.result.flags.wrap,d=c.result.positional;try{if(l){let e=await a(s,d,`base64`);if(!e.ok)return e.error;if(typeof Buffer<`u`){let t=Buffer.from(e.data).toString(`utf8`).replace(/\s/g,``);return{stdout:Buffer.from(t,`base64`).toString(`latin1`),stderr:``,exitCode:0,stdoutEncoding:`binary`}}let t=String.fromCharCode(...e.data).replace(/\s/g,``);return{stdout:atob(t),stderr:``,exitCode:0,stdoutEncoding:`binary`}}let e=await a(s,d,`base64`);if(!e.ok)return e.error;let t;if(t=typeof Buffer<`u`?Buffer.from(e.data).toString(`base64`):btoa(String.fromCharCode(...e.data)),u>0){let e=[];for(let n=0;n<t.length;n+=u)e.push(t.slice(n,n+u));t=e.join(`
`)+(t.length>0?`
`:``)}return{stdout:t,stderr:``,exitCode:0}}catch{return{stdout:``,stderr:`base64: invalid input
`,exitCode:1}}}},s={name:`base64`,flags:[{flag:`-d`,type:`boolean`},{flag:`-w`,type:`value`,valueHint:`number`}],stdinType:`text`,needsFiles:!0};export{s as n,o as t};
//# sourceMappingURL=chunk-QJ7O6ZN3-BCF2wp2J.mjs.map