import{n as e,r as t,t as n}from"./chunk-74CEPOFO-V0JXh91S.mjs";var r={name:`split`,summary:`split a file into pieces`,usage:`split [OPTION]... [FILE [PREFIX]]`,description:`Output pieces of FILE to PREFIXaa, PREFIXab, ...; default size is 1000 lines, and default PREFIX is 'x'.`,options:[`-l N         Put N lines per output file`,`-b SIZE      Put SIZE bytes per output file (K, M, G suffixes)`,`-n CHUNKS    Split into CHUNKS equal-sized files`,`-d           Use numeric suffixes (00, 01, ...) instead of alphabetic`,`-a LENGTH    Use suffixes of length LENGTH (default: 2)`,`--additional-suffix=SUFFIX  Append SUFFIX to file names`],examples:[`split -l 100 file.txt        # Split into 100-line chunks`,`split -b 1M file.bin         # Split into 1MB chunks`,`split -n 5 file.txt          # Split into 5 equal parts`,`split -d file.txt part_      # part_00, part_01, ...`,`split -a 3 -d file.txt x     # x000, x001, ...`]},i=1e5;function a(e){let t=e.match(/^(\d+)([KMGTPEZY]?)([B]?)$/i);if(!t)return null;let n=Number.parseInt(t[1],10);if(Number.isNaN(n)||n<1)return null;let r=(t[2]||``).toUpperCase(),i=new Map([[``,1],[`K`,1024],[`M`,1024*1024],[`G`,1024*1024*1024],[`T`,1024*1024*1024*1024],[`P`,1024*1024*1024*1024*1024]]).get(r);return i===void 0?null:n*i}function o(e,t,n){if(t)return e.toString().padStart(n,`0`);let r=``,i=e;for(let e=0;e<n;e++)r=`abcdefghijklmnopqrstuvwxyz`[i%26]+r,i=Math.floor(i/26);return r}function s(e,t){let n=e.split(`
`),r=e.endsWith(`
`)&&n[n.length-1]===``;r&&n.pop();let i=[];for(let e=0;e<n.length;e+=t){let a=n.slice(e,e+t),o=e+t>=n.length&&!r?a.join(`
`):`${a.join(`
`)}
`;i.push({content:o,hasContent:!0})}return i}function c(e,t){let n=new TextEncoder().encode(e),r=new TextDecoder,i=[];for(let e=0;e<n.length;e+=t){let a=n.slice(e,e+t);i.push({content:r.decode(a),hasContent:a.length>0})}return i}function l(e,t){let n=new TextEncoder().encode(e),r=new TextDecoder,i=[],a=Math.ceil(n.length/t);for(let e=0;e<t;e++){let t=e*a,o=Math.min(t+a,n.length),s=n.slice(t,o);i.push({content:r.decode(s),hasContent:s.length>0})}return i}var u={name:`split`,execute:async(u,d)=>{if(n(u))return t(r);let f={mode:`lines`,lines:1e3,bytes:0,chunks:0,useNumericSuffix:!1,suffixLength:2,additionalSuffix:``},p=[],m=0;for(;m<u.length;){let t=u[m];if(t===`-l`&&m+1<u.length){let e=Number.parseInt(u[m+1],10);if(Number.isNaN(e)||e<1)return{exitCode:1,stdout:``,stderr:`split: invalid number of lines: '${u[m+1]}'
`};f.mode=`lines`,f.lines=e,m+=2}else if(t.match(/^-l\d+$/)){let e=Number.parseInt(t.slice(2),10);if(Number.isNaN(e)||e<1)return{exitCode:1,stdout:``,stderr:`split: invalid number of lines: '${t.slice(2)}'
`};f.mode=`lines`,f.lines=e,m++}else if(t===`-b`&&m+1<u.length){let e=a(u[m+1]);if(e===null)return{exitCode:1,stdout:``,stderr:`split: invalid number of bytes: '${u[m+1]}'
`};f.mode=`bytes`,f.bytes=e,m+=2}else if(t.match(/^-b.+$/)){let e=a(t.slice(2));if(e===null)return{exitCode:1,stdout:``,stderr:`split: invalid number of bytes: '${t.slice(2)}'
`};f.mode=`bytes`,f.bytes=e,m++}else if(t===`-n`&&m+1<u.length){let e=Number.parseInt(u[m+1],10);if(Number.isNaN(e)||e<1)return{exitCode:1,stdout:``,stderr:`split: invalid number of chunks: '${u[m+1]}'
`};f.mode=`chunks`,f.chunks=e,m+=2}else if(t.match(/^-n\d+$/)){let e=Number.parseInt(t.slice(2),10);if(Number.isNaN(e)||e<1)return{exitCode:1,stdout:``,stderr:`split: invalid number of chunks: '${t.slice(2)}'
`};f.mode=`chunks`,f.chunks=e,m++}else if(t===`-a`&&m+1<u.length){let e=Number.parseInt(u[m+1],10);if(Number.isNaN(e)||e<1)return{exitCode:1,stdout:``,stderr:`split: invalid suffix length: '${u[m+1]}'
`};f.suffixLength=e,m+=2}else if(t.match(/^-a\d+$/)){let e=Number.parseInt(t.slice(2),10);if(Number.isNaN(e)||e<1)return{exitCode:1,stdout:``,stderr:`split: invalid suffix length: '${t.slice(2)}'
`};f.suffixLength=e,m++}else if(t===`-d`||t===`--numeric-suffixes`)f.useNumericSuffix=!0,m++;else if(t.startsWith(`--additional-suffix=`))f.additionalSuffix=t.slice(20),m++;else if(t===`--additional-suffix`&&m+1<u.length)f.additionalSuffix=u[m+1],m+=2;else if(t===`--`){p.push(...u.slice(m+1));break}else{if(t.startsWith(`-`)&&t!==`-`)return e(`split`,t);p.push(t),m++}}let h=`-`,g=`x`;p.length>=1&&(h=p[0]),p.length>=2&&(g=p[1]);let _;if(h===`-`)_=d.stdin??``;else{let e=d.fs.resolvePath(d.cwd,h),t=await d.fs.readFile(e);if(t===null)return{exitCode:1,stdout:``,stderr:`split: ${h}: No such file or directory
`};_=t}if(_===``)return{exitCode:0,stdout:``,stderr:``};let v;switch(f.mode){case`lines`:v=s(_,f.lines);break;case`bytes`:v=c(_,f.bytes);break;case`chunks`:v=l(_,f.chunks);break;default:return f.mode}if(v.length>i)return{exitCode:1,stdout:``,stderr:`split: too many output files (${v.length}), limit is ${i}
`};for(let e=0;e<v.length;e++){let t=v[e];if(!t.hasContent)continue;let n=o(e,f.useNumericSuffix,f.suffixLength),r=`${g}${n}${f.additionalSuffix}`,i=d.fs.resolvePath(d.cwd,r);await d.fs.writeFile(i,t.content)}return{exitCode:0,stdout:``,stderr:``}}},d={name:`split`,flags:[{flag:`-l`,type:`value`,valueHint:`number`},{flag:`-b`,type:`value`,valueHint:`string`},{flag:`-n`,type:`value`,valueHint:`number`},{flag:`-d`,type:`boolean`},{flag:`-a`,type:`value`,valueHint:`number`}],needsFiles:!0};export{u as n,d as t};
//# sourceMappingURL=chunk-MYE6AGBJ-DwzjGrc0.mjs.map