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