@visulima/fs 5.0.0-alpha.9 → 5.0.1
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 +461 -0
- package/LICENSE.md +81 -4
- package/README.md +65 -0
- package/dist/eol.d.ts +30 -0
- package/dist/eol.js +3 -26
- package/dist/error.d.ts +243 -13
- package/dist/error.js +1 -7
- package/dist/glob-parent.d.ts +30 -0
- package/dist/glob-parent.js +1 -90
- package/dist/glob.d.ts +3 -4
- package/dist/glob.js +1 -2
- package/dist/index.d.ts +877 -28
- package/dist/index.js +1 -38
- package/dist/ini.d.ts +64 -4
- package/dist/ini.js +1 -4
- package/dist/is-glob.d.ts +29 -0
- package/dist/is-glob.js +1 -9
- package/dist/json5.d.ts +28 -4
- package/dist/json5.js +1 -4
- package/dist/jsonc.d.ts +59 -4
- package/dist/jsonc.js +1 -4
- package/dist/match.d.ts +77 -2
- package/dist/match.js +1 -15
- package/dist/packem_shared/AlreadyExistsError-DEb3UWja.js +1 -0
- package/dist/packem_shared/DirectoryError-BtwSTLmT.js +1 -0
- package/dist/packem_shared/FIND_UP_STOP-CAwY1qU7.js +1 -0
- package/dist/packem_shared/JSONError-Cvp9ycba.js +4 -0
- package/dist/packem_shared/NotEmptyError-DZ1Ix089.js +1 -0
- package/dist/packem_shared/NotFoundError-CnRY6lVp.js +1 -0
- package/dist/packem_shared/PermissionError-DJ_2VWEj.js +1 -0
- package/dist/packem_shared/WalkError-B8qTd-v-.js +1 -0
- package/dist/packem_shared/_commonjsHelpers-CWAkuNXM.js +1 -0
- package/dist/packem_shared/assertValidFileContents-CbIN7sy7.js +1 -0
- package/dist/packem_shared/assertValidFileOrDirectoryPath-BTlt945W.js +1 -0
- package/dist/packem_shared/build-rm-options-avnusYx-.js +1 -0
- package/dist/packem_shared/collect-CIKDOMiD.js +1 -0
- package/dist/packem_shared/collectSync-D0FRLLqg.js +1 -0
- package/dist/packem_shared/copy-Beb64BYG.js +1 -0
- package/dist/packem_shared/copySync-CagcIEBi.js +1 -0
- package/dist/packem_shared/emptyDir-C7lyd1lW.js +1 -0
- package/dist/packem_shared/emptyDirSync-B8EYpmO9.js +1 -0
- package/dist/packem_shared/ensureDir-DGarVZw8.js +1 -0
- package/dist/packem_shared/ensureDirSync-CsgPrsDH.js +1 -0
- package/dist/packem_shared/ensureFile-CMugWljp.js +1 -0
- package/dist/packem_shared/ensureFileSync-CJYTEx2r.js +1 -0
- package/dist/packem_shared/ensureLink-ChShf3lf.js +1 -0
- package/dist/packem_shared/ensureLinkSync-DPpq0I2Z.js +1 -0
- package/dist/packem_shared/ensureSymlink-y4FZjfxA.js +1 -0
- package/dist/packem_shared/ensureSymlinkSync-TcHssCH7.js +1 -0
- package/dist/packem_shared/findUp-Cii5ATt5.js +1 -0
- package/dist/packem_shared/findUpSync-C9Lkh7-v.js +1 -0
- package/dist/packem_shared/get-file-info-type-DzWpohDB.js +1 -0
- package/dist/packem_shared/glob-DMbPwGSj.js +1 -0
- package/dist/packem_shared/glob-sync.d-hXe38TnZ.d.ts +54 -0
- package/dist/packem_shared/globSync-DiP2rtGn.js +1 -0
- package/dist/packem_shared/index-B2MhYg3r.js +1 -0
- package/dist/packem_shared/index-BHy3Kcr7.js +11 -0
- package/dist/packem_shared/index-Ct4GqZSP.js +1 -0
- package/dist/packem_shared/index-LUKYN3u3.js +1 -0
- package/dist/packem_shared/ini-preserve-D1DopDLd.js +4 -0
- package/dist/packem_shared/is-stats-identical-l1GRN4Qu.js +1 -0
- package/dist/packem_shared/isAccessible-PmWJhV6I.js +1 -0
- package/dist/packem_shared/isAccessibleSync-BrbOtwdr.js +1 -0
- package/dist/packem_shared/json-error.d-DVILOyHc.d.ts +52 -0
- package/dist/packem_shared/jsonc-merge-Bkw73TLW.js +2 -0
- package/dist/packem_shared/map-read-error-CR3rQUxx.js +1 -0
- package/dist/packem_shared/move-DopmzT-2.js +1 -0
- package/dist/packem_shared/parseJson-EASgP4J9.js +1 -0
- package/dist/packem_shared/readFile-BswaBgM0.js +1 -0
- package/dist/packem_shared/readFileSync-_fDF6Oj1.js +1 -0
- package/dist/packem_shared/readIni-BsXudu2r.js +1 -0
- package/dist/packem_shared/readIniSync-DKwRbbs9.js +1 -0
- package/dist/packem_shared/readJson-CcAsHxE5.js +1 -0
- package/dist/packem_shared/readJson5-CM1TIiHd.js +1 -0
- package/dist/packem_shared/readJson5Sync-Bc26c3Fy.js +1 -0
- package/dist/packem_shared/readJsonSync-DuMMeB3s.js +1 -0
- package/dist/packem_shared/readJsonc-BZjMw_0f.js +1 -0
- package/dist/packem_shared/readJsoncSync-C-xzeZz4.js +1 -0
- package/dist/packem_shared/readToml-D4jpe9q_.js +1 -0
- package/dist/packem_shared/readTomlSync-B5PIYT9z.js +1 -0
- package/dist/packem_shared/readYaml-DvPxndW_.js +1 -0
- package/dist/packem_shared/readYamlSync-DZ-0hSbZ.js +1 -0
- package/dist/packem_shared/remove-CSbrd0dl.js +1 -0
- package/dist/packem_shared/removeSync-BoLAzRQE.js +1 -0
- package/dist/packem_shared/renderError-B3ePOoBG-Bi9WKMjv.js +6 -0
- package/dist/packem_shared/resolve-symlink-target-CWrn0v4P.js +1 -0
- package/dist/packem_shared/sanitize-DGZ3w-_w.js +1 -0
- package/dist/packem_shared/stripJsonComments-Bfcn2PKv.js +1 -0
- package/dist/packem_shared/to-uint-8-array-BImOQNXm.js +1 -0
- package/dist/packem_shared/types.d-BMdL_ygj.d.ts +1773 -0
- package/dist/packem_shared/walk-OX4-6oCP.js +1 -0
- package/dist/packem_shared/walk-include-BXhGSn6t.js +1 -0
- package/dist/packem_shared/walkSync-BPs6czIM.js +1 -0
- package/dist/packem_shared/writeFile-BrMtsJY7.js +1 -0
- package/dist/packem_shared/writeFileSync-W7Mf4BNy.js +1 -0
- package/dist/packem_shared/writeIni-BWX3cP1K.js +4 -0
- package/dist/packem_shared/writeIniSync-fOdgPFfL.js +4 -0
- package/dist/packem_shared/writeJson-bEVi25gX.js +4 -0
- package/dist/packem_shared/writeJson5-Ch8TpNPI.js +4 -0
- package/dist/packem_shared/writeJson5Sync-BrctV_Mk.js +4 -0
- package/dist/packem_shared/writeJsonSync-DkGnd416.js +4 -0
- package/dist/packem_shared/writeJsonc-CefrwsOc.js +4 -0
- package/dist/packem_shared/writeJsoncSync-BskDjn8o.js +4 -0
- package/dist/packem_shared/writeToml-IuMO-yDu.js +1 -0
- package/dist/packem_shared/writeTomlSync-DhL7hHzB.js +1 -0
- package/dist/packem_shared/writeYaml-ClQgvQID.js +1 -0
- package/dist/packem_shared/writeYamlSync-DrXtHQQq.js +1 -0
- package/dist/size.d.ts +244 -0
- package/dist/size.js +1 -146
- package/dist/toml.d.ts +57 -3
- package/dist/toml.js +1 -4
- package/dist/utils.d.ts +92 -4
- package/dist/utils.js +1 -6
- package/dist/yaml.d.ts +3 -4
- package/dist/yaml.js +1 -4
- package/package.json +41 -44
- package/dist/packem_shared/AlreadyExistsError-6Y9hjgMn.js +0 -27
- package/dist/packem_shared/DirectoryError-BfYPkIYP.js +0 -27
- package/dist/packem_shared/F_OK-MldBaGxb.js +0 -8
- package/dist/packem_shared/JSONError-BkHRnInH.js +0 -26
- package/dist/packem_shared/NotEmptyError-B21RUlVr.js +0 -27
- package/dist/packem_shared/NotFoundError-BIp61X6k.js +0 -27
- package/dist/packem_shared/PermissionError-CjoiJgip.js +0 -27
- package/dist/packem_shared/WalkError-DER5A43G.js +0 -24
- package/dist/packem_shared/_commonjsHelpers-BqLXS_qQ.js +0 -5
- package/dist/packem_shared/assertValidFileContents-BmcLtsGd.js +0 -7
- package/dist/packem_shared/assertValidFileOrDirectoryPath-8HANmVjk.js +0 -7
- package/dist/packem_shared/build-rm-options-Cl3VDY4O.js +0 -12
- package/dist/packem_shared/collect-CqQ3eVab.js +0 -14
- package/dist/packem_shared/collectSync-noE08NNv.js +0 -14
- package/dist/packem_shared/emptyDir-DnwENOaV.js +0 -46
- package/dist/packem_shared/emptyDirSync-6WiHBo8a.js +0 -43
- package/dist/packem_shared/ensureDir-DNlPftys.js +0 -53
- package/dist/packem_shared/ensureDirSync-DcPZFMy5.js +0 -53
- package/dist/packem_shared/ensureFile-BRQpUOUM.js +0 -47
- package/dist/packem_shared/ensureFileSync-SBY7A9-C.js +0 -47
- package/dist/packem_shared/ensureLink-DJQeauEn.js +0 -55
- package/dist/packem_shared/ensureLinkSync-D9RVAglV.js +0 -55
- package/dist/packem_shared/ensureSymlink-CoRYDRwr.js +0 -80
- package/dist/packem_shared/ensureSymlinkSync-CFimFlgh.js +0 -81
- package/dist/packem_shared/findUp-YcNLKdfV.js +0 -84
- package/dist/packem_shared/findUpSync-BfA5fheN.js +0 -83
- package/dist/packem_shared/get-file-info-type-FD4-jsyg.js +0 -14
- package/dist/packem_shared/glob-DY8l7izD.js +0 -5
- package/dist/packem_shared/glob-sync.d-B83kqwUd.d.ts +0 -4
- package/dist/packem_shared/globSync-5P2KJf_g.js +0 -5
- package/dist/packem_shared/index-C8W8sfzP.js +0 -830
- package/dist/packem_shared/index-CHM-in-V.js +0 -100
- package/dist/packem_shared/index-bhgnhm4u.js +0 -167
- package/dist/packem_shared/index-xe4o3cYi.js +0 -1784
- package/dist/packem_shared/indexToLineColumn-BUb0GPKl-BF770uX7.js +0 -171
- package/dist/packem_shared/ini-preserve-Dq_Q_Jgb.js +0 -251
- package/dist/packem_shared/is-stats-identical-D8FxpvQU.js +0 -3
- package/dist/packem_shared/isAccessible-DuVrTNFV.js +0 -38
- package/dist/packem_shared/isAccessibleSync-DI8mM0fA.js +0 -38
- package/dist/packem_shared/isFsCaseSensitive-DunL7Iry.js +0 -62
- package/dist/packem_shared/json-error.d-DgKaeuIf.d.ts +0 -10
- package/dist/packem_shared/jsonc-merge-C6jWcfWh.js +0 -72
- package/dist/packem_shared/move-DbpW5_vA.js +0 -134
- package/dist/packem_shared/parseJson-BIp89Xjo.js +0 -63
- package/dist/packem_shared/readFile-Iz7kvCCk.js +0 -65
- package/dist/packem_shared/readFileSync-gm9yfIhh.js +0 -54
- package/dist/packem_shared/readIni-CJ2xfpjB.js +0 -10
- package/dist/packem_shared/readIniSync-9LUjaSSp.js +0 -10
- package/dist/packem_shared/readJson-C_rwm-wq.js +0 -22
- package/dist/packem_shared/readJson5-mBoTZppy.js +0 -15
- package/dist/packem_shared/readJson5Sync-8WS2yUok.js +0 -15
- package/dist/packem_shared/readJsonSync-BMEmCcJ6.js +0 -22
- package/dist/packem_shared/readJsonc-j-OS-APg.js +0 -28
- package/dist/packem_shared/readJsoncSync-Aw6EMlWO.js +0 -16
- package/dist/packem_shared/readToml-B2MHaSes.js +0 -9
- package/dist/packem_shared/readTomlSync-DNbK8NEb.js +0 -9
- package/dist/packem_shared/readYaml-D5q2a0e1.js +0 -10
- package/dist/packem_shared/readYamlSync-BKX-PAfq.js +0 -10
- package/dist/packem_shared/remove-C8_gl3jF.js +0 -39
- package/dist/packem_shared/removeSync-BJR_wTwN.js +0 -39
- package/dist/packem_shared/resolve-symlink-target-Kh4GovFf.js +0 -16
- package/dist/packem_shared/sanitize-BZoLN9Fg.js +0 -205
- package/dist/packem_shared/stripJsonComments-vo4k0mpF.js +0 -19
- package/dist/packem_shared/to-uint-8-array-Dz2nF1y1.js +0 -19
- package/dist/packem_shared/types.d-dP-lAGNn.d.ts +0 -145
- package/dist/packem_shared/walk-CSZgCuDx.js +0 -124
- package/dist/packem_shared/walk-include-CZco7BvN.js +0 -16
- package/dist/packem_shared/walkSync-C4Cy28xb.js +0 -123
- package/dist/packem_shared/writeFile-B8HX0JIQ.js +0 -81
- package/dist/packem_shared/writeFileSync-DB8vv8xR.js +0 -81
- package/dist/packem_shared/writeIni-i55QrL8y.js +0 -65
- package/dist/packem_shared/writeIniSync-CLqJE5t3.js +0 -64
- package/dist/packem_shared/writeJson-Bo7C2UHw.js +0 -50
- package/dist/packem_shared/writeJson5-vVmHUQOd.js +0 -53
- package/dist/packem_shared/writeJson5Sync-oJ546h5k.js +0 -53
- package/dist/packem_shared/writeJsonSync-BKZ_9Acr.js +0 -50
- package/dist/packem_shared/writeJsonc-BufH_oC5.js +0 -60
- package/dist/packem_shared/writeJsoncSync-DB9be1YL.js +0 -59
- package/dist/packem_shared/writeToml-DgTW_-7F.js +0 -8
- package/dist/packem_shared/writeTomlSync-DiBiE9ja.js +0 -8
- package/dist/packem_shared/writeYaml-BWCOome-.js +0 -24
- package/dist/packem_shared/writeYamlSync-DBVnXmuY.js +0 -24
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as x}from"node:module";import{resolve as $,join as q,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 S,s as m,l as p}from"./walk-include-BXhGSn6t.js";const F=x(import.meta.url),l=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=e=>{if(typeof l<"u"&&l.versions&&l.versions.node){const[t,o]=l.versions.node.split(".").map(Number);if(t>22||t===22&&o>=3||t===20&&o>=16)return l.getBuiltinModule(e)}return F(e)},{readdir:I,realpath:N,stat:j}=T("node:fs/promises"),M=async e=>{const t=P(e),o=z(t),r=await j(t);return p(r,o,t)};async function*R(e,t={}){const{extensions:o,followSymlinks:r=!1,includeDirs:y=!0,includeFiles:h=!0,includeSymlinks:_=!0,match:w,maxDepth:f=Number.POSITIVE_INFINITY,skip:v}=t;if(E(e),f<0)return;const u=t.visited??new Set,c=w?w.map(i=>typeof i=="string"?S(i):i):void 0,a=v?v.map(i=>typeof i=="string"?S(i):i):void 0;if(e=$(B(e)),y&&m(e,o,c,a)&&(yield await M(e)),!(f<1||!m(e,void 0,void 0,a)))try{const i=await I(e,{withFileTypes:!0});for(const s of i){let n=q(e,s.name),g=s.isDirectory(),k=s.isFile();if(s.isSymbolicLink())if(r){const d=await N(n);if(u.has(d))continue;n=d;const b=await j(d);g=b.isDirectory(),k=b.isFile()}else if(_&&m(n,o,c,a)){yield p(s,s.name,n);continue}else continue;g?(r&&u.add(n),yield*R(n,{extensions:o,followSymlinks:r,includeDirs:y,includeFiles:h,includeSymlinks:_,match:c,maxDepth:f-1,skip:a,visited:u})):k&&h&&m(n,o,c,a)&&(yield p(s,s.name,n))}}catch(i){throw i instanceof D?i:new D(i,e)}}export{R as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const i=e=>{const r=e.replace(/[$()+\\^]/g,String.raw`\$&`).replace(/\.\*/g,".([^/]*)").replace(/\*\*/g,"(.*)").replace(/(?<!\.)\*(?!\*)/g,"([^/]*)").replace(/\?/g,"[^/]").replace(/\.(?!\*)/g,String.raw`\.`).replace(/\{/g,"(").replace(/\}/g,")").replace(/,/g,"|").replace(/\[!(.*?)\]/g,"[^$1]");try{return new RegExp(`^${r}$`)}catch(t){throw new Error(`Invalid glob pattern: ${e}`,{cause:t})}};class c{name;path;#e;constructor(r,t,n){this.#e=r,this.name=t,this.path=n}isDirectory(){return this.#e.isDirectory()}isFile(){return this.#e.isFile()}isSymbolicLink(){return this.#e.isSymbolicLink()}}const l=(e,r,t)=>new c(e,r,t),o=(e,r,t,n)=>{if(Array.isArray(r)&&r.length>0&&!r.some(s=>e.endsWith(s)))return!1;const a=e.includes("\\")?e.replaceAll("\\","/"):e;return t&&!t.some(s=>s.test(a))?!1:!n?.some(s=>s.test(a))};export{i as a,l,o as s};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as T}from"node:module";import{resolve as P,join as $,normalize as p,basename as z}from"@visulima/path";import{toPath as B}from"@visulima/path/utils";import F from"./WalkError-B8qTd-v-.js";import E from"./assertValidFileOrDirectoryPath-BTlt945W.js";import{a as j,s as m,l as y}from"./walk-include-BXhGSn6t.js";const x=T(import.meta.url),c=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,I=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 x(e)},{readdirSync:N,realpathSync:q,statSync:w}=I("node:fs"),M=e=>{const o=p(e),t=w(o);return y(t,z(o),o)};function*R(e,o={}){const{extensions:t,followSymlinks:a=!1,includeDirs:h=!0,includeFiles:_=!0,includeSymlinks:S=!0,match:v,maxDepth:f=Number.POSITIVE_INFINITY,skip:g}=o;if(E(e),f<0)return;const d=o.visited??new Set,l=v?v.map(i=>typeof i=="string"?j(i):i):void 0,r=g?g.map(i=>typeof i=="string"?j(i):i):void 0;if(e=P(B(e)),h&&m(e,t,l,r)&&(yield M(e)),!(f<1||!m(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(a){const u=q(s);if(d.has(u))continue;s=u;const D=w(u);k=D.isDirectory(),b=D.isFile()}else if(S&&m(s,t,l,r)){yield y(n,n.name,p(s));continue}else continue;k?(a&&d.add(s),yield*R(s,{extensions:t,followSymlinks:a,includeDirs:h,includeFiles:_,includeSymlinks:S,match:l,maxDepth:f-1,skip:r,visited:d})):b&&_&&m(s,t,l,r)&&(yield y(n,n.name,p(s)))}}catch(i){throw i instanceof F?i:new F(i,e)}}export{R as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as f}from"node:module";import{dirname as _}from"@visulima/path";import{toPath as y}from"@visulima/path/utils";import{F_OK as v}from"./FIND_UP_STOP-CAwY1qU7.js";import b from"./AlreadyExistsError-DEb3UWja.js";import c from"./isAccessible-PmWJhV6I.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-BImOQNXm.js";const m=f(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=i=>{if(typeof a<"u"&&a.versions&&a.versions.node){const[e,o]=a.versions.node.split(".").map(Number);if(e>22||e===22&&o>=3||e===20&&o>=16)return a.getBuiltinModule(i)}return m(i)},{mkdir:d,writeFile:w,stat:l,rename:n,chown:p,chmod:g,unlink:h}=u("node:fs/promises"),O=async(i,e,o)=>{o={backup:!1,encoding:"utf8",flag:"w",overwrite:!0,recursive:!0,...o},k(i),j(e),i=y(i);const s=await c(i,v);if(s&&!o.overwrite)throw new b(`file already exists, open '${i}'`);const r=q(i);try{!s&&o.recursive&&await d(_(i),{recursive:!0});let t;if(await w(r,typeof e=="string"?Buffer.from(e,o.encoding??"utf8"):x(e),{flag:"wx"}),s&&o.backup&&(t=await l(i),o.chown??={gid:t.gid,uid:t.uid},await n(i,`${i}.bak`)),o.chown)try{await p(r,o.chown.uid,o.chown.gid)}catch{}await g(r,t&&!o.mode?t.mode:o.mode??438),await n(r,i)}catch(t){throw new Error(`Failed to write file at: ${i} - ${t.message}`,{cause:t})}finally{await c(r)&&await h(r)}};export{O as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as m}from"node:module";import{dirname as h}from"@visulima/path";import{toPath as _}from"@visulima/path/utils";import{F_OK as v}from"./FIND_UP_STOP-CAwY1qU7.js";import b from"./AlreadyExistsError-DEb3UWja.js";import f from"./isAccessibleSync-BrbOtwdr.js";import S from"./assertValidFileContents-CbIN7sy7.js";import j from"./assertValidFileOrDirectoryPath-BTlt945W.js";import{o as k,i as q}from"./to-uint-8-array-BImOQNXm.js";const a=m(import.meta.url),n=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,u=e=>{if(typeof n<"u"&&n.versions&&n.versions.node){const[i,o]=n.versions.node.split(".").map(Number);if(i>22||i===22&&o>=3||i===20&&o>=16)return n.getBuiltinModule(e)}return a(e)},{mkdirSync:d,writeFileSync:l,statSync:p,renameSync:s,chownSync:g,chmodSync:w,unlinkSync:y}=u("node:fs"),K=(e,i,o)=>{o={backup:!1,encoding:"utf8",flag:"w",overwrite:!0,recursive:!0,...o},j(e),S(i),e=_(e);const c=f(e,v);if(c&&!o.overwrite)throw new b(`file already exists, open '${e}'`);const r=k(e);try{!c&&o.recursive&&d(h(e),{recursive:!0});let t;if(l(r,typeof i=="string"?Buffer.from(i,o.encoding??"utf8"):q(i),{flag:"wx"}),c&&o.backup&&(t=p(e),o.chown??={gid:t.gid,uid:t.uid},s(e,`${e}.bak`)),o.chown)try{g(r,o.chown.uid,o.chown.gid)}catch{}w(r,t&&!o.mode?t.mode:o.mode??438),s(r,e)}catch(t){throw new Error(`Failed to write file at: ${e} - ${t.message}`,{cause:t})}finally{f(r)&&y(r)}};export{K as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as A}from"node:module";import{parse as I,stringify as N}from"ini";import{R_OK as O}from"./FIND_UP_STOP-CAwY1qU7.js";import R from"./isAccessible-PmWJhV6I.js";import{d as B,m as L}from"./ini-preserve-D1DopDLd.js";import M from"./writeFile-BrMtsJY7.js";const E=A(import.meta.url),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,T=r=>{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(r)}return E(r)},{readFile:q}=T("node:fs/promises"),C=async(r,t,n={})=>{const{eol:g,preserveStyle:_=!0,whitespace:y,...w}=n,{align:h,bracketedArray:l,newline:b,platform:v,section:p,sort:j,...k}=w;let a=g,f=y,o,c;if(_&&await R(r,O))try{o=await q(r,"utf8"),c=I(o,{bracketedArray:l??!0});const e=B(o);a??=e.eol,f??=e.whitespace}catch(e){if(e.code!=="ENOENT")throw e}const m={align:h,bracketedArray:l,newline:b,platform:v,section:p,sort:j,whitespace:f},d=(e,u)=>N(e,u===void 0?m:{...m,section:u});let s;o!==void 0&&c?s=L(o,c,t,d,{eol:a??`
|
|
2
|
+
`}):(s=d(t,p),a===`\r
|
|
3
|
+
`&&(s=s.replaceAll(/\r?\n/g,`\r
|
|
4
|
+
`))),await M(r,s,k)};export{C as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as S}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-BrbOtwdr.js";import{d as R,m as B}from"./ini-preserve-D1DopDLd.js";import L from"./writeFileSync-W7Mf4BNy.js";const T=S(import.meta.url),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,k=r=>{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(r)}return T(r)},{readFileSync:q}=k("node:fs"),C=(r,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(r,N))try{o=q(r,"utf8"),l=E(o,{bracketedArray:a??!0});const e=R(o);c??=e.eol,f??=e.whitespace}catch(e){if(e.code!=="ENOENT")throw e}const m={align:b,bracketedArray:a,newline:v,platform:w,section:p,sort:j,whitespace:f},d=(e,u)=>I(e,u===void 0?m:{...m,section:u});let s;o!==void 0&&l?s=B(o,l,t,d,{eol:c??`
|
|
2
|
+
`}):(s=d(t,p),c===`\r
|
|
3
|
+
`&&(s=s.replaceAll(/\r?\n/g,`\r
|
|
4
|
+
`))),L(r,s,A)};export{C as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as u}from"node:module";import{k as h}from"./index-B2MhYg3r.js";import{R_OK as j}from"./FIND_UP_STOP-CAwY1qU7.js";import N from"./isAccessible-PmWJhV6I.js";import b from"./writeFile-BrMtsJY7.js";const _=u(import.meta.url),i=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,g=e=>{if(typeof i<"u"&&i.versions&&i.versions.node){const[t,s]=i.versions.node.split(".").map(Number);if(t>22||t===22&&s>=3||t===20&&s>=16)return i.getBuiltinModule(e)}return _(e)},{readFile:y}=g("node:fs/promises"),O=async(e,t,s={})=>{const{detectIndent:c,indent:a,replacer:f,stringify:d=JSON.stringify,...p}={indent:" ",...s};let r=a,n=`
|
|
2
|
+
`;if(await N(e,j))try{const o=await y(e,"utf8");if(c){const{indent:l}=h(o);r=l}n=o.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:""}catch(o){if(o.code!=="ENOENT")throw o}const m=d(t,f,r);await b(e,`${m}${n}`,p)};export{O as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as l}from"node:module";import{k as y}from"./index-B2MhYg3r.js";import j from"json5";import{R_OK as q}from"./FIND_UP_STOP-CAwY1qU7.js";import b from"./isAccessible-PmWJhV6I.js";import w from"./writeFile-BrMtsJY7.js";const _=l(import.meta.url),r=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,g=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 _(e)},{readFile:h}=g("node:fs/promises"),M=async(e,t,i={})=>{const{detectIndent:a,indent:f,quote:p,replacer:d,...m}={indent:" ",...i};let s=f,n=`
|
|
2
|
+
`;if(await b(e,q))try{const o=await h(e,"utf8");if(a){const{indent:c}=y(o);c&&(s=c)}n=o.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:""}catch(o){if(o.code!=="ENOENT")throw o}const u=j.stringify(t,{quote:p,replacer:d,space:s});await w(e,`${u}${n}`,m)};export{M as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as a}from"node:module";import{k as y}from"./index-B2MhYg3r.js";import j from"json5";import{R_OK as q}from"./FIND_UP_STOP-CAwY1qU7.js";import b from"./isAccessibleSync-BrbOtwdr.js";import T from"./writeFileSync-W7Mf4BNy.js";const _=a(import.meta.url),r=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,g=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 _(e)},{readFileSync:h}=g("node:fs"),O=(e,t,s={})=>{const{detectIndent:f,indent:d,quote:p,replacer:m,...u}={indent:" ",...s};let i=d,n=`
|
|
2
|
+
`;if(b(e,q))try{const o=h(e,"utf8");if(f){const{indent:c}=y(o);c&&(i=c)}n=o.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:""}catch(o){if(o.code!=="ENOENT")throw o}const l=j.stringify(t,{quote:p,replacer:m,space:i});T(e,`${l}${n}`,u)};export{O as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as a}from"node:module";import{k as h}from"./index-B2MhYg3r.js";import{R_OK as j}from"./FIND_UP_STOP-CAwY1qU7.js";import N from"./isAccessibleSync-BrbOtwdr.js";import b from"./writeFileSync-W7Mf4BNy.js";const _=a(import.meta.url),n=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,g=e=>{if(typeof n<"u"&&n.versions&&n.versions.node){const[t,r]=n.versions.node.split(".").map(Number);if(t>22||t===22&&r>=3||t===20&&r>=16)return n.getBuiltinModule(e)}return _(e)},{readFileSync:y}=g("node:fs"),$=(e,t,r={})=>{const{detectIndent:c,indent:f,replacer:d,stringify:p=JSON.stringify,...l}={indent:" ",...r};let i=f,s=`
|
|
2
|
+
`;if(N(e,j))try{const o=y(e,"utf8");if(c){const{indent:u}=h(o);i=u}s=o.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:""}catch(o){if(o.code!=="ENOENT")throw o}const m=p(t,d,i);b(e,`${m}${s}`,l)};export{$ as default};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{createRequire as u}from"node:module";import{k as b}from"./index-B2MhYg3r.js";import{R_OK as N}from"./FIND_UP_STOP-CAwY1qU7.js";import h from"./isAccessible-PmWJhV6I.js";import{b as y}from"./jsonc-merge-Bkw73TLW.js";import T from"./writeFile-BrMtsJY7.js";const _=u(import.meta.url),a=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,g=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 _(e)},{readFile:w}=g("node:fs/promises"),j=async(e,t,n)=>{let r,o=n,s=`
|
|
2
|
+
`;if(!await h(e,N))return{indent:o,trailingNewline:s};try{if(r=await w(e,"utf8"),t){const{indent:i}=b(r);i&&(o=i)}s=r.endsWith(`
|
|
3
|
+
`)?`
|
|
4
|
+
`:""}catch(i){if(i.code!=="ENOENT")throw i}return{existingText:r,indent:o,trailingNewline:s}},B=async(e,t,n={})=>{const{detectIndent:r,formattingOptions:o,indent:s,preserveComments:i=!0,replacer:c,...d}={indent:" ",...n},{existingText:l,indent:m,trailingNewline:p}=await j(e,r,s),f=y(l,t,i,m,p,o,c);await T(e,f,d)};export{B 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 h}from"./FIND_UP_STOP-CAwY1qU7.js";import T from"./isAccessibleSync-BrbOtwdr.js";import{b as j}from"./jsonc-merge-Bkw73TLW.js";import x from"./writeFileSync-W7Mf4BNy.js";const _=a(import.meta.url),c=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,g=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 _(e)},{readFileSync:N}=g("node:fs"),y=(e,t,i)=>{let r,o=i,s=`
|
|
2
|
+
`;if(!T(e,h))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}},E=(e,t,i={})=>{const{detectIndent:r,formattingOptions:o,indent:s,preserveComments:n=!0,replacer:d,...l}={indent:" ",...i},{existingText:f,indent:m,trailingNewline:p}=y(e,r,s),u=j(f,t,n,m,p,o,d);x(e,u,l)};export{E as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{stringify as a}from"smol-toml";import i from"./writeFile-BrMtsJY7.js";const s=async(t,o,r)=>{await i(t,a(o),r)};export{s as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{stringify as f}from"smol-toml";import i from"./writeFileSync-W7Mf4BNy.js";const p=(o,r,t)=>{i(o,f(r),t)};export{p as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{stringify as p}from"yaml";import t from"./writeFile-BrMtsJY7.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{stringify as n}from"yaml";import t from"./writeFileSync-W7Mf4BNy.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
|
@@ -1,12 +1,256 @@
|
|
|
1
1
|
import { Readable } from 'node:stream';
|
|
2
2
|
import { URL } from 'node:url';
|
|
3
3
|
import { BrotliOptions, ZlibOptions } from 'node:zlib';
|
|
4
|
+
/**
|
|
5
|
+
* Input type for size calculation functions.
|
|
6
|
+
* Can be a Buffer, Readable stream, URL object, or string (file path or content).
|
|
7
|
+
*/
|
|
4
8
|
type SizeInput = Buffer | Readable | URL | string;
|
|
9
|
+
/**
|
|
10
|
+
* Input type for synchronous size calculation functions.
|
|
11
|
+
* Can be a Buffer, URL object, or string (file path or content).
|
|
12
|
+
*/
|
|
5
13
|
type SizeInputSync = Buffer | URL | string;
|
|
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
|
+
*/
|
|
6
57
|
declare const gzipSize: (input: SizeInput, options?: ZlibOptions) => Promise<number>;
|
|
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
|
+
*/
|
|
7
101
|
declare const brotliSize: (input: SizeInput, options?: BrotliOptions) => Promise<number>;
|
|
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
|
+
*/
|
|
8
144
|
declare const rawSize: (input: SizeInput) => Promise<number>;
|
|
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
|
+
*/
|
|
9
181
|
declare const gzipSizeSync: (input: SizeInputSync, options?: ZlibOptions) => number;
|
|
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
|
+
*/
|
|
10
218
|
declare const brotliSizeSync: (input: SizeInputSync, options?: BrotliOptions) => number;
|
|
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
|
+
*/
|
|
11
255
|
declare const rawSizeSync: (input: SizeInputSync) => number;
|
|
12
256
|
export { brotliSize, brotliSizeSync, gzipSize, gzipSizeSync, rawSize, rawSizeSync };
|
package/dist/size.js
CHANGED
|
@@ -1,146 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
const __cjs_require = __cjs_createRequire(import.meta.url);
|
|
4
|
-
|
|
5
|
-
const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
|
|
6
|
-
|
|
7
|
-
const __cjs_getBuiltinModule = (module) => {
|
|
8
|
-
// Check if we're in Node.js and version supports getBuiltinModule
|
|
9
|
-
if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
|
|
10
|
-
const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
|
|
11
|
-
// Node.js 20.16.0+ and 22.3.0+
|
|
12
|
-
if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
|
|
13
|
-
return __cjs_getProcess.getBuiltinModule(module);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
// Fallback to createRequire
|
|
17
|
-
return __cjs_require(module);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
readFileSync,
|
|
22
|
-
statSync,
|
|
23
|
-
existsSync
|
|
24
|
-
} = __cjs_getBuiltinModule("node:fs");
|
|
25
|
-
const {
|
|
26
|
-
readFile
|
|
27
|
-
} = __cjs_getBuiltinModule("node:fs/promises");
|
|
28
|
-
const {
|
|
29
|
-
isAbsolute,
|
|
30
|
-
resolve
|
|
31
|
-
} = __cjs_getBuiltinModule("node:path");
|
|
32
|
-
const {
|
|
33
|
-
Readable
|
|
34
|
-
} = __cjs_getBuiltinModule("node:stream");
|
|
35
|
-
const {
|
|
36
|
-
URL
|
|
37
|
-
} = __cjs_getBuiltinModule("node:url");
|
|
38
|
-
const {
|
|
39
|
-
brotliCompressSync,
|
|
40
|
-
gzipSync,
|
|
41
|
-
createGzip,
|
|
42
|
-
createBrotliCompress
|
|
43
|
-
} = __cjs_getBuiltinModule("node:zlib");
|
|
44
|
-
import { toPath } from '@visulima/path/utils';
|
|
45
|
-
|
|
46
|
-
const fileExists = (input) => {
|
|
47
|
-
if (isAbsolute(input)) {
|
|
48
|
-
return existsSync(input);
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
return existsSync(resolve(input));
|
|
52
|
-
} catch {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const getStreamSizeEfficient = async (stream) => {
|
|
57
|
-
let totalSize = 0;
|
|
58
|
-
for await (const chunk of stream) {
|
|
59
|
-
totalSize += Buffer.from(chunk).length;
|
|
60
|
-
}
|
|
61
|
-
return totalSize;
|
|
62
|
-
};
|
|
63
|
-
const getCompressedStreamSizeEfficient = async (stream, createCompressor) => {
|
|
64
|
-
let totalSize = 0;
|
|
65
|
-
const compressor = createCompressor();
|
|
66
|
-
return await new Promise((resolve2, reject) => {
|
|
67
|
-
compressor.on("data", (chunk) => {
|
|
68
|
-
totalSize += chunk.length;
|
|
69
|
-
});
|
|
70
|
-
compressor.on("end", () => {
|
|
71
|
-
resolve2(totalSize);
|
|
72
|
-
});
|
|
73
|
-
compressor.on("error", reject);
|
|
74
|
-
stream.on("error", reject);
|
|
75
|
-
stream.pipe(compressor);
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
const processInputEfficiently = async (input, processor, streamProcessor) => {
|
|
79
|
-
if (input instanceof URL || typeof input === "string") {
|
|
80
|
-
const path = toPath(input);
|
|
81
|
-
if (fileExists(path)) {
|
|
82
|
-
const fileStream = Readable.from(await readFile(path));
|
|
83
|
-
return await streamProcessor(fileStream);
|
|
84
|
-
}
|
|
85
|
-
if (typeof input === "string") {
|
|
86
|
-
return processor(Buffer.from(input));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (input instanceof Readable) {
|
|
90
|
-
return await streamProcessor(input);
|
|
91
|
-
}
|
|
92
|
-
return processor(input);
|
|
93
|
-
};
|
|
94
|
-
const gzipSize = async (input, options) => {
|
|
95
|
-
const streamProcessor = async (stream) => await getCompressedStreamSizeEfficient(stream, () => createGzip(options));
|
|
96
|
-
const bufferProcessor = (data) => gzipSync(data, options).length;
|
|
97
|
-
return await processInputEfficiently(input, bufferProcessor, streamProcessor);
|
|
98
|
-
};
|
|
99
|
-
const brotliSize = async (input, options) => {
|
|
100
|
-
const streamProcessor = async (stream) => await getCompressedStreamSizeEfficient(stream, () => createBrotliCompress(options));
|
|
101
|
-
const bufferProcessor = (data) => brotliCompressSync(data, options).length;
|
|
102
|
-
return await processInputEfficiently(input, bufferProcessor, streamProcessor);
|
|
103
|
-
};
|
|
104
|
-
const rawSize = async (input) => {
|
|
105
|
-
const streamProcessor = async (stream) => await getStreamSizeEfficient(stream);
|
|
106
|
-
const bufferProcessor = (data) => data.length;
|
|
107
|
-
return await processInputEfficiently(input, bufferProcessor, streamProcessor);
|
|
108
|
-
};
|
|
109
|
-
const gzipSizeSync = (input, options) => {
|
|
110
|
-
if (input instanceof URL || typeof input === "string") {
|
|
111
|
-
const path = toPath(input);
|
|
112
|
-
if (fileExists(path)) {
|
|
113
|
-
return gzipSync(readFileSync(path), options).length;
|
|
114
|
-
}
|
|
115
|
-
if (typeof input === "string") {
|
|
116
|
-
return gzipSync(Buffer.from(input), options).length;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return gzipSync(input, options).length;
|
|
120
|
-
};
|
|
121
|
-
const brotliSizeSync = (input, options) => {
|
|
122
|
-
if (input instanceof URL || typeof input === "string") {
|
|
123
|
-
const path = toPath(input);
|
|
124
|
-
if (fileExists(path)) {
|
|
125
|
-
return brotliCompressSync(readFileSync(path), options).length;
|
|
126
|
-
}
|
|
127
|
-
if (typeof input === "string") {
|
|
128
|
-
return brotliCompressSync(Buffer.from(input), options).length;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return brotliCompressSync(input, options).length;
|
|
132
|
-
};
|
|
133
|
-
const rawSizeSync = (input) => {
|
|
134
|
-
if (input instanceof URL || typeof input === "string") {
|
|
135
|
-
const path = toPath(input);
|
|
136
|
-
if (fileExists(path)) {
|
|
137
|
-
return statSync(path).size;
|
|
138
|
-
}
|
|
139
|
-
if (typeof input === "string") {
|
|
140
|
-
return Buffer.from(input).length;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
return input.length;
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
export { brotliSize, brotliSizeSync, gzipSize, gzipSizeSync, rawSize, rawSizeSync };
|
|
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:m,statSync:z,createReadStream:_,existsSync:y}=i("node:fs"),{isAbsolute:b,resolve:B}=i("node:path"),{Readable:j}=i("node:stream"),{URL:c}=i("node:url"),{brotliCompressSync:s,gzipSync:a,createGzip:R,createBrotliCompress:v}=i("node:zlib"),l=t=>{if(b(t))return y(t);try{return y(B(t))}catch{return!1}},q=async t=>{let n=0;for await(const e of t)n+=Buffer.from(e).length;return n},d=async(t,n)=>{let e=0;const r=n();return await new Promise((u,p)=>{r.on("data",h=>{e+=h.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=_(r);return await e(u)}if(typeof t=="string")return n(Buffer.from(t))}return t instanceof j?await e(t):n(t)},x=async(t,n)=>await g(t,e=>a(e,n).length,async e=>await d(e,()=>R(n))),C=async(t,n)=>await g(t,e=>s(e,n).length,async e=>await d(e,()=>v(n))),M=async t=>await g(t,n=>n.length,async n=>await q(n)),A=(t,n)=>{if(t instanceof c||typeof t=="string"){const e=f(t);if(l(e))return a(m(e),n).length;if(typeof t=="string")return a(Buffer.from(t),n).length}return a(t,n).length},F=(t,n)=>{if(t instanceof c||typeof t=="string"){const e=f(t);if(l(e))return s(m(e),n).length;if(typeof t=="string")return s(Buffer.from(t),n).length}return s(t,n).length},G=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{C as brotliSize,F as brotliSizeSync,x as gzipSize,A as gzipSizeSync,M as rawSize,G as rawSizeSync};
|
package/dist/toml.d.ts
CHANGED
|
@@ -1,9 +1,63 @@
|
|
|
1
|
-
import { C as CompressionType,
|
|
1
|
+
import { C as CompressionType, i as ReadTomlOptions, j as WriteTomlOptions } from "./packem_shared/types.d-BMdL_ygj.js";
|
|
2
2
|
import 'node:fs';
|
|
3
|
-
import '
|
|
4
|
-
|
|
3
|
+
import 'fdir';
|
|
4
|
+
/**
|
|
5
|
+
* Asynchronously reads a TOML file and parses it into an object.
|
|
6
|
+
* @template R The expected type of the parsed TOML object. Defaults to `Record<string, unknown>`.
|
|
7
|
+
* @param path The path to the TOML file to read. Can be a file URL or a string path.
|
|
8
|
+
* @param options Optional configuration for reading the file. See {@link ReadTomlOptions}.
|
|
9
|
+
* @returns A promise that resolves with the parsed TOML object of type `R`.
|
|
10
|
+
* @example
|
|
11
|
+
* ```javascript
|
|
12
|
+
* import { readToml } from "@visulima/fs/toml";
|
|
13
|
+
* import { join } from "node:path";
|
|
14
|
+
*
|
|
15
|
+
* const config = await readToml(join("path", "to", "config.toml"));
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
5
18
|
declare const readToml: <R = Record<string, unknown>>(path: URL | string, options?: ReadTomlOptions<CompressionType>) => Promise<R>;
|
|
19
|
+
/**
|
|
20
|
+
* Synchronously reads a TOML file and parses it into an object.
|
|
21
|
+
* @template R The expected type of the parsed TOML object. Defaults to `Record<string, unknown>`.
|
|
22
|
+
* @param path The path to the TOML file to read. Can be a file URL or a string path.
|
|
23
|
+
* @param options Optional configuration for reading the file. See {@link ReadTomlOptions}.
|
|
24
|
+
* @returns The parsed TOML object of type `R`.
|
|
25
|
+
* @example
|
|
26
|
+
* ```javascript
|
|
27
|
+
* import { readTomlSync } from "@visulima/fs/toml";
|
|
28
|
+
* import { join } from "node:path";
|
|
29
|
+
*
|
|
30
|
+
* const config = readTomlSync(join("path", "to", "config.toml"));
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
6
33
|
declare const readTomlSync: (path: URL | string, options?: ReadTomlOptions<CompressionType>) => Record<string, unknown>;
|
|
34
|
+
/**
|
|
35
|
+
* Asynchronously writes an object to a TOML file.
|
|
36
|
+
* @param path The path to the TOML file to write. Can be a file URL or a string path.
|
|
37
|
+
* @param data The data to serialize. Must be a plain object compatible with `smol-toml.stringify`.
|
|
38
|
+
* @param options Optional configuration for writing the TOML file. See {@link WriteTomlOptions}.
|
|
39
|
+
* @returns A promise that resolves when the TOML file has been written.
|
|
40
|
+
* @example
|
|
41
|
+
* ```javascript
|
|
42
|
+
* import { writeToml } from "@visulima/fs/toml";
|
|
43
|
+
* import { join } from "node:path";
|
|
44
|
+
*
|
|
45
|
+
* await writeToml(join("/tmp", "config.toml"), { name: "app", version: 1 });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
7
48
|
declare const writeToml: (path: URL | string, data: Record<string, unknown>, options?: WriteTomlOptions) => Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Synchronously writes an object to a TOML file.
|
|
51
|
+
* @param path The path to the TOML file to write. Can be a file URL or a string path.
|
|
52
|
+
* @param data The data to serialize. Must be a plain object compatible with `smol-toml.stringify`.
|
|
53
|
+
* @param options Optional configuration for writing the TOML file. See {@link WriteTomlOptions}.
|
|
54
|
+
* @example
|
|
55
|
+
* ```javascript
|
|
56
|
+
* import { writeTomlSync } from "@visulima/fs/toml";
|
|
57
|
+
* import { join } from "node:path";
|
|
58
|
+
*
|
|
59
|
+
* writeTomlSync(join("/tmp", "config.toml"), { name: "app", version: 1 });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
8
62
|
declare const writeTomlSync: (path: URL | string, data: Record<string, unknown>, options?: WriteTomlOptions) => void;
|
|
9
63
|
export { type ReadTomlOptions, type WriteTomlOptions, readToml, readTomlSync, writeToml, writeTomlSync };
|
package/dist/toml.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { default as readTomlSync } from './packem_shared/readTomlSync-DNbK8NEb.js';
|
|
3
|
-
export { default as writeToml } from './packem_shared/writeToml-DgTW_-7F.js';
|
|
4
|
-
export { default as writeTomlSync } from './packem_shared/writeTomlSync-DiBiE9ja.js';
|
|
1
|
+
import{default as r}from"./packem_shared/readToml-D4jpe9q_.js";import{default as t}from"./packem_shared/readTomlSync-B5PIYT9z.js";import{default as l}from"./packem_shared/writeToml-IuMO-yDu.js";import{default as d}from"./packem_shared/writeTomlSync-DhL7hHzB.js";export{r as readToml,t as readTomlSync,l as writeToml,d as writeTomlSync};
|