@visulima/fs 5.0.9 → 5.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/eol.d.ts +25 -25
- package/dist/eol.js +2 -2
- package/dist/error.d.ts +218 -218
- package/dist/glob-parent.d.ts +27 -27
- package/dist/glob-parent.js +1 -1
- package/dist/glob.d.ts +2 -2
- package/dist/glob.js +1 -1
- package/dist/index.d.ts +765 -765
- package/dist/index.js +1 -1
- package/dist/ini.d.ts +59 -59
- package/dist/ini.js +1 -1
- package/dist/is-glob.d.ts +26 -26
- package/dist/json5.d.ts +25 -25
- package/dist/json5.js +1 -1
- package/dist/jsonc.d.ts +54 -54
- package/dist/jsonc.js +1 -1
- package/dist/match.d.ts +40 -40
- package/dist/packem_shared/{collect-CIKDOMiD.js → collect-B0S0bJoE.js} +1 -1
- package/dist/packem_shared/{collectSync-D0FRLLqg.js → collectSync-0M1eoilI.js} +1 -1
- package/dist/packem_shared/copy-DiR5_5iA.js +1 -0
- package/dist/packem_shared/copySync-DffsYlhb.js +1 -0
- package/dist/packem_shared/emptyDir-BlBeczk0.js +1 -0
- package/dist/packem_shared/emptyDirSync-DfUZ9Ejz.js +1 -0
- package/dist/packem_shared/ensureDir-BEiomfxz.js +1 -0
- package/dist/packem_shared/ensureDirSync-B0w9WMwE.js +1 -0
- package/dist/packem_shared/ensureFile-waD4hDO8.js +1 -0
- package/dist/packem_shared/ensureFileSync-CG07zjV7.js +1 -0
- package/dist/packem_shared/ensureLink-Dz-PDWa5.js +1 -0
- package/dist/packem_shared/ensureLinkSync-BZH7TaSQ.js +1 -0
- package/dist/packem_shared/ensureSymlink-Byi6ajoE.js +1 -0
- package/dist/packem_shared/ensureSymlinkSync-D7OCsAd8.js +1 -0
- package/dist/packem_shared/findUp-Ylerv_a2.js +1 -0
- package/dist/packem_shared/findUpSync-BWBPRzEq.js +1 -0
- package/dist/packem_shared/glob-BUjyjdE8.js +1 -0
- package/dist/packem_shared/glob-sync.d-DaAZHTsv.d.ts +54 -0
- package/dist/packem_shared/globSync-Bk9TUV7x.js +1 -0
- package/dist/packem_shared/index-CPZbuHkp.js +1 -0
- package/dist/packem_shared/isAccessible-B7guOm3k.js +1 -0
- package/dist/packem_shared/isAccessibleSync-XH4YleJW.js +1 -0
- package/dist/packem_shared/json-error.d-COL8oxF_.d.ts +52 -0
- package/dist/packem_shared/move-KhPRvsRd.js +1 -0
- package/dist/packem_shared/{parseJson-EASgP4J9.js → parseJson-_OfIPruP.js} +1 -1
- package/dist/packem_shared/readFile-VgxUDrNH.js +1 -0
- package/dist/packem_shared/readFileSync-CloFeQw8.js +1 -0
- package/dist/packem_shared/{readIni-BsXudu2r.js → readIni-CEXHWn92.js} +1 -1
- package/dist/packem_shared/readIniSync-DsxVHypc.js +1 -0
- package/dist/packem_shared/{readJson-CcAsHxE5.js → readJson-Q3T3RlSy.js} +1 -1
- package/dist/packem_shared/{readJson5-CM1TIiHd.js → readJson5-S68aVros.js} +1 -1
- package/dist/packem_shared/{readJson5Sync-Bc26c3Fy.js → readJson5Sync-Bi9Rv46R.js} +1 -1
- package/dist/packem_shared/{readJsonSync-DuMMeB3s.js → readJsonSync-BnWiH5-R.js} +1 -1
- package/dist/packem_shared/{readJsonc-BZjMw_0f.js → readJsonc-DSoFyuDk.js} +1 -1
- package/dist/packem_shared/{readJsoncSync-C-xzeZz4.js → readJsoncSync-CLtlvFKV.js} +1 -1
- package/dist/packem_shared/readToml-CN_xnICv.js +1 -0
- package/dist/packem_shared/readTomlSync-B9TVGzen.js +1 -0
- package/dist/packem_shared/{readYaml-DvPxndW_.js → readYaml-DcpUq11D.js} +1 -1
- package/dist/packem_shared/{readYamlSync-DZ-0hSbZ.js → readYamlSync-D5RVZwco.js} +1 -1
- package/dist/packem_shared/remove-D_CUIlBL.js +1 -0
- package/dist/packem_shared/removeSync-F4nKiwrU.js +1 -0
- package/dist/packem_shared/renderError-DjesnVYT-pWsLqw-_.js +6 -0
- package/dist/packem_shared/sanitize-aEqeyx4d.js +1 -0
- package/dist/packem_shared/to-uint-8-array-7sXMoZwU.js +1 -0
- package/dist/packem_shared/{types.d-BMdL_ygj.d.ts → types.d-D3Jo_iA-.d.ts} +361 -383
- package/dist/packem_shared/walk-BReeHTKb.js +1 -0
- package/dist/packem_shared/walkSync-yHJUIJb9.js +1 -0
- package/dist/packem_shared/writeFile-srDcYaRC.js +1 -0
- package/dist/packem_shared/writeFileSync-Ddl_u4my.js +1 -0
- package/dist/packem_shared/writeIni-CKinbquM.js +4 -0
- package/dist/packem_shared/writeIniSync-BISRFyg0.js +4 -0
- package/dist/packem_shared/writeJson-DlCrFMXb.js +4 -0
- package/dist/packem_shared/writeJson5-rSp3QAKP.js +4 -0
- package/dist/packem_shared/writeJson5Sync-tSBBKnaP.js +4 -0
- package/dist/packem_shared/writeJsonSync-CKqVRz_9.js +4 -0
- package/dist/packem_shared/writeJsonc-bxz1jdeU.js +4 -0
- package/dist/packem_shared/writeJsoncSync-C-W0H9qP.js +4 -0
- package/dist/packem_shared/{writeToml-IuMO-yDu.js → writeToml-CrpfWNyK.js} +1 -1
- package/dist/packem_shared/{writeTomlSync-DhL7hHzB.js → writeTomlSync-DveRchLG.js} +1 -1
- package/dist/packem_shared/{writeYaml-ClQgvQID.js → writeYaml-DvSQ_Jbn.js} +1 -1
- package/dist/packem_shared/{writeYamlSync-DrXtHQQq.js → writeYamlSync-CEf0PUGQ.js} +1 -1
- package/dist/size.d.ts +236 -236
- package/dist/size.js +1 -1
- package/dist/toml.d.ts +52 -52
- package/dist/toml.js +1 -1
- package/dist/utils.d.ts +88 -88
- package/dist/utils.js +1 -1
- package/dist/yaml.d.ts +2 -2
- package/dist/yaml.js +1 -1
- package/package.json +1 -1
- package/dist/packem_shared/copy-Beb64BYG.js +0 -1
- package/dist/packem_shared/copySync-CagcIEBi.js +0 -1
- package/dist/packem_shared/emptyDir-C7lyd1lW.js +0 -1
- package/dist/packem_shared/emptyDirSync-B8EYpmO9.js +0 -1
- package/dist/packem_shared/ensureDir-DGarVZw8.js +0 -1
- package/dist/packem_shared/ensureDirSync-CsgPrsDH.js +0 -1
- package/dist/packem_shared/ensureFile-CMugWljp.js +0 -1
- package/dist/packem_shared/ensureFileSync-CJYTEx2r.js +0 -1
- package/dist/packem_shared/ensureLink-ChShf3lf.js +0 -1
- package/dist/packem_shared/ensureLinkSync-DPpq0I2Z.js +0 -1
- package/dist/packem_shared/ensureSymlink-y4FZjfxA.js +0 -1
- package/dist/packem_shared/ensureSymlinkSync-TcHssCH7.js +0 -1
- package/dist/packem_shared/findUp-Cii5ATt5.js +0 -1
- package/dist/packem_shared/findUpSync-C9Lkh7-v.js +0 -1
- package/dist/packem_shared/glob-DMbPwGSj.js +0 -1
- package/dist/packem_shared/glob-sync.d-hXe38TnZ.d.ts +0 -54
- package/dist/packem_shared/globSync-DiP2rtGn.js +0 -1
- package/dist/packem_shared/index-Ct4GqZSP.js +0 -1
- package/dist/packem_shared/isAccessible-PmWJhV6I.js +0 -1
- package/dist/packem_shared/isAccessibleSync-BrbOtwdr.js +0 -1
- package/dist/packem_shared/json-error.d-DVILOyHc.d.ts +0 -52
- package/dist/packem_shared/move-DopmzT-2.js +0 -1
- package/dist/packem_shared/readFile-BswaBgM0.js +0 -1
- package/dist/packem_shared/readFileSync-_fDF6Oj1.js +0 -1
- package/dist/packem_shared/readIniSync-DKwRbbs9.js +0 -1
- package/dist/packem_shared/readToml-D4jpe9q_.js +0 -1
- package/dist/packem_shared/readTomlSync-B5PIYT9z.js +0 -1
- package/dist/packem_shared/remove-CSbrd0dl.js +0 -1
- package/dist/packem_shared/removeSync-BoLAzRQE.js +0 -1
- package/dist/packem_shared/renderError-B3ePOoBG-Bi9WKMjv.js +0 -6
- package/dist/packem_shared/sanitize-DGZ3w-_w.js +0 -1
- package/dist/packem_shared/to-uint-8-array-BImOQNXm.js +0 -1
- package/dist/packem_shared/walk-OX4-6oCP.js +0 -1
- package/dist/packem_shared/walkSync-BPs6czIM.js +0 -1
- package/dist/packem_shared/writeFile-BrMtsJY7.js +0 -1
- package/dist/packem_shared/writeFileSync-W7Mf4BNy.js +0 -1
- package/dist/packem_shared/writeIni-BWX3cP1K.js +0 -4
- package/dist/packem_shared/writeIniSync-fOdgPFfL.js +0 -4
- package/dist/packem_shared/writeJson-bEVi25gX.js +0 -4
- package/dist/packem_shared/writeJson5-Ch8TpNPI.js +0 -4
- package/dist/packem_shared/writeJson5Sync-BrctV_Mk.js +0 -4
- package/dist/packem_shared/writeJsonSync-DkGnd416.js +0 -4
- package/dist/packem_shared/writeJsonc-CefrwsOc.js +0 -4
- package/dist/packem_shared/writeJsoncSync-BskDjn8o.js +0 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as x}from"node:module";import{resolve as $,join as P,normalize as R,basename as z}from"@visulima/path";import{toPath as B}from"@visulima/path/utils";import j from"./WalkError-B8qTd-v-.js";import E from"./assertValidFileOrDirectoryPath-BTlt945W.js";import{a as D,s as m,l as p}from"./walk-include-BXhGSn6t.js";let F;const T=e=>(F??=x(import.meta.url))(e),c=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,I=e=>{if(typeof c<"u"&&c.versions&&c.versions.node){const[t,s]=c.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return c.getBuiltinModule(e)}return T(e)},{readdir:q,realpath:N,stat:S}=I("node:fs/promises"),M=async e=>{const t=R(e),s=z(t),r=await S(t);return p(r,s,t)};async function*L(e,t={}){const{extensions:s,followSymlinks:r=!1,includeDirs:y=!0,includeFiles:_=!0,includeSymlinks:h=!0,match:w,maxDepth:u=Number.POSITIVE_INFINITY,skip:v}=t;if(E(e),u<0)return;const d=t.visited??new Set,l=w?w.map(i=>typeof i=="string"?D(i):i):void 0,a=v?v.map(i=>typeof i=="string"?D(i):i):void 0;if(e=$(B(e)),y&&m(e,s,l,a)&&(yield await M(e)),!(u<1||!m(e,void 0,void 0,a)))try{const i=await q(e,{withFileTypes:!0});for(const o of i){let n=P(e,o.name),g=o.isDirectory(),k=o.isFile();if(o.isSymbolicLink())if(r){const f=await N(n);if(d.has(f))continue;n=f;const b=await S(f);g=b.isDirectory(),k=b.isFile()}else if(h&&m(n,s,l,a)){yield p(o,o.name,n);continue}else continue;g?(r&&d.add(n),yield*L(n,{extensions:s,followSymlinks:r,includeDirs:y,includeFiles:_,includeSymlinks:h,match:l,maxDepth:u-1,skip:a,visited:d})):k&&_&&m(n,s,l,a)&&(yield p(o,o.name,n))}}catch(i){throw i instanceof j?i:new j(i,e)}}export{L as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as T}from"node:module";import{resolve as R,join as $,normalize as p,basename as z}from"@visulima/path";import{toPath as B}from"@visulima/path/utils";import D from"./WalkError-B8qTd-v-.js";import E from"./assertValidFileOrDirectoryPath-BTlt945W.js";import{a as F,s as a,l as y}from"./walk-include-BXhGSn6t.js";let x;const I=e=>(x??=T(import.meta.url))(e),c=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,q=e=>{if(typeof c<"u"&&c.versions&&c.versions.node){const[o,t]=c.versions.node.split(".").map(Number);if(o>22||o===22&&t>=3||o===20&&t>=16)return c.getBuiltinModule(e)}return I(e)},{readdirSync:N,realpathSync:P,statSync:w}=q("node:fs"),M=e=>{const o=p(e),t=w(o);return y(t,z(o),o)};function*L(e,o={}){const{extensions:t,followSymlinks:m=!1,includeDirs:_=!0,includeFiles:h=!0,includeSymlinks:S=!0,match:v,maxDepth:u=Number.POSITIVE_INFINITY,skip:g}=o;if(E(e),u<0)return;const d=o.visited??new Set,l=v?v.map(i=>typeof i=="string"?F(i):i):void 0,r=g?g.map(i=>typeof i=="string"?F(i):i):void 0;if(e=R(B(e)),_&&a(e,t,l,r)&&(yield M(e)),!(u<1||!a(e,void 0,void 0,r)))try{const i=N(e,{withFileTypes:!0});for(const n of i){let s=$(e,n.name),k=n.isDirectory(),b=n.isFile();if(n.isSymbolicLink())if(m){const f=P(s);if(d.has(f))continue;s=f;const j=w(f);k=j.isDirectory(),b=j.isFile()}else if(S&&a(s,t,l,r)){yield y(n,n.name,p(s));continue}else continue;k?(m&&d.add(s),yield*L(s,{extensions:t,followSymlinks:m,includeDirs:_,includeFiles:h,includeSymlinks:S,match:l,maxDepth:u-1,skip:r,visited:d})):b&&h&&a(s,t,l,r)&&(yield y(n,n.name,p(s)))}}catch(i){throw i instanceof D?i:new D(i,e)}}export{L as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as f}from"node:module";import{dirname as y}from"@visulima/path";import{toPath as v}from"@visulima/path/utils";import{F_OK as b}from"./FIND_UP_STOP-CAwY1qU7.js";import j from"./AlreadyExistsError-DEb3UWja.js";import c from"./isAccessible-B7guOm3k.js";import k from"./assertValidFileContents-CbIN7sy7.js";import q from"./assertValidFileOrDirectoryPath-BTlt945W.js";import{o as x,i as B}from"./to-uint-8-array-7sXMoZwU.js";let m;const u=e=>(m??=f(import.meta.url))(e),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,d=e=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[t,i]=a.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return a.getBuiltinModule(e)}return u(e)},{mkdir:l,writeFile:w,stat:p,rename:n,chown:_,chmod:g,unlink:h}=d("node:fs/promises"),z=async(e,t,i)=>{i={backup:!1,encoding:"utf8",flag:"w",overwrite:!0,recursive:!0,...i},q(e),k(t),e=v(e);const s=await c(e,b);if(s&&!i.overwrite)throw new j(`file already exists, open '${e}'`);const r=x(e);try{!s&&i.recursive&&await l(y(e),{recursive:!0});let o;if(await w(r,typeof t=="string"?Buffer.from(t,i.encoding??"utf8"):B(t),{flag:"wx"}),s&&i.backup&&(o=await p(e),i.chown??={gid:o.gid,uid:o.uid},await n(e,`${e}.bak`)),i.chown)try{await _(r,i.chown.uid,i.chown.gid)}catch{}await g(r,o&&!i.mode?o.mode:i.mode??438),await n(r,e)}catch(o){throw new Error(`Failed to write file at: ${e} - ${o.message}`,{cause:o})}finally{await c(r)&&await h(r)}};export{z as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as m}from"node:module";import{dirname as y}from"@visulima/path";import{toPath as v}from"@visulima/path/utils";import{F_OK as b}from"./FIND_UP_STOP-CAwY1qU7.js";import S from"./AlreadyExistsError-DEb3UWja.js";import f from"./isAccessibleSync-XH4YleJW.js";import j from"./assertValidFileContents-CbIN7sy7.js";import k from"./assertValidFileOrDirectoryPath-BTlt945W.js";import{o as q,i as x}from"./to-uint-8-array-7sXMoZwU.js";let u;const a=e=>(u??=m(import.meta.url))(e),n=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,d=e=>{if(typeof n<"u"&&n.versions&&n.versions.node){const[r,o]=n.versions.node.split(".").map(Number);if(r>22||r===22&&o>=3||r===20&&o>=16)return n.getBuiltinModule(e)}return a(e)},{mkdirSync:l,writeFileSync:p,statSync:_,renameSync:s,chownSync:g,chmodSync:h,unlinkSync:w}=d("node:fs"),N=(e,r,o)=>{o={backup:!1,encoding:"utf8",flag:"w",overwrite:!0,recursive:!0,...o},k(e),j(r),e=v(e);const c=f(e,b);if(c&&!o.overwrite)throw new S(`file already exists, open '${e}'`);const i=q(e);try{!c&&o.recursive&&l(y(e),{recursive:!0});let t;if(p(i,typeof r=="string"?Buffer.from(r,o.encoding??"utf8"):x(r),{flag:"wx"}),c&&o.backup&&(t=_(e),o.chown??={gid:t.gid,uid:t.uid},s(e,`${e}.bak`)),o.chown)try{g(i,o.chown.uid,o.chown.gid)}catch{}h(i,t&&!o.mode?t.mode:o.mode??438),s(i,e)}catch(t){throw new Error(`Failed to write file at: ${e} - ${t.message}`,{cause:t})}finally{f(i)&&w(i)}};export{N as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as q}from"node:module";import{parse as I,stringify as N}from"ini";import{R_OK as O}from"./FIND_UP_STOP-CAwY1qU7.js";import B from"./isAccessible-B7guOm3k.js";import{d as L,m as M}from"./ini-preserve-D1DopDLd.js";import P from"./writeFile-srDcYaRC.js";let A;const E=e=>(A??=q(import.meta.url))(e),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,R=e=>{if(typeof i<"u"&&i.versions&&i.versions.node){const[t,n]=i.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return i.getBuiltinModule(e)}return E(e)},{readFile:T}=R("node:fs/promises"),D=async(e,t,n={})=>{const{eol:_,preserveStyle:g=!0,whitespace:y,...h}=n,{align:w,bracketedArray:l,newline:b,platform:v,section:p,sort:j,...k}=h;let a=_,d=y,o,c;if(g&&await B(e,O))try{o=await T(e,"utf8"),c=I(o,{bracketedArray:l??!0});const r=L(o);a??=r.eol,d??=r.whitespace}catch(r){if(r.code!=="ENOENT")throw r}const f={align:w,bracketedArray:l,newline:b,platform:v,section:p,sort:j,whitespace:d},m=(r,u)=>N(r,u===void 0?f:{...f,section:u});let s;o!==void 0&&c?s=M(o,c,t,m,{eol:a??`
|
|
2
|
+
`}):(s=m(t,p),a===`\r
|
|
3
|
+
`&&(s=s.replaceAll(/\r?\n/g,`\r
|
|
4
|
+
`))),await P(e,s,k)};export{D as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as q}from"node:module";import{parse as E,stringify as I}from"ini";import{R_OK as N}from"./FIND_UP_STOP-CAwY1qU7.js";import O from"./isAccessibleSync-XH4YleJW.js";import{d as B,m as L}from"./ini-preserve-D1DopDLd.js";import M from"./writeFileSync-Ddl_u4my.js";let R;const S=e=>(R??=q(import.meta.url))(e),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=e=>{if(typeof i<"u"&&i.versions&&i.versions.node){const[t,n]=i.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return i.getBuiltinModule(e)}return S(e)},{readFileSync:k}=T("node:fs"),D=(e,t,n={})=>{const{eol:_,preserveStyle:g=!0,whitespace:y,...h}=n,{align:b,bracketedArray:a,newline:v,platform:w,section:p,sort:j,...A}=h;let c=_,f=y,o,l;if(g&&O(e,N))try{o=k(e,"utf8"),l=E(o,{bracketedArray:a??!0});const r=B(o);c??=r.eol,f??=r.whitespace}catch(r){if(r.code!=="ENOENT")throw r}const d={align:b,bracketedArray:a,newline:v,platform:w,section:p,sort:j,whitespace:f},m=(r,u)=>I(r,u===void 0?d:{...d,section:u});let s;o!==void 0&&l?s=L(o,l,t,m,{eol:c??`
|
|
2
|
+
`}):(s=m(t,p),c===`\r
|
|
3
|
+
`&&(s=s.replaceAll(/\r?\n/g,`\r
|
|
4
|
+
`))),M(e,s,A)};export{D as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as l}from"node:module";import{k as j}from"./index-B2MhYg3r.js";import{R_OK as N}from"./FIND_UP_STOP-CAwY1qU7.js";import b from"./isAccessible-B7guOm3k.js";import q from"./writeFile-srDcYaRC.js";let _;const g=e=>(_??=l(import.meta.url))(e),o=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,h=e=>{if(typeof o<"u"&&o.versions&&o.versions.node){const[t,r]=o.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return o.getBuiltinModule(e)}return g(e)},{readFile:y}=h("node:fs/promises"),O=async(e,t,r={})=>{const{detectIndent:c,indent:a,replacer:f,stringify:d=JSON.stringify,...p}={indent:" ",...r};let s=a,n=`
|
|
2
|
+
`;if(await b(e,N))try{const i=await y(e,"utf8");if(c){const{indent:u}=j(i);s=u}n=i.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:""}catch(i){if(i.code!=="ENOENT")throw i}const m=d(t,f,s);await q(e,`${m}${n}`,p)};export{O as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as l}from"node:module";import{k as q}from"./index-B2MhYg3r.js";import y from"json5";import{R_OK as b}from"./FIND_UP_STOP-CAwY1qU7.js";import w from"./isAccessible-B7guOm3k.js";import N from"./writeFile-srDcYaRC.js";let _;const g=e=>(_??=l(import.meta.url))(e),r=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,h=e=>{if(typeof r<"u"&&r.versions&&r.versions.node){const[t,i]=r.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return r.getBuiltinModule(e)}return g(e)},{readFile:j}=h("node:fs/promises"),O=async(e,t,i={})=>{const{detectIndent:a,indent:f,quote:d,replacer:p,...u}={indent:" ",...i};let s=f,n=`
|
|
2
|
+
`;if(await w(e,b))try{const o=await j(e,"utf8");if(a){const{indent:c}=q(o);c&&(s=c)}n=o.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:""}catch(o){if(o.code!=="ENOENT")throw o}const m=y.stringify(t,{quote:d,replacer:p,space:s});await N(e,`${m}${n}`,u)};export{O as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as a}from"node:module";import{k as q}from"./index-B2MhYg3r.js";import y from"json5";import{R_OK as b}from"./FIND_UP_STOP-CAwY1qU7.js";import R from"./isAccessibleSync-XH4YleJW.js";import T from"./writeFileSync-Ddl_u4my.js";let _;const g=e=>(_??=a(import.meta.url))(e),r=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,h=e=>{if(typeof r<"u"&&r.versions&&r.versions.node){const[t,s]=r.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return r.getBuiltinModule(e)}return g(e)},{readFileSync:j}=h("node:fs"),$=(e,t,s={})=>{const{detectIndent:f,indent:d,quote:p,replacer:u,...l}={indent:" ",...s};let i=d,n=`
|
|
2
|
+
`;if(R(e,b))try{const o=j(e,"utf8");if(f){const{indent:c}=q(o);c&&(i=c)}n=o.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:""}catch(o){if(o.code!=="ENOENT")throw o}const m=y.stringify(t,{quote:p,replacer:u,space:i});T(e,`${m}${n}`,l)};export{$ as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as _}from"node:module";import{k as j}from"./index-B2MhYg3r.js";import{R_OK as N}from"./FIND_UP_STOP-CAwY1qU7.js";import b from"./isAccessibleSync-XH4YleJW.js";import q from"./writeFileSync-Ddl_u4my.js";let a;const g=e=>(a??=_(import.meta.url))(e),r=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,h=e=>{if(typeof r<"u"&&r.versions&&r.versions.node){const[t,n]=r.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return r.getBuiltinModule(e)}return g(e)},{readFileSync:y}=h("node:fs"),B=(e,t,n={})=>{const{detectIndent:c,indent:f,replacer:d,stringify:l=JSON.stringify,...p}={indent:" ",...n};let i=f,s=`
|
|
2
|
+
`;if(b(e,N))try{const o=y(e,"utf8");if(c){const{indent:m}=j(o);i=m}s=o.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:""}catch(o){if(o.code!=="ENOENT")throw o}const u=l(t,d,i);q(e,`${u}${s}`,p)};export{B as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as f}from"node:module";import{k as h}from"./index-B2MhYg3r.js";import{R_OK as N}from"./FIND_UP_STOP-CAwY1qU7.js";import j from"./isAccessible-B7guOm3k.js";import{b as y}from"./jsonc-merge-Bkw73TLW.js";import T from"./writeFile-srDcYaRC.js";let _;const g=e=>(_??=f(import.meta.url))(e),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,w=e=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[t,n]=a.versions.node.split(".").map(Number);if(t>22||t===22&&n>=3||t===20&&n>=16)return a.getBuiltinModule(e)}return g(e)},{readFile:b}=w("node:fs/promises"),x=async(e,t,n)=>{let r,o=n,s=`
|
|
2
|
+
`;if(!await j(e,N))return{indent:o,trailingNewline:s};try{if(r=await b(e,"utf8"),t){const{indent:i}=h(r);i&&(o=i)}s=r.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:""}catch(i){if(i.code!=="ENOENT")throw i}return{existingText:r,indent:o,trailingNewline:s}},M=async(e,t,n={})=>{const{detectIndent:r,formattingOptions:o,indent:s,preserveComments:i=!0,replacer:c,...d}={indent:" ",...n},{existingText:l,indent:u,trailingNewline:m}=await x(e,r,s),p=y(l,t,i,u,m,o,c);await T(e,p,d)};export{M as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as a}from"node:module";import{k as b}from"./index-B2MhYg3r.js";import{R_OK as j}from"./FIND_UP_STOP-CAwY1qU7.js";import T from"./isAccessibleSync-XH4YleJW.js";import{b as x}from"./jsonc-merge-Bkw73TLW.js";import y from"./writeFileSync-Ddl_u4my.js";let _;const g=e=>(_??=a(import.meta.url))(e),c=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,h=e=>{if(typeof c<"u"&&c.versions&&c.versions.node){const[t,i]=c.versions.node.split(".").map(Number);if(t>22||t===22&&i>=3||t===20&&i>=16)return c.getBuiltinModule(e)}return g(e)},{readFileSync:N}=h("node:fs"),O=(e,t,i)=>{let r,o=i,s=`
|
|
2
|
+
`;if(!T(e,j))return{indent:o,trailingNewline:s};try{if(r=N(e,"utf8"),t){const{indent:n}=b(r);n&&(o=n)}s=r.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:""}catch(n){if(n.code!=="ENOENT")throw n}return{existingText:r,indent:o,trailingNewline:s}},M=(e,t,i={})=>{const{detectIndent:r,formattingOptions:o,indent:s,preserveComments:n=!0,replacer:d,...l}={indent:" ",...i},{existingText:u,indent:f,trailingNewline:m}=O(e,r,s),p=x(u,t,n,f,m,o,d);y(e,p,l)};export{M as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{stringify as a}from"smol-toml";import i from"./writeFile-
|
|
1
|
+
import{stringify as a}from"smol-toml";import i from"./writeFile-srDcYaRC.js";const s=async(t,o,r)=>{await i(t,a(o),r)};export{s as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{stringify as f}from"smol-toml";import i from"./writeFileSync-
|
|
1
|
+
import{stringify as f}from"smol-toml";import i from"./writeFileSync-Ddl_u4my.js";const p=(o,r,t)=>{i(o,f(r),t)};export{p as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{stringify as p}from"yaml";import t from"./writeFile-
|
|
1
|
+
import{stringify as p}from"yaml";import t from"./writeFile-srDcYaRC.js";async function l(c,i,e,f){let r,a,o;typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e!="function"?(r=e,a=r.replacer,o=r.space):typeof f=="object"?(r=f,a=e,o=r.space):(a=e,o=f);const n=p(i,a,o??r);await t(c,n,r)}export{l as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{stringify as n}from"yaml";import t from"./writeFileSync-
|
|
1
|
+
import{stringify as n}from"yaml";import t from"./writeFileSync-Ddl_u4my.js";function y(a,c,e,p){let r,o,f;typeof e=="object"&&e!==null&&!Array.isArray(e)&&typeof e!="function"?(r=e,o=r.replacer,f=r.space):typeof p=="object"?(r=p,o=e,f=r.space):(o=e,f=p);const i=n(c,o,f??r);t(a,i,r)}export{y as default};
|
package/dist/size.d.ts
CHANGED
|
@@ -2,255 +2,255 @@ import { Readable } from 'node:stream';
|
|
|
2
2
|
import { URL } from 'node:url';
|
|
3
3
|
import { BrotliOptions, ZlibOptions } from 'node:zlib';
|
|
4
4
|
/**
|
|
5
|
-
* Input type for size calculation functions.
|
|
6
|
-
* Can be a Buffer, Readable stream, URL object, or string (file path or content).
|
|
7
|
-
*/
|
|
5
|
+
* Input type for size calculation functions.
|
|
6
|
+
* Can be a Buffer, Readable stream, URL object, or string (file path or content).
|
|
7
|
+
*/
|
|
8
8
|
type SizeInput = Buffer | Readable | URL | string;
|
|
9
9
|
/**
|
|
10
|
-
* Input type for synchronous size calculation functions.
|
|
11
|
-
* Can be a Buffer, URL object, or string (file path or content).
|
|
12
|
-
*/
|
|
10
|
+
* Input type for synchronous size calculation functions.
|
|
11
|
+
* Can be a Buffer, URL object, or string (file path or content).
|
|
12
|
+
*/
|
|
13
13
|
type SizeInputSync = Buffer | URL | string;
|
|
14
14
|
/**
|
|
15
|
-
* Asynchronously calculates the gzipped size of the given input.
|
|
16
|
-
* The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
17
|
-
* Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
18
|
-
* @param input The input data to gzip and measure.
|
|
19
|
-
* @param [options] Optional Zlib options for gzip compression.
|
|
20
|
-
* @returns A promise that resolves with the gzipped size in bytes.
|
|
21
|
-
* @example
|
|
22
|
-
* ```javascript
|
|
23
|
-
* import { gzipSize } from "@visulima/fs";
|
|
24
|
-
* import { Readable } from "node:stream";
|
|
25
|
-
* import { writeFile, unlink } from "node:fs/promises";
|
|
26
|
-
* import { join } from "node:path";
|
|
27
|
-
*
|
|
28
|
-
* const text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
|
29
|
-
* const filePath = join("temp-file.txt");
|
|
30
|
-
*
|
|
31
|
-
* async function main() {
|
|
32
|
-
* // From Buffer
|
|
33
|
-
* const buffer = Buffer.from(text);
|
|
34
|
-
* console.log(`Gzip size of buffer: ${await gzipSize(buffer)} bytes`);
|
|
35
|
-
*
|
|
36
|
-
* // From string (content)
|
|
37
|
-
* console.log(`Gzip size of string content: ${await gzipSize(text)} bytes`);
|
|
38
|
-
*
|
|
39
|
-
* // From file path
|
|
40
|
-
* await writeFile(filePath, text);
|
|
41
|
-
* console.log(`Gzip size of file: ${await gzipSize(filePath)} bytes`);
|
|
42
|
-
*
|
|
43
|
-
* // From URL
|
|
44
|
-
* const fileUrl = new URL(`file://${filePath}`);
|
|
45
|
-
* console.log(`Gzip size of URL: ${await gzipSize(fileUrl)} bytes`);
|
|
46
|
-
*
|
|
47
|
-
* // From Readable stream
|
|
48
|
-
* const stream = Readable.from(text);
|
|
49
|
-
* console.log(`Gzip size of stream: ${await gzipSize(stream)} bytes`);
|
|
50
|
-
*
|
|
51
|
-
* await unlink(filePath); // Clean up temp file
|
|
52
|
-
* }
|
|
53
|
-
*
|
|
54
|
-
* main().catch(console.error);
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
15
|
+
* Asynchronously calculates the gzipped size of the given input.
|
|
16
|
+
* The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
17
|
+
* Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
18
|
+
* @param input The input data to gzip and measure.
|
|
19
|
+
* @param [options] Optional Zlib options for gzip compression.
|
|
20
|
+
* @returns A promise that resolves with the gzipped size in bytes.
|
|
21
|
+
* @example
|
|
22
|
+
* ```javascript
|
|
23
|
+
* import { gzipSize } from "@visulima/fs";
|
|
24
|
+
* import { Readable } from "node:stream";
|
|
25
|
+
* import { writeFile, unlink } from "node:fs/promises";
|
|
26
|
+
* import { join } from "node:path";
|
|
27
|
+
*
|
|
28
|
+
* const text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
|
29
|
+
* const filePath = join("temp-file.txt");
|
|
30
|
+
*
|
|
31
|
+
* async function main() {
|
|
32
|
+
* // From Buffer
|
|
33
|
+
* const buffer = Buffer.from(text);
|
|
34
|
+
* console.log(`Gzip size of buffer: ${await gzipSize(buffer)} bytes`);
|
|
35
|
+
*
|
|
36
|
+
* // From string (content)
|
|
37
|
+
* console.log(`Gzip size of string content: ${await gzipSize(text)} bytes`);
|
|
38
|
+
*
|
|
39
|
+
* // From file path
|
|
40
|
+
* await writeFile(filePath, text);
|
|
41
|
+
* console.log(`Gzip size of file: ${await gzipSize(filePath)} bytes`);
|
|
42
|
+
*
|
|
43
|
+
* // From URL
|
|
44
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
45
|
+
* console.log(`Gzip size of URL: ${await gzipSize(fileUrl)} bytes`);
|
|
46
|
+
*
|
|
47
|
+
* // From Readable stream
|
|
48
|
+
* const stream = Readable.from(text);
|
|
49
|
+
* console.log(`Gzip size of stream: ${await gzipSize(stream)} bytes`);
|
|
50
|
+
*
|
|
51
|
+
* await unlink(filePath); // Clean up temp file
|
|
52
|
+
* }
|
|
53
|
+
*
|
|
54
|
+
* main().catch(console.error);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
57
|
declare const gzipSize: (input: SizeInput, options?: ZlibOptions) => Promise<number>;
|
|
58
58
|
/**
|
|
59
|
-
* Asynchronously calculates the Brotli compressed size of the given input.
|
|
60
|
-
* The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
61
|
-
* Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
62
|
-
* @param input The input data to compress with Brotli and measure.
|
|
63
|
-
* @param [options] Optional Zlib options for Brotli compression.
|
|
64
|
-
* @returns A promise that resolves with the Brotli compressed size in bytes.
|
|
65
|
-
* @example
|
|
66
|
-
* ```javascript
|
|
67
|
-
* import { brotliSize } from "@visulima/fs";
|
|
68
|
-
* import { Readable } from "node:stream";
|
|
69
|
-
* import { writeFile, unlink } from "node:fs/promises";
|
|
70
|
-
* import { join } from "node:path";
|
|
71
|
-
*
|
|
72
|
-
* const text = "This is a test string for Brotli compression efficiency.";
|
|
73
|
-
* const filePath = join("temp-brotli-file.txt");
|
|
74
|
-
*
|
|
75
|
-
* async function main() {
|
|
76
|
-
* // From Buffer
|
|
77
|
-
* const buffer = Buffer.from(text);
|
|
78
|
-
* console.log(`Brotli size of buffer: ${await brotliSize(buffer)} bytes`);
|
|
79
|
-
*
|
|
80
|
-
* // From string (content)
|
|
81
|
-
* console.log(`Brotli size of string content: ${await brotliSize(text)} bytes`);
|
|
82
|
-
*
|
|
83
|
-
* // From file path
|
|
84
|
-
* await writeFile(filePath, text);
|
|
85
|
-
* console.log(`Brotli size of file: ${await brotliSize(filePath)} bytes`);
|
|
86
|
-
*
|
|
87
|
-
* // From URL
|
|
88
|
-
* const fileUrl = new URL(`file://${filePath}`);
|
|
89
|
-
* console.log(`Brotli size of URL: ${await brotliSize(fileUrl)} bytes`);
|
|
90
|
-
*
|
|
91
|
-
* // From Readable stream
|
|
92
|
-
* const stream = Readable.from(text);
|
|
93
|
-
* console.log(`Brotli size of stream: ${await brotliSize(stream)} bytes`);
|
|
94
|
-
*
|
|
95
|
-
* await unlink(filePath); // Clean up temp file
|
|
96
|
-
* }
|
|
97
|
-
*
|
|
98
|
-
* main().catch(console.error);
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
59
|
+
* Asynchronously calculates the Brotli compressed size of the given input.
|
|
60
|
+
* The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
61
|
+
* Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
62
|
+
* @param input The input data to compress with Brotli and measure.
|
|
63
|
+
* @param [options] Optional Zlib options for Brotli compression.
|
|
64
|
+
* @returns A promise that resolves with the Brotli compressed size in bytes.
|
|
65
|
+
* @example
|
|
66
|
+
* ```javascript
|
|
67
|
+
* import { brotliSize } from "@visulima/fs";
|
|
68
|
+
* import { Readable } from "node:stream";
|
|
69
|
+
* import { writeFile, unlink } from "node:fs/promises";
|
|
70
|
+
* import { join } from "node:path";
|
|
71
|
+
*
|
|
72
|
+
* const text = "This is a test string for Brotli compression efficiency.";
|
|
73
|
+
* const filePath = join("temp-brotli-file.txt");
|
|
74
|
+
*
|
|
75
|
+
* async function main() {
|
|
76
|
+
* // From Buffer
|
|
77
|
+
* const buffer = Buffer.from(text);
|
|
78
|
+
* console.log(`Brotli size of buffer: ${await brotliSize(buffer)} bytes`);
|
|
79
|
+
*
|
|
80
|
+
* // From string (content)
|
|
81
|
+
* console.log(`Brotli size of string content: ${await brotliSize(text)} bytes`);
|
|
82
|
+
*
|
|
83
|
+
* // From file path
|
|
84
|
+
* await writeFile(filePath, text);
|
|
85
|
+
* console.log(`Brotli size of file: ${await brotliSize(filePath)} bytes`);
|
|
86
|
+
*
|
|
87
|
+
* // From URL
|
|
88
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
89
|
+
* console.log(`Brotli size of URL: ${await brotliSize(fileUrl)} bytes`);
|
|
90
|
+
*
|
|
91
|
+
* // From Readable stream
|
|
92
|
+
* const stream = Readable.from(text);
|
|
93
|
+
* console.log(`Brotli size of stream: ${await brotliSize(stream)} bytes`);
|
|
94
|
+
*
|
|
95
|
+
* await unlink(filePath); // Clean up temp file
|
|
96
|
+
* }
|
|
97
|
+
*
|
|
98
|
+
* main().catch(console.error);
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
101
|
declare const brotliSize: (input: SizeInput, options?: BrotliOptions) => Promise<number>;
|
|
102
102
|
/**
|
|
103
|
-
* Asynchronously calculates the raw (uncompressed) size of the given input.
|
|
104
|
-
* The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
105
|
-
* Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
106
|
-
* @param input The input data to measure.
|
|
107
|
-
* @returns A promise that resolves with the raw size in bytes.
|
|
108
|
-
* @example
|
|
109
|
-
* ```javascript
|
|
110
|
-
* import { rawSize } from "@visulima/fs";
|
|
111
|
-
* import { Readable } from "node:stream";
|
|
112
|
-
* import { writeFile, unlink } from "node:fs/promises";
|
|
113
|
-
* import { join } from "node:path";
|
|
114
|
-
*
|
|
115
|
-
* const text = "Hello, World!";
|
|
116
|
-
* const filePath = join("temp-raw-file.txt");
|
|
117
|
-
*
|
|
118
|
-
* async function main() {
|
|
119
|
-
* // From Buffer
|
|
120
|
-
* const buffer = Buffer.from(text);
|
|
121
|
-
* console.log(`Raw size of buffer: ${await rawSize(buffer)} bytes`);
|
|
122
|
-
*
|
|
123
|
-
* // From string (content)
|
|
124
|
-
* console.log(`Raw size of string content: ${await rawSize(text)} bytes`);
|
|
125
|
-
*
|
|
126
|
-
* // From file path
|
|
127
|
-
* await writeFile(filePath, text);
|
|
128
|
-
* console.log(`Raw size of file: ${await rawSize(filePath)} bytes`);
|
|
129
|
-
*
|
|
130
|
-
* // From URL
|
|
131
|
-
* const fileUrl = new URL(`file://${filePath}`);
|
|
132
|
-
* console.log(`Raw size of URL: ${await rawSize(fileUrl)} bytes`);
|
|
133
|
-
*
|
|
134
|
-
* // From Readable stream
|
|
135
|
-
* const stream = Readable.from(text);
|
|
136
|
-
* console.log(`Raw size of stream: ${await rawSize(stream)} bytes`);
|
|
137
|
-
*
|
|
138
|
-
* await unlink(filePath); // Clean up temp file
|
|
139
|
-
* }
|
|
140
|
-
*
|
|
141
|
-
* main().catch(console.error);
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
103
|
+
* Asynchronously calculates the raw (uncompressed) size of the given input.
|
|
104
|
+
* The input can be a Buffer, a Readable stream, a URL object pointing to a file, or a string (file path or content).
|
|
105
|
+
* Uses memory-efficient streaming for files and streams to avoid loading entire contents into memory.
|
|
106
|
+
* @param input The input data to measure.
|
|
107
|
+
* @returns A promise that resolves with the raw size in bytes.
|
|
108
|
+
* @example
|
|
109
|
+
* ```javascript
|
|
110
|
+
* import { rawSize } from "@visulima/fs";
|
|
111
|
+
* import { Readable } from "node:stream";
|
|
112
|
+
* import { writeFile, unlink } from "node:fs/promises";
|
|
113
|
+
* import { join } from "node:path";
|
|
114
|
+
*
|
|
115
|
+
* const text = "Hello, World!";
|
|
116
|
+
* const filePath = join("temp-raw-file.txt");
|
|
117
|
+
*
|
|
118
|
+
* async function main() {
|
|
119
|
+
* // From Buffer
|
|
120
|
+
* const buffer = Buffer.from(text);
|
|
121
|
+
* console.log(`Raw size of buffer: ${await rawSize(buffer)} bytes`);
|
|
122
|
+
*
|
|
123
|
+
* // From string (content)
|
|
124
|
+
* console.log(`Raw size of string content: ${await rawSize(text)} bytes`);
|
|
125
|
+
*
|
|
126
|
+
* // From file path
|
|
127
|
+
* await writeFile(filePath, text);
|
|
128
|
+
* console.log(`Raw size of file: ${await rawSize(filePath)} bytes`);
|
|
129
|
+
*
|
|
130
|
+
* // From URL
|
|
131
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
132
|
+
* console.log(`Raw size of URL: ${await rawSize(fileUrl)} bytes`);
|
|
133
|
+
*
|
|
134
|
+
* // From Readable stream
|
|
135
|
+
* const stream = Readable.from(text);
|
|
136
|
+
* console.log(`Raw size of stream: ${await rawSize(stream)} bytes`);
|
|
137
|
+
*
|
|
138
|
+
* await unlink(filePath); // Clean up temp file
|
|
139
|
+
* }
|
|
140
|
+
*
|
|
141
|
+
* main().catch(console.error);
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
144
|
declare const rawSize: (input: SizeInput) => Promise<number>;
|
|
145
145
|
/**
|
|
146
|
-
* Synchronously calculates the gzipped size of the given input.
|
|
147
|
-
* The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
148
|
-
* Note: For Readable streams or very large files, consider using the asynchronous `gzipSize` function for better performance and to avoid blocking.
|
|
149
|
-
* @param input The input data to gzip and measure.
|
|
150
|
-
* @param [options] Optional Zlib options for gzip compression.
|
|
151
|
-
* @returns The gzipped size in bytes.
|
|
152
|
-
* @example
|
|
153
|
-
* ```javascript
|
|
154
|
-
* import { gzipSizeSync } from "@visulima/fs";
|
|
155
|
-
* import { writeFileSync, unlinkSync } from "node:fs";
|
|
156
|
-
* import { join } from "node:path";
|
|
157
|
-
*
|
|
158
|
-
* const text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
|
159
|
-
* const filePath = join("temp-sync-file.txt");
|
|
160
|
-
*
|
|
161
|
-
* // From Buffer
|
|
162
|
-
* const buffer = Buffer.from(text);
|
|
163
|
-
* console.log(`Sync Gzip size of buffer: ${gzipSizeSync(buffer)} bytes`);
|
|
164
|
-
*
|
|
165
|
-
* // From string (content)
|
|
166
|
-
* console.log(`Sync Gzip size of string content: ${gzipSizeSync(text)} bytes`);
|
|
167
|
-
*
|
|
168
|
-
* // From file path
|
|
169
|
-
* try {
|
|
170
|
-
* writeFileSync(filePath, text);
|
|
171
|
-
* console.log(`Sync Gzip size of file: ${gzipSizeSync(filePath)} bytes`);
|
|
172
|
-
*
|
|
173
|
-
* // From URL
|
|
174
|
-
* const fileUrl = new URL(`file://${filePath}`);
|
|
175
|
-
* console.log(`Sync Gzip size of URL: ${gzipSizeSync(fileUrl)} bytes`);
|
|
176
|
-
* } finally {
|
|
177
|
-
* try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
178
|
-
* }
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
146
|
+
* Synchronously calculates the gzipped size of the given input.
|
|
147
|
+
* The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
148
|
+
* Note: For Readable streams or very large files, consider using the asynchronous `gzipSize` function for better performance and to avoid blocking.
|
|
149
|
+
* @param input The input data to gzip and measure.
|
|
150
|
+
* @param [options] Optional Zlib options for gzip compression.
|
|
151
|
+
* @returns The gzipped size in bytes.
|
|
152
|
+
* @example
|
|
153
|
+
* ```javascript
|
|
154
|
+
* import { gzipSizeSync } from "@visulima/fs";
|
|
155
|
+
* import { writeFileSync, unlinkSync } from "node:fs";
|
|
156
|
+
* import { join } from "node:path";
|
|
157
|
+
*
|
|
158
|
+
* const text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
|
|
159
|
+
* const filePath = join("temp-sync-file.txt");
|
|
160
|
+
*
|
|
161
|
+
* // From Buffer
|
|
162
|
+
* const buffer = Buffer.from(text);
|
|
163
|
+
* console.log(`Sync Gzip size of buffer: ${gzipSizeSync(buffer)} bytes`);
|
|
164
|
+
*
|
|
165
|
+
* // From string (content)
|
|
166
|
+
* console.log(`Sync Gzip size of string content: ${gzipSizeSync(text)} bytes`);
|
|
167
|
+
*
|
|
168
|
+
* // From file path
|
|
169
|
+
* try {
|
|
170
|
+
* writeFileSync(filePath, text);
|
|
171
|
+
* console.log(`Sync Gzip size of file: ${gzipSizeSync(filePath)} bytes`);
|
|
172
|
+
*
|
|
173
|
+
* // From URL
|
|
174
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
175
|
+
* console.log(`Sync Gzip size of URL: ${gzipSizeSync(fileUrl)} bytes`);
|
|
176
|
+
* } finally {
|
|
177
|
+
* try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
178
|
+
* }
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
181
|
declare const gzipSizeSync: (input: SizeInputSync, options?: ZlibOptions) => number;
|
|
182
182
|
/**
|
|
183
|
-
* Synchronously calculates the Brotli compressed size of the given input.
|
|
184
|
-
* The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
185
|
-
* Note: For Readable streams or very large files, consider using the asynchronous `brotliSize` function for better performance and to avoid blocking.
|
|
186
|
-
* @param input The input data to compress with Brotli and measure.
|
|
187
|
-
* @param [options] Optional Zlib options for Brotli compression.
|
|
188
|
-
* @returns The Brotli compressed size in bytes.
|
|
189
|
-
* @example
|
|
190
|
-
* ```javascript
|
|
191
|
-
* import { brotliSizeSync } from "@visulima/fs";
|
|
192
|
-
* import { writeFileSync, unlinkSync } from "node:fs";
|
|
193
|
-
* import { join } from "node:path";
|
|
194
|
-
*
|
|
195
|
-
* const text = "This is a test string for Brotli compression efficiency, synchronously.";
|
|
196
|
-
* const filePath = join("temp-brotli-sync-file.txt");
|
|
197
|
-
*
|
|
198
|
-
* // From Buffer
|
|
199
|
-
* const buffer = Buffer.from(text);
|
|
200
|
-
* console.log(`Sync Brotli size of buffer: ${brotliSizeSync(buffer)} bytes`);
|
|
201
|
-
*
|
|
202
|
-
* // From string (content)
|
|
203
|
-
* console.log(`Sync Brotli size of string content: ${brotliSizeSync(text)} bytes`);
|
|
204
|
-
*
|
|
205
|
-
* // From file path
|
|
206
|
-
* try {
|
|
207
|
-
* writeFileSync(filePath, text);
|
|
208
|
-
* console.log(`Sync Brotli size of file: ${brotliSizeSync(filePath)} bytes`);
|
|
209
|
-
*
|
|
210
|
-
* // From URL
|
|
211
|
-
* const fileUrl = new URL(`file://${filePath}`);
|
|
212
|
-
* console.log(`Sync Brotli size of URL: ${brotliSizeSync(fileUrl)} bytes`);
|
|
213
|
-
* } finally {
|
|
214
|
-
* try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
215
|
-
* }
|
|
216
|
-
* ```
|
|
217
|
-
*/
|
|
183
|
+
* Synchronously calculates the Brotli compressed size of the given input.
|
|
184
|
+
* The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
185
|
+
* Note: For Readable streams or very large files, consider using the asynchronous `brotliSize` function for better performance and to avoid blocking.
|
|
186
|
+
* @param input The input data to compress with Brotli and measure.
|
|
187
|
+
* @param [options] Optional Zlib options for Brotli compression.
|
|
188
|
+
* @returns The Brotli compressed size in bytes.
|
|
189
|
+
* @example
|
|
190
|
+
* ```javascript
|
|
191
|
+
* import { brotliSizeSync } from "@visulima/fs";
|
|
192
|
+
* import { writeFileSync, unlinkSync } from "node:fs";
|
|
193
|
+
* import { join } from "node:path";
|
|
194
|
+
*
|
|
195
|
+
* const text = "This is a test string for Brotli compression efficiency, synchronously.";
|
|
196
|
+
* const filePath = join("temp-brotli-sync-file.txt");
|
|
197
|
+
*
|
|
198
|
+
* // From Buffer
|
|
199
|
+
* const buffer = Buffer.from(text);
|
|
200
|
+
* console.log(`Sync Brotli size of buffer: ${brotliSizeSync(buffer)} bytes`);
|
|
201
|
+
*
|
|
202
|
+
* // From string (content)
|
|
203
|
+
* console.log(`Sync Brotli size of string content: ${brotliSizeSync(text)} bytes`);
|
|
204
|
+
*
|
|
205
|
+
* // From file path
|
|
206
|
+
* try {
|
|
207
|
+
* writeFileSync(filePath, text);
|
|
208
|
+
* console.log(`Sync Brotli size of file: ${brotliSizeSync(filePath)} bytes`);
|
|
209
|
+
*
|
|
210
|
+
* // From URL
|
|
211
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
212
|
+
* console.log(`Sync Brotli size of URL: ${brotliSizeSync(fileUrl)} bytes`);
|
|
213
|
+
* } finally {
|
|
214
|
+
* try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
215
|
+
* }
|
|
216
|
+
* ```
|
|
217
|
+
*/
|
|
218
218
|
declare const brotliSizeSync: (input: SizeInputSync, options?: BrotliOptions) => number;
|
|
219
219
|
/**
|
|
220
|
-
* Synchronously calculates the raw (uncompressed) size of the given input.
|
|
221
|
-
* The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
222
|
-
* For file paths, it uses `statSync` to get the file size.
|
|
223
|
-
* Note: For Readable streams or very large files, consider using the asynchronous `rawSize` function for better performance and to avoid blocking.
|
|
224
|
-
* @param input The input data to measure.
|
|
225
|
-
* @returns The raw size in bytes.
|
|
226
|
-
* @example
|
|
227
|
-
* ```javascript
|
|
228
|
-
* import { rawSizeSync } from "@visulima/fs";
|
|
229
|
-
* import { writeFileSync, unlinkSync } from "node:fs";
|
|
230
|
-
* import { join } from "node:path";
|
|
231
|
-
*
|
|
232
|
-
* const text = "Hello, Synchronous World!";
|
|
233
|
-
* const filePath = join("temp-raw-sync-file.txt");
|
|
234
|
-
*
|
|
235
|
-
* // From Buffer
|
|
236
|
-
* const buffer = Buffer.from(text);
|
|
237
|
-
* console.log(`Sync Raw size of buffer: ${rawSizeSync(buffer)} bytes`);
|
|
238
|
-
*
|
|
239
|
-
* // From string (content)
|
|
240
|
-
* console.log(`Sync Raw size of string content: ${rawSizeSync(text)} bytes`);
|
|
241
|
-
*
|
|
242
|
-
* // From file path
|
|
243
|
-
* try {
|
|
244
|
-
* writeFileSync(filePath, text);
|
|
245
|
-
* console.log(`Sync Raw size of file: ${rawSizeSync(filePath)} bytes`);
|
|
246
|
-
*
|
|
247
|
-
* // From URL
|
|
248
|
-
* const fileUrl = new URL(`file://${filePath}`);
|
|
249
|
-
* console.log(`Sync Raw size of URL: ${rawSizeSync(fileUrl)} bytes`);
|
|
250
|
-
* } finally {
|
|
251
|
-
* try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
252
|
-
* }
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
220
|
+
* Synchronously calculates the raw (uncompressed) size of the given input.
|
|
221
|
+
* The input can be a Buffer, a URL object pointing to a file, or a string (file path or content).
|
|
222
|
+
* For file paths, it uses `statSync` to get the file size.
|
|
223
|
+
* Note: For Readable streams or very large files, consider using the asynchronous `rawSize` function for better performance and to avoid blocking.
|
|
224
|
+
* @param input The input data to measure.
|
|
225
|
+
* @returns The raw size in bytes.
|
|
226
|
+
* @example
|
|
227
|
+
* ```javascript
|
|
228
|
+
* import { rawSizeSync } from "@visulima/fs";
|
|
229
|
+
* import { writeFileSync, unlinkSync } from "node:fs";
|
|
230
|
+
* import { join } from "node:path";
|
|
231
|
+
*
|
|
232
|
+
* const text = "Hello, Synchronous World!";
|
|
233
|
+
* const filePath = join("temp-raw-sync-file.txt");
|
|
234
|
+
*
|
|
235
|
+
* // From Buffer
|
|
236
|
+
* const buffer = Buffer.from(text);
|
|
237
|
+
* console.log(`Sync Raw size of buffer: ${rawSizeSync(buffer)} bytes`);
|
|
238
|
+
*
|
|
239
|
+
* // From string (content)
|
|
240
|
+
* console.log(`Sync Raw size of string content: ${rawSizeSync(text)} bytes`);
|
|
241
|
+
*
|
|
242
|
+
* // From file path
|
|
243
|
+
* try {
|
|
244
|
+
* writeFileSync(filePath, text);
|
|
245
|
+
* console.log(`Sync Raw size of file: ${rawSizeSync(filePath)} bytes`);
|
|
246
|
+
*
|
|
247
|
+
* // From URL
|
|
248
|
+
* const fileUrl = new URL(`file://${filePath}`);
|
|
249
|
+
* console.log(`Sync Raw size of URL: ${rawSizeSync(fileUrl)} bytes`);
|
|
250
|
+
* } finally {
|
|
251
|
+
* try { unlinkSync(filePath); } catch {} // Clean up temp file
|
|
252
|
+
* }
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
255
|
declare const rawSizeSync: (input: SizeInputSync) => number;
|
|
256
256
|
export { brotliSize, brotliSizeSync, gzipSize, gzipSizeSync, rawSize, rawSizeSync };
|
package/dist/size.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as S}from"node:module";import{toPath as f}from"@visulima/path/utils";const w=S(import.meta.url),o=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,i=t=>{if(typeof o<"u"&&o.versions&&o.versions.node){const[n,e]=o.versions.node.split(".").map(Number);if(n>22||n===22&&e>=3||n===20&&e>=16)return o.getBuiltinModule(t)}return w(t)},{readFileSync:
|
|
1
|
+
import{createRequire as S}from"node:module";import{toPath as f}from"@visulima/path/utils";let _;const w=t=>(_??=S(import.meta.url))(t),o=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,i=t=>{if(typeof o<"u"&&o.versions&&o.versions.node){const[n,e]=o.versions.node.split(".").map(Number);if(n>22||n===22&&e>=3||n===20&&e>=16)return o.getBuiltinModule(t)}return w(t)},{readFileSync:d,statSync:z,createReadStream:b,existsSync:y}=i("node:fs"),{isAbsolute:B,resolve:j}=i("node:path"),{Readable:R}=i("node:stream"),{URL:c}=i("node:url"),{brotliCompressSync:s,gzipSync:a,createGzip:q,createBrotliCompress:v}=i("node:zlib"),l=t=>{if(B(t))return y(t);try{return y(j(t))}catch{return!1}},P=async t=>{let n=0;for await(const e of t)n+=Buffer.from(e).length;return n},h=async(t,n)=>{let e=0;const r=n();return await new Promise((u,p)=>{r.on("data",m=>{e+=m.length}),r.on("end",()=>{u(e)}),r.on("error",p),t.on("error",p),t.pipe(r)})},g=async(t,n,e)=>{if(t instanceof c||typeof t=="string"){const r=f(t);if(l(r)){const u=b(r);return await e(u)}if(typeof t=="string")return n(Buffer.from(t))}return t instanceof R?await e(t):n(t)},C=async(t,n)=>await g(t,e=>a(e,n).length,async e=>await h(e,()=>q(n))),M=async(t,n)=>await g(t,e=>s(e,n).length,async e=>await h(e,()=>v(n))),A=async t=>await g(t,n=>n.length,async n=>await P(n)),F=(t,n)=>{if(t instanceof c||typeof t=="string"){const e=f(t);if(l(e))return a(d(e),n).length;if(typeof t=="string")return a(Buffer.from(t),n).length}return a(t,n).length},G=(t,n)=>{if(t instanceof c||typeof t=="string"){const e=f(t);if(l(e))return s(d(e),n).length;if(typeof t=="string")return s(Buffer.from(t),n).length}return s(t,n).length},L=t=>{if(t instanceof c||typeof t=="string"){const n=f(t);if(l(n))return z(n).size;if(typeof t=="string")return Buffer.from(t).length}return t.length};export{M as brotliSize,G as brotliSizeSync,C as gzipSize,F as gzipSizeSync,A as rawSize,L as rawSizeSync};
|