import{a as f}from"./chunk-HWKDQ44K.js";import{a as l,b as u}from"./chunk-74CEPOFO.js";import"./chunk-DXB73IDG.js";var g={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"]},b={decode:{short:"d",long:"decode",type:"boolean"},wrap:{short:"w",long:"wrap",type:"number",default:76}};async function p(r,o,a){if(o.length===0||o.length===1&&o[0]==="-")return{ok:!0,data:Uint8Array.from(r.stdin,e=>e.charCodeAt(0))};let s=[];for(let e of o){if(e==="-"){s.push(Uint8Array.from(r.stdin,t=>t.charCodeAt(0)));continue}try{let t=r.fs.resolvePath(r.cwd,e),n=await r.fs.readFileBuffer(t);s.push(n)}catch{return{ok:!1,error:{stdout:"",stderr:`${a}: ${e}: No such file or directory
`,exitCode:1}}}}let c=s.reduce((e,t)=>e+t.length,0),i=new Uint8Array(c),d=0;for(let e of s)i.set(e,d),d+=e.length;return{ok:!0,data:i}}var y={name:"base64",async execute(r,o){if(u(r))return l(g);let a=f("base64",r,b);if(!a.ok)return a.error;let s=a.result.flags.decode,c=a.result.flags.wrap,i=a.result.positional;try{if(s){let t=await p(o,i,"base64");if(!t.ok)return t.error;let h=String.fromCharCode(...t.data).replace(/\s/g,"");return{stdout:atob(h),stderr:"",exitCode:0}}let d=await p(o,i,"base64");if(!d.ok)return d.error;let e=btoa(String.fromCharCode(...d.data));if(c>0){let t=[];for(let n=0;n<e.length;n+=c)t.push(e.slice(n,n+c));e=t.join(`
`)+(e.length>0?`
`:"")}return{stdout:e,stderr:"",exitCode:0}}catch{return{stdout:"",stderr:`base64: invalid input
`,exitCode:1}}}};export{y as base64Command};
