appstore/dist/lib/ui/base/fs.js

2 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2023-12-19 15:30:29 +08:00
function p(e){let r=e.slice(0,64),t=e.slice(-64);return Promise.all([r.arrayBuffer(),t.arrayBuffer()]).then(([n,i])=>{let l=new Uint8Array(n),a=new Uint8Array(i),o=new Uint8Array(l.length+a.length);return o.set(l),o.set(a,l.length),o})}function c(e,r){return fetch(e).then(t=>t.blob()).then(t=>URL.createObjectURL(r?new Blob([t],{type:r}):t))}function u(e){return e<1024?`${e} B`:(e=(e/1024).toFixed(2)-0,e<1024?`${e} KB`:(e=(e/1024).toFixed(2)-0,`${e} MB`))}async function y(e){return new Uint8Array(await e.arrayBuffer())}function s(e,r){let t=e.split("/"),n=r.split("/");for(t.at(-1)===""&&t.pop();n.length;){let i=n.shift();i==="."||i===""||(i===".."?t.pop():t.push(i))}return t.join("/")}function h(e){return e.split("/").pop()}async function f(e,r=""){let t=s(r,e.name);if(e.kind==="directory"){let n=await e.entries(),i,l=[];for(;(i=await n.next())&&!i.done;){let a=i.value[1];a.kind==="directory"?l=l.concat(await f(a,t)):l.push({key:s(t,a.name),file:await a.getFile()})}return l}else return{key:t,file:await e.getFile()}}async function w(e){return Promise.all([...e].map(r=>r.getAsFileSystemHandle())).then(async r=>{let t=[];for(let n of r)t=t.concat(await f(n));return t})}export{h as filename,p as getFingerprint,s as join,u as parseSize,w as resolveFiles,c as toBlobURL,y as toUint8};