@mikestools/usefilesystem 0.0.1 → 0.0.2

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.
@@ -1 +1 @@
1
- (function(w,E){typeof exports=="object"&&typeof module<"u"?E(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],E):(w=typeof globalThis<"u"?globalThis:w||self,E(w.usefilesystem={},w.Vue))})(this,(function(w,E){"use strict";function K(){const n={name:"",path:"/",createdAt:Date.now(),files:new Map,directories:new Map},o=new Set;function s(e,t,i){for(const r of o)r(e,t,i)}function c(e){const t=e.split(/[/\\]/).filter(r=>r.length>0&&r!=="."),i=[];for(const r of t)r===".."?i.pop():i.push(r);return"/"+i.join("/")}function l(e){const t=c(e);return{segments:t.split("/").filter(r=>r.length>0),normalized:t}}function f(e){const{segments:t}=l(e);if(t.length===0)return{parentPath:"/",name:""};const i=t[t.length-1]??"";return{parentPath:"/"+t.slice(0,-1).join("/"),name:i}}function u(e,t=!1){const{segments:i}=l(e);let r=n;for(const a of i){let d=r.directories.get(a);if(!d){if(!t)return;d={name:a,path:r.path==="/"?`/${a}`:`${r.path}/${a}`,createdAt:Date.now(),files:new Map,directories:new Map},r.directories.set(a,d),s("create",d.path,"directory")}r=d}return r}function h(e){return new TextEncoder().encode(e)}function T(e){return new TextDecoder().decode(e)}function U(e){const t=e.split(".").pop()?.toLowerCase()??"";return{txt:"text/plain",html:"text/html",htm:"text/html",css:"text/css",js:"text/javascript",mjs:"text/javascript",ts:"text/typescript",tsx:"text/typescript",json:"application/json",xml:"application/xml",csv:"text/csv",md:"text/markdown",yaml:"text/yaml",yml:"text/yaml",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",svg:"image/svg+xml",webp:"image/webp",ico:"image/x-icon",pdf:"application/pdf",zip:"application/zip",gz:"application/gzip",tar:"application/x-tar",woff:"font/woff",woff2:"font/woff2",ttf:"font/ttf",otf:"font/otf",mp3:"audio/mpeg",wav:"audio/wav",mp4:"video/mp4",webm:"video/webm"}[t]??"application/octet-stream"}function S(e){return new Uint8Array(e)}function p(e,t,i={}){const{parentPath:r,name:a}=f(e),{normalized:d}=l(e);if(!a)return{success:!1,error:"Invalid file path: no filename specified"};const O=u(r,!0);if(!O)return{success:!1,error:`Failed to create parent directory: ${r}`};const B=O.files.get(a);if(B&&i.overwrite===!1)return{success:!1,error:`File already exists: ${d}`};const _=typeof t=="string"?h(t):S(t),oe=Date.now(),he={name:a,path:d,content:_,size:_.length,mimeType:i.mimeType??U(a),createdAt:B?.createdAt??oe,modifiedAt:oe};return O.files.set(a,he),s(B?"modify":"create",d,"file"),{success:!0}}function m(e,t){const i=y(e,{encoding:"binary"}),r=typeof t=="string"?h(t):t;if(i===void 0)return p(e,r);const a=i,d=new Uint8Array(a.length+r.length);return d.set(a,0),d.set(r,a.length),p(e,d)}function y(e,t={}){const{parentPath:i,name:r}=f(e),d=u(i)?.files.get(r);return d?(t.encoding??"utf8")==="binary"?S(d.content):T(d.content):void 0}function D(e){const{parentPath:t,name:i}=f(e),a=u(t)?.files.get(i);if(a)return{name:a.name,path:a.path,size:a.size,mimeType:a.mimeType,createdAt:a.createdAt,modifiedAt:a.modifiedAt}}function v(e){return D(e)!==void 0||A(e)}function b(e){return D(e)!==void 0}function A(e){return u(e)!==void 0}function C(e){const{parentPath:t,name:i}=f(e),{normalized:r}=l(e),a=u(t);return a?a.files.has(i)?(a.files.delete(i),s("delete",r,"file"),{success:!0}):{success:!1,error:`File not found: ${r}`}:{success:!1,error:`Parent directory not found: ${t}`}}function z(e,t,i={}){const r=y(e,{encoding:"binary"});if(r===void 0)return{success:!1,error:`Source file not found: ${e}`};const a=D(e);return p(t,r,{mimeType:a?.mimeType,overwrite:i.overwrite})}function P(e,t,i={}){const r=z(e,t,{overwrite:i.overwrite});return r.success?C(e):r}function F(e,t){return P(e,t,{overwrite:!1})}function R(e){return u(e,!0)?{success:!0}:{success:!1,error:`Failed to create directory: ${e}`}}function j(e){const{parentPath:t,name:i}=f(e),{normalized:r}=l(e);if(r==="/")return{success:!1,error:"Cannot remove root directory"};const a=u(t);if(!a)return{success:!1,error:`Parent directory not found: ${t}`};const d=a.directories.get(i);return d?d.files.size>0||d.directories.size>0?{success:!1,error:`Directory not empty: ${r}`}:(a.directories.delete(i),s("delete",r,"directory"),{success:!0}):{success:!1,error:`Directory not found: ${r}`}}function x(e){const{parentPath:t,name:i}=f(e),{normalized:r}=l(e);if(r==="/")return{success:!1,error:"Cannot remove root directory"};const a=u(t);return a?a.directories.get(i)?(a.directories.delete(i),s("delete",r,"directory"),{success:!0}):{success:!1,error:`Directory not found: ${r}`}:{success:!1,error:`Parent directory not found: ${t}`}}function M(e,t={}){const{recursive:i=!1,filesOnly:r=!1,directoriesOnly:a=!1}=t,d=e==="/"||e===""?n:u(e);if(!d)return[];const O=[];if(!a)for(const B of d.files.values())O.push({name:B.name,path:B.path,type:"file",size:B.size});if(!r){for(const B of d.directories.values())if(O.push({name:B.name,path:B.path,type:"directory"}),i){const _=M(B.path,t);O.push(..._)}}return O}function g(e){const t=u(e);if(t)return{name:t.name,path:t.path,createdAt:t.createdAt}}function L(){const e=[];function t(i){for(const r of i.files.values())e.push(r);for(const r of i.directories.values())t(r)}return t(n),e}function q(){return L().map(e=>e.path)}function de(){let e=0,t=0,i=0;function r(a){for(const d of a.files.values())e++,i+=d.size;for(const d of a.directories.values())t++,r(d)}return r(n),{totalFiles:e,totalDirectories:t,totalSize:i}}function re(){n.files.clear(),n.directories.clear(),s("delete","/","directory")}function me(e){const t=q(),i=e.replace(/\./g,"\\.").replace(/\*\*/g,"<<<GLOBSTAR>>>").replace(/\*/g,"[^/]*").replace(/<<<GLOBSTAR>>>/g,".*"),r=new RegExp(`^${i}$`);return t.filter(a=>r.test(a))}function pe(e){const t=e.startsWith(".")?e:`.${e}`;return q().filter(i=>i.endsWith(t))}function ye(e){return o.add(e),()=>{o.delete(e)}}function ge(){const e={};for(const t of L()){const i=btoa(Array.from(t.content,r=>String.fromCharCode(r)).join(""));e[t.path]={content:i,mimeType:t.mimeType}}return e}function we(e){re();for(const[t,{content:i,mimeType:r}]of Object.entries(e)){const a=atob(i),d=Uint8Array.from(a,O=>O.charCodeAt(0));p(t,d,{mimeType:r})}}return{writeFile:p,appendFile:m,readFile:y,stat:D,exists:v,isFile:b,isDirectory:A,remove:C,copy:z,move:P,rename:F,mkdir:R,rmdir:j,rmdirRecursive:x,list:M,statDirectory:g,getAllFiles:L,getAllPaths:q,getStats:de,clear:re,find:me,findByExtension:pe,watch:ye,toJSON:ge,fromJSON:we}}function se(n={}){const{adapter:o,autoPersist:s=!1}=n,c=K(),l=E.shallowRef(0);function f(){l.value++,s&&o&&U()}c.watch(()=>{f()});const u=E.computed(()=>(l.value,c.getStats())),h=E.computed(()=>u.value.totalFiles),T=E.computed(()=>u.value.totalSize);async function U(){if(!o)throw new Error("No storage adapter configured");const p=c.toJSON(),m=new TextEncoder().encode(JSON.stringify(p));await o.save("filesystem",m)}async function S(){if(!o)throw new Error("No storage adapter configured");const p=await o.load("filesystem");if(p){const m=JSON.parse(new TextDecoder().decode(p));c.fromJSON(m),f()}}return{...c,stats:u,fileCount:h,totalSize:T,persist:U,restore:S}}const Q=67324752,V=33639248,X=101010256,ie=0,N=8,ce=(function(){const o=new Uint32Array(256);for(let s=0;s<256;s++){let c=s;for(let l=0;l<8;l++)c=c&1?3988292384^c>>>1:c>>>1;o[s]=c}return o})();function J(n){let o=4294967295;for(let s=0;s<n.length;s++){const c=n[s]??0,l=(o^c)&255;o=o>>>8^(ce[l]??0)}return~o>>>0}function $(n){const o=new ArrayBuffer(n.byteLength);return new Uint8Array(o).set(n),o}function k(n){return new TextEncoder().encode(n)}function ee(n){return new TextDecoder().decode(n)}async function G(n){const s=new Blob([$(n)]).stream().pipeThrough(new CompressionStream("deflate-raw")),c=await new Response(s).blob();return new Uint8Array(await c.arrayBuffer())}async function W(n){const s=new Blob([$(n)]).stream().pipeThrough(new DecompressionStream("deflate-raw")),c=await new Response(s).blob();return new Uint8Array(await c.arrayBuffer())}function ae(n){const o=n.getHours(),s=n.getMinutes(),c=Math.floor(n.getSeconds()/2),l=o<<11|s<<5|c,f=n.getFullYear()-1980,u=n.getMonth()+1,h=n.getDate(),T=f<<9|u<<5|h;return{time:l,date:T}}function H(n,o){const s=(n&31)*2,c=n>>5&63,l=n>>11&31,f=o&31,u=(o>>5&15)-1,h=(o>>9&127)+1980;return new Date(h,u,f,l,c,s)}async function I(n,o={}){const{level:s="default",comment:c=""}=o,l=s!=="none",f=[],u=[];let h=0;const U=ae(new Date);for(const v of n){const b=k(v.path),A=typeof v.content=="string"?k(v.content):v.content,C=J(A),z=A.length,P=l?await G(A):A,F=P.length,R=l?N:ie,j=new ArrayBuffer(30),x=new DataView(j);x.setUint32(0,Q,!0),x.setUint16(4,20,!0),x.setUint16(6,0,!0),x.setUint16(8,R,!0),x.setUint16(10,U.time,!0),x.setUint16(12,U.date,!0),x.setUint32(14,C,!0),x.setUint32(18,F,!0),x.setUint32(22,z,!0),x.setUint16(26,b.length,!0),x.setUint16(28,0,!0),f.push(new Uint8Array(j),b,P);const M=new ArrayBuffer(46),g=new DataView(M);g.setUint32(0,V,!0),g.setUint16(4,20,!0),g.setUint16(6,20,!0),g.setUint16(8,0,!0),g.setUint16(10,R,!0),g.setUint16(12,U.time,!0),g.setUint16(14,U.date,!0),g.setUint32(16,C,!0),g.setUint32(20,F,!0),g.setUint32(24,z,!0),g.setUint16(28,b.length,!0),g.setUint16(30,0,!0),g.setUint16(32,0,!0),g.setUint16(34,0,!0),g.setUint16(36,0,!0),g.setUint32(38,0,!0),g.setUint32(42,h,!0);const L=new Uint8Array(46+b.length);L.set(new Uint8Array(M),0),L.set(b,46),u.push(L),h+=30+b.length+F}const S=u.reduce((v,b)=>v+b.length,0),p=k(c),m=new ArrayBuffer(22),y=new DataView(m);y.setUint32(0,X,!0),y.setUint16(4,0,!0),y.setUint16(6,0,!0),y.setUint16(8,n.length,!0),y.setUint16(10,n.length,!0),y.setUint32(12,S,!0),y.setUint32(16,h,!0),y.setUint16(20,p.length,!0);const D=[...f.map(v=>$(v)),...u.map(v=>$(v)),m,$(p)];return new Blob(D,{type:"application/zip"})}async function te(n){const o=n instanceof Blob?new Uint8Array(await n.arrayBuffer()):n,s=[],c=ue(o);if(!c)throw new Error("Invalid ZIP file: end of central directory not found");const l=new DataView(o.buffer,o.byteOffset,o.byteLength);let f=c.centralDirectoryOffset;for(let u=0;u<c.entryCount;u++){if(l.getUint32(f,!0)!==V)throw new Error("Invalid ZIP file: invalid central directory entry");const T=l.getUint16(f+10,!0),U=l.getUint16(f+12,!0),S=l.getUint16(f+14,!0),p=l.getUint32(f+20,!0),m=l.getUint32(f+24,!0),y=l.getUint16(f+28,!0),D=l.getUint16(f+30,!0),v=l.getUint16(f+32,!0),b=o.slice(f+46,f+46+y),A=ee(b);s.push({path:A,compressedSize:p,uncompressedSize:m,compressionMethod:T===N?"deflate":"store",isDirectory:A.endsWith("/"),modifiedAt:H(U,S)}),f+=46+y+D+v}return s}async function Y(n,o={}){const{filter:s}=o,c=n instanceof Blob?new Uint8Array(await n.arrayBuffer()):n,l=[],f=new DataView(c.buffer,c.byteOffset,c.byteLength);let u=0;for(;u<c.length-4;){const h=f.getUint32(u,!0);if(h===Q){const T=f.getUint16(u+8,!0),U=f.getUint16(u+10,!0),S=f.getUint16(u+12,!0),p=f.getUint32(u+14,!0),m=f.getUint32(u+18,!0),y=f.getUint32(u+22,!0),D=f.getUint16(u+26,!0),v=f.getUint16(u+28,!0),b=c.slice(u+30,u+30+D),A=ee(b),C=u+30+D+v,z=c.slice(C,C+m),P=A.endsWith("/"),F=T===N?"deflate":"store";if(s){const j={path:A,compressedSize:m,uncompressedSize:y,compressionMethod:F,isDirectory:P,modifiedAt:H(U,S)};if(!s(j)){u=C+m;continue}}let R;P?R=new Uint8Array(0):T===N?R=await W(z):R=new Uint8Array(z),l.push({path:A,content:R,compressedSize:m,uncompressedSize:y,compressionMethod:F,crc32:p,modifiedAt:H(U,S),isDirectory:P}),u=C+m}else{if(h===V)break;u++}}return l}async function ne(n,o){const s=await Y(n,{filter:c=>c.path===o});return s.length>0?s[0]?.content:void 0}function ue(n){const o=new DataView(n.buffer,n.byteOffset,n.byteLength);for(let s=n.length-22;s>=0;s--)if(o.getUint32(s,!0)===X)return{entryCount:o.getUint16(s+10,!0),centralDirectorySize:o.getUint32(s+12,!0),centralDirectoryOffset:o.getUint32(s+16,!0)}}function Z(n,o){const s=URL.createObjectURL(n),c=document.createElement("a");c.href=s,c.download=o,document.body.appendChild(c),c.click(),document.body.removeChild(c),URL.revokeObjectURL(s)}async function fe(n,o,s={}){const c=await I(n,s);Z(c,o)}function le(){const n=E.ref(!1),o=E.ref(0),s=E.ref(void 0),c=E.computed(()=>({isProcessing:n.value,progress:o.value,error:s.value}));async function l(p){n.value=!0,o.value=0,s.value=void 0;try{const m=await p();return o.value=100,m}catch(m){const y=m instanceof Error?m.message:"Unknown error";throw s.value=y,m}finally{n.value=!1}}async function f(p,m={}){return l(()=>I(p,m))}async function u(p,m={}){return l(()=>Y(p,m))}async function h(p,m){return l(()=>ne(p,m))}async function T(p){return l(()=>te(p))}async function U(p,m,y={}){return l(async()=>{const D=await I(p,y);Z(D,m)})}function S(){s.value=void 0}return{state:c,isProcessing:n,progress:o,error:s,create:f,extract:u,extractSingle:h,list:T,download:U,downloadBlob:Z,compress:G,decompress:W,computeCrc32:J,clearError:S}}w.compress=G,w.computeCrc32=J,w.createFileSystem=K,w.createZip=I,w.decompress=W,w.downloadAsZip=fe,w.downloadBlob=Z,w.extractFile=ne,w.extractZip=Y,w.listZip=te,w.useFileSystem=se,w.useZip=le,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(m,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],p):(m=typeof globalThis<"u"?globalThis:m||self,p(m.usefilesystem={},m.Vue))})(this,(function(m,p){"use strict";function j(){const y={name:"",path:"/",createdAt:Date.now(),files:new Map,directories:new Map},u=new Set;function g(e,t,n){for(const r of u)r(e,t,n)}function h(e){const t=e.split(/[/\\]/).filter(r=>r.length>0&&r!=="."),n=[];for(const r of t)r===".."?n.pop():n.push(r);return"/"+n.join("/")}function l(e){const t=h(e);return{segments:t.split("/").filter(r=>r.length>0),normalized:t}}function d(e){const{segments:t}=l(e);if(t.length===0)return{parentPath:"/",name:""};const n=t[t.length-1]??"";return{parentPath:"/"+t.slice(0,-1).join("/"),name:n}}function s(e,t=!1){const{segments:n}=l(e);let r=y;for(const o of n){let i=r.directories.get(o);if(!i){if(!t)return;i={name:o,path:r.path==="/"?`/${o}`:`${r.path}/${o}`,createdAt:Date.now(),files:new Map,directories:new Map},r.directories.set(o,i),g("create",i.path,"directory")}r=i}return r}function w(e){return new TextEncoder().encode(e)}function A(e){return new TextDecoder().decode(e)}function x(e){const t=e.split(".").pop()?.toLowerCase()??"";return{txt:"text/plain",html:"text/html",htm:"text/html",css:"text/css",js:"text/javascript",mjs:"text/javascript",ts:"text/typescript",tsx:"text/typescript",json:"application/json",xml:"application/xml",csv:"text/csv",md:"text/markdown",yaml:"text/yaml",yml:"text/yaml",png:"image/png",jpg:"image/jpeg",jpeg:"image/jpeg",gif:"image/gif",svg:"image/svg+xml",webp:"image/webp",ico:"image/x-icon",pdf:"application/pdf",zip:"application/zip",gz:"application/gzip",tar:"application/x-tar",woff:"font/woff",woff2:"font/woff2",ttf:"font/ttf",otf:"font/otf",mp3:"audio/mpeg",wav:"audio/wav",mp4:"video/mp4",webm:"video/webm"}[t]??"application/octet-stream"}function S(e){return new Uint8Array(e)}function f(e,t,n={}){const{parentPath:r,name:o}=d(e),{normalized:i}=l(e);if(!o)return{success:!1,error:"Invalid file path: no filename specified"};const c=s(r,!0);if(!c)return{success:!1,error:`Failed to create parent directory: ${r}`};const a=c.files.get(o);if(a&&n.overwrite===!1)return{success:!1,error:`File already exists: ${i}`};const z=typeof t=="string"?w(t):S(t),B=Date.now(),X={name:o,path:i,content:z,size:z.length,mimeType:n.mimeType??x(o),createdAt:a?.createdAt??B,modifiedAt:B};return c.files.set(o,X),g(a?"modify":"create",i,"file"),{success:!0}}function v(e,t){const n=P(e,{encoding:"binary"}),r=typeof t=="string"?w(t):t;if(n===void 0)return f(e,r);const o=n,i=new Uint8Array(o.length+r.length);return i.set(o,0),i.set(r,o.length),f(e,i)}function P(e,t={}){const{parentPath:n,name:r}=d(e),i=s(n)?.files.get(r);return i?(t.encoding??"utf8")==="binary"?S(i.content):A(i.content):void 0}function T(e){const{parentPath:t,name:n}=d(e),o=s(t)?.files.get(n);if(o)return{name:o.name,path:o.path,size:o.size,mimeType:o.mimeType,createdAt:o.createdAt,modifiedAt:o.modifiedAt}}function M(e){return T(e)!==void 0||F(e)}function R(e){return T(e)!==void 0}function F(e){return s(e)!==void 0}function D(e){const{parentPath:t,name:n}=d(e),{normalized:r}=l(e),o=s(t);return o?o.files.has(n)?(o.files.delete(n),g("delete",r,"file"),{success:!0}):{success:!1,error:`File not found: ${r}`}:{success:!1,error:`Parent directory not found: ${t}`}}function O(e,t,n={}){const r=P(e,{encoding:"binary"});if(r===void 0)return{success:!1,error:`Source file not found: ${e}`};const o=T(e);return f(t,r,{mimeType:o?.mimeType,overwrite:n.overwrite})}function C(e,t,n={}){const r=O(e,t,{overwrite:n.overwrite});return r.success?D(e):r}function U(e,t){return C(e,t,{overwrite:!1})}function L(e){return s(e,!0)?{success:!0}:{success:!1,error:`Failed to create directory: ${e}`}}function G(e){const{parentPath:t,name:n}=d(e),{normalized:r}=l(e);if(r==="/")return{success:!1,error:"Cannot remove root directory"};const o=s(t);if(!o)return{success:!1,error:`Parent directory not found: ${t}`};const i=o.directories.get(n);return i?i.files.size>0||i.directories.size>0?{success:!1,error:`Directory not empty: ${r}`}:(o.directories.delete(n),g("delete",r,"directory"),{success:!0}):{success:!1,error:`Directory not found: ${r}`}}function W(e){const{parentPath:t,name:n}=d(e),{normalized:r}=l(e);if(r==="/")return{success:!1,error:"Cannot remove root directory"};const o=s(t);return o?o.directories.get(n)?(o.directories.delete(n),g("delete",r,"directory"),{success:!0}):{success:!1,error:`Directory not found: ${r}`}:{success:!1,error:`Parent directory not found: ${t}`}}function E(e,t={}){const{recursive:n=!1,filesOnly:r=!1,directoriesOnly:o=!1}=t,i=e==="/"||e===""?y:s(e);if(!i)return[];const c=[];if(!o)for(const a of i.files.values())c.push({name:a.name,path:a.path,type:"file",size:a.size});if(!r){for(const a of i.directories.values())if(c.push({name:a.name,path:a.path,type:"directory"}),n){const z=E(a.path,t);c.push(...z)}}return c}function k(e){const t=s(e);if(t)return{name:t.name,path:t.path,createdAt:t.createdAt}}function b(){const e=[];function t(n){for(const r of n.files.values())e.push(r);for(const r of n.directories.values())t(r)}return t(y),e}function $(){return b().map(e=>e.path)}function q(){let e=0,t=0,n=0;function r(o){for(const i of o.files.values())e++,n+=i.size;for(const i of o.directories.values())t++,r(i)}return r(y),{totalFiles:e,totalDirectories:t,totalSize:n}}function N(){y.files.clear(),y.directories.clear(),g("delete","/","directory")}function I(e){const t=$(),n=e.replace(/\./g,"\\.").replace(/\*\*/g,"<<<GLOBSTAR>>>").replace(/\*/g,"[^/]*").replace(/<<<GLOBSTAR>>>/g,".*"),r=new RegExp(`^${n}$`);return t.filter(o=>r.test(o))}function V(e){const t=e.startsWith(".")?e:`.${e}`;return $().filter(n=>n.endsWith(t))}function H(e){return u.add(e),()=>{u.delete(e)}}function K(){const e={};for(const t of b()){const n=btoa(Array.from(t.content,r=>String.fromCharCode(r)).join(""));e[t.path]={content:n,mimeType:t.mimeType}}return e}function Q(e){N();for(const[t,{content:n,mimeType:r}]of Object.entries(e)){const o=atob(n),i=Uint8Array.from(o,c=>c.charCodeAt(0));f(t,i,{mimeType:r})}}return{writeFile:f,appendFile:v,readFile:P,stat:T,exists:M,isFile:R,isDirectory:F,remove:D,copy:O,move:C,rename:U,mkdir:L,rmdir:G,rmdirRecursive:W,list:E,statDirectory:k,getAllFiles:b,getAllPaths:$,getStats:q,clear:N,find:I,findByExtension:V,watch:H,toJSON:K,fromJSON:Q}}function J(y={}){const{adapter:u,autoPersist:g=!1}=y,h=j(),l=p.shallowRef(0);function d(){l.value++,g&&u&&x()}h.watch(()=>{d()});const s=p.computed(()=>(l.value,h.getStats())),w=p.computed(()=>s.value.totalFiles),A=p.computed(()=>s.value.totalSize);async function x(){if(!u)throw new Error("No storage adapter configured");const f=h.toJSON(),v=new TextEncoder().encode(JSON.stringify(f));await u.save("filesystem",v)}async function S(){if(!u)throw new Error("No storage adapter configured");const f=await u.load("filesystem");if(f){const v=JSON.parse(new TextDecoder().decode(f));h.fromJSON(v),d()}}return{...h,stats:s,fileCount:w,totalSize:A,persist:x,restore:S}}m.createFileSystem=j,m.useFileSystem=J,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikestools/usefilesystem",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Vue 3 composables for in-memory virtual filesystem and ZIP archive operations",
5
5
  "type": "module",
6
6
  "main": "./dist/usefilesystem.umd.cjs",
@@ -65,6 +65,7 @@
65
65
  "devDependencies": {
66
66
  "@eslint/js": "^9.39.1",
67
67
  "@mikestools/usebootstrap": "^0.0.5",
68
+ "@mikestools/usedatabase": "^0.0.1",
68
69
  "@mikestools/usetable": "^0.0.1",
69
70
  "@mikestools/usetools": "^0.0.10",
70
71
  "@popperjs/core": "^2.11.8",