@gjsify/fs 0.3.20 → 0.3.21

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
- var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};export{t as __exportAll};
1
+ var e=Object.defineProperty,__exportAll=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r};export{__exportAll};
@@ -1 +1 @@
1
- import{normalizePath as e}from"./utils.js";import{BigIntStats as t,STAT_ATTRIBUTES as n,Stats as r}from"./stats.js";import{FileHandle as i}from"./file-handle.js";import{createNodeError as a}from"./errors.js";import{accessSync as o,appendFileSync as s,chmodSync as c,chownSync as l,copyFileSync as u,mkdirSync as d,readFileSync as f,readdirSync as p,readlinkSync as m,realpathSync as h,renameSync as g,rmdirSync as _,truncateSync as v,writeFileSync as y}from"./sync.js";import{open as b,rm as x}from"./promises.js";import S from"@girs/glib-2.0";import C from"@girs/gio-2.0";import{Buffer as w}from"node:buffer";function T(e,t){return typeof e==`function`?{options:{},callback:e}:{options:e??{},callback:t}}function E(i,o,s,c,l){let u=e(i),d=C.File.new_for_path(u);d.query_info_async(n,o,S.PRIORITY_DEFAULT,null,(e,n)=>{try{let e=d.query_info_finish(n);l(null,c?.bigint?new t(e,u):new r(e,u))}catch(e){l(a(e,s,u))}})}function D(e,t,n){let{options:r,callback:i}=T(t,n);E(e,C.FileQueryInfoFlags.NONE,`stat`,r,i)}function O(e,t,n){let{options:r,callback:i}=T(t,n);E(e,C.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,r,i)}function k(e,t,n){let{options:r,callback:i}=T(t,n);Promise.resolve().then(()=>{try{i(null,p(e,r))}catch(t){i(a(t,`readdir`,e))}})}function A(e,t,n){let{callback:r}=T(t,n);Promise.resolve().then(()=>{try{r(null,h(e))}catch(e){r(e)}})}function j(t,n,r,i){let o=typeof r==`function`?r:i;if(typeof o!=`function`)throw TypeError(`Callback must be a function. Received `+typeof o);let s=e(n),c=e(t),l=C.File.new_for_path(s);l.make_symbolic_link_async(c,S.PRIORITY_DEFAULT,null,(e,t)=>{try{l.make_symbolic_link_finish(t),o(null)}catch(e){o(a(e,`symlink`,c,s))}})}function M(e,...t){let n,r,i;switch(t.length){case 1:i=t[0];break;case 2:n=t[0],i=t[1];break;case 3:n=t[0],r=t[1],i=t[2];break;default:break}b(e,n,r).then(e=>{i(null,e.fd)}).catch(e=>{i(e,-1)})}function N(e,t,...n){let r=i.getInstance(e);if(typeof t==`string`){let e=n.pop(),i=n[0],a=n[1];r.write(t,i,a).then(t=>{e(null,t.bytesWritten,t.buffer)}).catch(t=>{e(t,0,``)});return}let a=n[n.length-1],o=n[0],s=n[1],c=n[2];r.write(t,o,s,c).then(e=>{a(null,e.bytesWritten,e.buffer)}).catch(e=>{a(e,0,w.from([]))})}function P(e,...t){let n=i.getInstance(e),r=t[t.length-1],a,o,s,c;if(!(t.length<=1))if(typeof t[0]==`object`&&!ArrayBuffer.isView(t[0])){let e=t[0];a=e.buffer,o=e.offset,s=e.length,c=e.position}else a=t[0],o=t[1],s=t[2],c=t[3];n.read(a,o,s,c).then(e=>{r(null,e.bytesRead,e.buffer)}).catch(e=>{r(e,0,w.from([]))})}function F(e,t){i.getInstance(e).close().then(()=>{t(null)}).catch(e=>t(e))}function I(e,...t){let n={},r=t[t.length-1];t.length>=2&&(n=t[0]),x(e,n).then(()=>{r(null)}).catch(e=>{r(e)})}function L(e,t,n){Promise.resolve().then(()=>{try{g(e,t),n(null)}catch(e){n(e)}})}function R(e,t,n,r){let i=typeof n==`function`?0:n,a=typeof n==`function`?n:r;Promise.resolve().then(()=>{try{u(e,t,i),a(null)}catch(e){a(e)}})}function z(e,t,n){let r=typeof t==`function`?void 0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{o(e,r),i(null)}catch(e){i(e)}})}function B(e,t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n;Promise.resolve().then(()=>{try{s(e,t,a),i(null)}catch(e){i(e)}})}function V(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{r(null,m(e,i))}catch(e){r(e,``)}})}function H(e,t,n){let r=typeof t==`function`?0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{v(e,r),i(null)}catch(e){i(e)}})}function U(e,t,n){Promise.resolve().then(()=>{try{c(e,t),n(null)}catch(e){n(e)}})}function W(e,t,n,r){Promise.resolve().then(()=>{try{l(e,t,n),r(null)}catch(e){r(e)}})}function G(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{d(e,i),r(null)}catch(e){r(e)}})}function K(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{_(e,i),r(null)}catch(e){r(e)}})}function q(t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n,o=e(t);Promise.resolve().then(()=>{try{i(null,f(o,typeof a==`string`?{encoding:a,flag:`r`}:{encoding:a?.encoding??null,flag:a?.flag??`r`}))}catch(e){i(e,null)}})}function J(t,n,r,i){let a=typeof r==`function`?r:i,o=e(t);Promise.resolve().then(()=>{try{y(o,n),a(null)}catch(e){a(e)}})}function Y(t,n,r){let i=e(t),a=e(n);Promise.resolve().then(()=>{try{if(!S.spawn_command_line_sync(`ln ${i} ${a}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, link '${i}' -> '${a}'`),{code:`EPERM`,errno:-1,syscall:`link`,path:i,dest:a});r(null)}catch(e){r(e)}})}function X(t,n){let r=e(t);Promise.resolve().then(()=>{try{S.unlink(r),n(null)}catch(e){n(e)}})}export{z as access,B as appendFile,U as chmod,W as chown,F as close,R as copyFile,Y as link,O as lstat,G as mkdir,M as open,P as read,q as readFile,k as readdir,V as readlink,A as realpath,L as rename,I as rm,K as rmdir,D as stat,j as symlink,H as truncate,X as unlink,N as write,J as writeFile};
1
+ import{normalizePath as e}from"./utils.js";import{BigIntStats as t,STAT_ATTRIBUTES as n,Stats as r}from"./stats.js";import{FileHandle as i}from"./file-handle.js";import{createNodeError as a}from"./errors.js";import{accessSync as o,appendFileSync as s,chmodSync as c,chownSync as l,copyFileSync as u,mkdirSync as d,readFileSync as f,readdirSync as p,readlinkSync as m,realpathSync as h,renameSync as g,rmdirSync as _,truncateSync as v,writeFileSync as y}from"./sync.js";import{open as b,rm as x}from"./promises.js";import S from"@girs/glib-2.0";import C from"@girs/gio-2.0";import{Buffer as w}from"node:buffer";function parseOptsCb(e,t){return typeof e==`function`?{options:{},callback:e}:{options:e??{},callback:t}}function statImpl(i,o,s,c,l){let u=e(i),d=C.File.new_for_path(u);d.query_info_async(n,o,S.PRIORITY_DEFAULT,null,(e,n)=>{try{let e=d.query_info_finish(n);l(null,c?.bigint?new t(e,u):new r(e,u))}catch(e){l(a(e,s,u))}})}function stat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,C.FileQueryInfoFlags.NONE,`stat`,r,i)}function lstat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,C.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,r,i)}function readdir(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{i(null,p(e,r))}catch(t){i(a(t,`readdir`,e))}})}function realpath(e,t,n){let{callback:r}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{r(null,h(e))}catch(e){r(e)}})}function symlink(t,n,r,i){let o=typeof r==`function`?r:i;if(typeof o!=`function`)throw TypeError(`Callback must be a function. Received `+typeof o);let s=e(n),c=e(t),l=C.File.new_for_path(s);l.make_symbolic_link_async(c,S.PRIORITY_DEFAULT,null,(e,t)=>{try{l.make_symbolic_link_finish(t),o(null)}catch(e){o(a(e,`symlink`,c,s))}})}function open(e,...t){let n,r,i;switch(t.length){case 1:i=t[0];break;case 2:n=t[0],i=t[1];break;case 3:n=t[0],r=t[1],i=t[2];break;default:break}b(e,n,r).then(e=>{i(null,e.fd)}).catch(e=>{i(e,-1)})}function write(e,t,...n){let r=i.getInstance(e);if(typeof t==`string`){let e=n.pop(),i=n[0],a=n[1];r.write(t,i,a).then(t=>{e(null,t.bytesWritten,t.buffer)}).catch(t=>{e(t,0,``)});return}let a=n[n.length-1],o=n[0],s=n[1],c=n[2];r.write(t,o,s,c).then(e=>{a(null,e.bytesWritten,e.buffer)}).catch(e=>{a(e,0,w.from([]))})}function read(e,...t){let n=i.getInstance(e),r=t[t.length-1],a,o,s,c;if(!(t.length<=1))if(typeof t[0]==`object`&&!ArrayBuffer.isView(t[0])){let e=t[0];a=e.buffer,o=e.offset,s=e.length,c=e.position}else a=t[0],o=t[1],s=t[2],c=t[3];n.read(a,o,s,c).then(e=>{r(null,e.bytesRead,e.buffer)}).catch(e=>{r(e,0,w.from([]))})}function close(e,t){i.getInstance(e).close().then(()=>{t(null)}).catch(e=>t(e))}function rm(e,...t){let n={},r=t[t.length-1];t.length>=2&&(n=t[0]),x(e,n).then(()=>{r(null)}).catch(e=>{r(e)})}function rename(e,t,n){Promise.resolve().then(()=>{try{g(e,t),n(null)}catch(e){n(e)}})}function copyFile(e,t,n,r){let i=typeof n==`function`?0:n,a=typeof n==`function`?n:r;Promise.resolve().then(()=>{try{u(e,t,i),a(null)}catch(e){a(e)}})}function access(e,t,n){let r=typeof t==`function`?void 0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{o(e,r),i(null)}catch(e){i(e)}})}function appendFile(e,t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n;Promise.resolve().then(()=>{try{s(e,t,a),i(null)}catch(e){i(e)}})}function readlink(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{r(null,m(e,i))}catch(e){r(e,``)}})}function truncate(e,t,n){let r=typeof t==`function`?0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{v(e,r),i(null)}catch(e){i(e)}})}function chmod(e,t,n){Promise.resolve().then(()=>{try{c(e,t),n(null)}catch(e){n(e)}})}function chown(e,t,n,r){Promise.resolve().then(()=>{try{l(e,t,n),r(null)}catch(e){r(e)}})}function mkdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{d(e,i),r(null)}catch(e){r(e)}})}function rmdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{_(e,i),r(null)}catch(e){r(e)}})}function readFile(t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n,o=e(t);Promise.resolve().then(()=>{try{i(null,f(o,typeof a==`string`?{encoding:a,flag:`r`}:{encoding:a?.encoding??null,flag:a?.flag??`r`}))}catch(e){i(e,null)}})}function writeFile(t,n,r,i){let a=typeof r==`function`?r:i,o=e(t);Promise.resolve().then(()=>{try{y(o,n),a(null)}catch(e){a(e)}})}function link(t,n,r){let i=e(t),a=e(n);Promise.resolve().then(()=>{try{if(!S.spawn_command_line_sync(`ln ${i} ${a}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, link '${i}' -> '${a}'`),{code:`EPERM`,errno:-1,syscall:`link`,path:i,dest:a});r(null)}catch(e){r(e)}})}function unlink(t,n){let r=e(t);Promise.resolve().then(()=>{try{S.unlink(r),n(null)}catch(e){n(e)}})}export{access,appendFile,chmod,chown,close,copyFile,link,lstat,mkdir,open,read,readFile,readdir,readlink,realpath,rename,rm,rmdir,stat,symlink,truncate,unlink,write,writeFile};
package/lib/esm/cp.js CHANGED
@@ -1 +1 @@
1
- import{normalizePath as e}from"./utils.js";import{createNodeError as t}from"./errors.js";import n from"@girs/gio-2.0";import{join as r}from"node:path";function i(e){let t=Error(`ERR_FS_CP_EEXIST: file already exists, copyfile '${e}'`);return t.code=`ERR_FS_CP_EEXIST`,t.syscall=`copyfile`,t.path=e,t}function a(e){let t=Error(`ERR_FS_EISDIR: illegal operation on a directory, copyfile '${e}'`);return t.code=`ERR_FS_EISDIR`,t.syscall=`copyfile`,t.path=e,t}function o(e,t){let n=Error(`ENOTDIR: not a directory, copyfile '${e}' -> '${t}'`);return n.code=`ENOTDIR`,n.syscall=`copyfile`,n.path=e,n.dest=t,n}function s(e,t){let n=Error(`ELOOP: too many levels of symbolic links, copyfile '${e}' -> '${t}'`);return n.code=`ELOOP`,n.syscall=`copyfile`,n.path=e,n.dest=t,n}function c(e){let t=e.force??!0,r=n.FileCopyFlags.NONE;return t&&(r|=n.FileCopyFlags.OVERWRITE),e.preserveTimestamps&&(r|=n.FileCopyFlags.TARGET_DEFAULT_MODIFIED_TIME),e.dereference||(r|=n.FileCopyFlags.NOFOLLOW_SYMLINKS),r}function l(e,r,a,s,l){let u=l.force??!0;try{if(r.query_info(`standard::type`,n.FileQueryInfoFlags.NONE,null).get_file_type()===n.FileType.DIRECTORY)throw o(a,s);if(!u){if(l.errorOnExist)throw i(s);return}}catch(e){if(typeof e.code==`string`)throw e}let d=c(l);try{e.copy(r,d,null,null)}catch(e){throw t(e,`copyfile`,a,s)}}function u(e,i,a,c,l){let u=a.endsWith(`/`)?``:`/`;if(c.startsWith(a+u)&&c!==a)throw s(a,c);if(i.query_exists(null))try{if(i.query_info(`standard::type`,n.FileQueryInfoFlags.NONE,null).get_file_type()!==n.FileType.DIRECTORY)throw o(c,a)}catch(e){if(typeof e.code==`string`)throw e}else try{i.make_directory_with_parents(null)}catch(e){throw t(e,`mkdir`,c)}let f;try{f=e.enumerate_children(`standard::name,standard::type,standard::is-symlink`,l.dereference?n.FileQueryInfoFlags.NONE:n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(e){throw t(e,`scandir`,a)}let p=f.next_file(null);for(;p!==null;){let e=p.get_name(),t=r(a,e),n=r(c,e),i=l.filter;if(i&&!i(t,n)){p=f.next_file(null);continue}d(t,n,l),p=f.next_file(null)}}function d(e,r,i){let o=n.File.new_for_path(e),s=n.File.new_for_path(r),c;try{c=o.query_info(`standard::type,standard::is-symlink`,i.dereference?n.FileQueryInfoFlags.NONE:n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(n){throw t(n,`stat`,e)}if(c.get_file_type()===n.FileType.DIRECTORY){if(!i.recursive)throw a(e);u(o,s,e,r,i)}else l(o,s,e,r,i)}function f(r,i,o){let s=e(r),c=e(i),l=o??{},u=n.File.new_for_path(s),f=l.filter;if(!(f&&!f(s,c))){try{if(u.query_info(`standard::type`,l.dereference?n.FileQueryInfoFlags.NONE:n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null).get_file_type()===n.FileType.DIRECTORY&&!l.recursive)throw a(s)}catch(e){throw typeof e.code==`string`?e:t(e,`stat`,s)}d(s,c,l)}}function p(t,n,r,i){let a,o;typeof r==`function`?(o=r,a={}):(o=i,a=r);let s=a.filter;if(s){Promise.resolve(s(e(t),e(n))).then(e=>{if(!e){o(null);return}try{h(t,n,a).then(()=>o(null)).catch(o)}catch(e){o(e)}}).catch(o);return}Promise.resolve().then(()=>{try{f(t,n,a),o(null)}catch(e){o(e)}})}async function m(e,i,a){let o=e.endsWith(`/`)?``:`/`;if(i.startsWith(e+o)&&i!==e)throw s(e,i);let c=n.File.new_for_path(i);if(!c.query_exists(null))try{c.make_directory_with_parents(null)}catch(e){throw t(e,`mkdir`,i)}let l=n.File.new_for_path(e),u;try{u=l.enumerate_children(`standard::name,standard::type`,a.dereference?n.FileQueryInfoFlags.NONE:n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(n){throw t(n,`scandir`,e)}let d=u.next_file(null);for(;d!==null;){let t=d.get_name(),n=r(e,t),o=r(i,t),s=a.filter;if(s&&!await Promise.resolve(s(n,o))){d=u.next_file(null);continue}await h(n,o,a),d=u.next_file(null)}}async function h(r,i,o={}){let s=e(r),c=e(i),u=n.File.new_for_path(s),d;try{d=u.query_info(`standard::type`,o.dereference?n.FileQueryInfoFlags.NONE:n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(e){throw t(e,`stat`,s)}if(d.get_file_type()===n.FileType.DIRECTORY){if(!o.recursive)throw a(s);await m(s,c,o)}else l(u,n.File.new_for_path(c),s,c,o)}export{p as cp,h as cpAsync,f as cpSync};
1
+ import{normalizePath as e}from"./utils.js";import{createNodeError as t}from"./errors.js";import n from"@girs/gio-2.0";import{join as r}from"node:path";function makeEEXIST(e){let t=Error(`ERR_FS_CP_EEXIST: file already exists, copyfile '${e}'`);return t.code=`ERR_FS_CP_EEXIST`,t.syscall=`copyfile`,t.path=e,t}function makeEISDIR(e){let t=Error(`ERR_FS_EISDIR: illegal operation on a directory, copyfile '${e}'`);return t.code=`ERR_FS_EISDIR`,t.syscall=`copyfile`,t.path=e,t}function makeENOTDIR(e,t){let n=Error(`ENOTDIR: not a directory, copyfile '${e}' -> '${t}'`);return n.code=`ENOTDIR`,n.syscall=`copyfile`,n.path=e,n.dest=t,n}function makeSYMLINKLOOP(e,t){let n=Error(`ELOOP: too many levels of symbolic links, copyfile '${e}' -> '${t}'`);return n.code=`ELOOP`,n.syscall=`copyfile`,n.path=e,n.dest=t,n}function queryCopyFlags(e){let t=e.force??!0,r=n.FileCopyFlags.NONE;return t&&(r|=n.FileCopyFlags.OVERWRITE),e.preserveTimestamps&&(r|=n.FileCopyFlags.TARGET_DEFAULT_MODIFIED_TIME),e.dereference||(r|=n.FileCopyFlags.NOFOLLOW_SYMLINKS),r}function copyOneSyncFile(e,r,i,a,o){let s=o.force??!0;try{if(r.query_info(`standard::type`,n.FileQueryInfoFlags.NONE,null).get_file_type()===n.FileType.DIRECTORY)throw makeENOTDIR(i,a);if(!s){if(o.errorOnExist)throw makeEEXIST(a);return}}catch(e){if(typeof e.code==`string`)throw e}let c=queryCopyFlags(o);try{e.copy(r,c,null,null)}catch(e){throw t(e,`copyfile`,i,a)}}function cpOneDirSync(e,i,a,o,s){let c=a.endsWith(`/`)?``:`/`;if(o.startsWith(a+c)&&o!==a)throw makeSYMLINKLOOP(a,o);if(i.query_exists(null))try{if(i.query_info(`standard::type`,n.FileQueryInfoFlags.NONE,null).get_file_type()!==n.FileType.DIRECTORY)throw makeENOTDIR(o,a)}catch(e){if(typeof e.code==`string`)throw e}else try{i.make_directory_with_parents(null)}catch(e){throw t(e,`mkdir`,o)}let l;try{l=e.enumerate_children(`standard::name,standard::type,standard::is-symlink`,s.dereference?n.FileQueryInfoFlags.NONE:n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(e){throw t(e,`scandir`,a)}let u=l.next_file(null);for(;u!==null;){let e=u.get_name(),t=r(a,e),n=r(o,e),i=s.filter;if(i&&!i(t,n)){u=l.next_file(null);continue}cpSyncInternal(t,n,s),u=l.next_file(null)}}function cpSyncInternal(e,r,i){let a=n.File.new_for_path(e),o=n.File.new_for_path(r),s;try{s=a.query_info(`standard::type,standard::is-symlink`,i.dereference?n.FileQueryInfoFlags.NONE:n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(n){throw t(n,`stat`,e)}if(s.get_file_type()===n.FileType.DIRECTORY){if(!i.recursive)throw makeEISDIR(e);cpOneDirSync(a,o,e,r,i)}else copyOneSyncFile(a,o,e,r,i)}function cpSync(r,i,a){let o=e(r),s=e(i),c=a??{},l=n.File.new_for_path(o),u=c.filter;if(!(u&&!u(o,s))){try{if(l.query_info(`standard::type`,c.dereference?n.FileQueryInfoFlags.NONE:n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null).get_file_type()===n.FileType.DIRECTORY&&!c.recursive)throw makeEISDIR(o)}catch(e){throw typeof e.code==`string`?e:t(e,`stat`,o)}cpSyncInternal(o,s,c)}}function cp(t,n,r,i){let a,o;typeof r==`function`?(o=r,a={}):(o=i,a=r);let s=a.filter;if(s){Promise.resolve(s(e(t),e(n))).then(e=>{if(!e){o(null);return}try{cpPromises(t,n,a).then(()=>o(null)).catch(o)}catch(e){o(e)}}).catch(o);return}Promise.resolve().then(()=>{try{cpSync(t,n,a),o(null)}catch(e){o(e)}})}async function cpPromisesDir(e,i,a){let o=e.endsWith(`/`)?``:`/`;if(i.startsWith(e+o)&&i!==e)throw makeSYMLINKLOOP(e,i);let s=n.File.new_for_path(i);if(!s.query_exists(null))try{s.make_directory_with_parents(null)}catch(e){throw t(e,`mkdir`,i)}let c=n.File.new_for_path(e),l;try{l=c.enumerate_children(`standard::name,standard::type`,a.dereference?n.FileQueryInfoFlags.NONE:n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(n){throw t(n,`scandir`,e)}let u=l.next_file(null);for(;u!==null;){let t=u.get_name(),n=r(e,t),o=r(i,t),s=a.filter;if(s&&!await Promise.resolve(s(n,o))){u=l.next_file(null);continue}await cpPromises(n,o,a),u=l.next_file(null)}}async function cpPromises(r,i,a={}){let o=e(r),s=e(i),c=n.File.new_for_path(o),l;try{l=c.query_info(`standard::type`,a.dereference?n.FileQueryInfoFlags.NONE:n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(e){throw t(e,`stat`,o)}if(l.get_file_type()===n.FileType.DIRECTORY){if(!a.recursive)throw makeEISDIR(o);await cpPromisesDir(o,s,a)}else copyOneSyncFile(c,n.File.new_for_path(s),o,s,a)}export{cp,cpPromises as cpAsync,cpSync};
package/lib/esm/dir.js CHANGED
@@ -1 +1 @@
1
- import{normalizePath as e}from"./utils.js";import{Dirent as t}from"./dirent.js";import{createNodeError as n}from"./errors.js";import r from"@girs/glib-2.0";import i from"@girs/gio-2.0";const a=`standard::name,standard::type,standard::is-symlink,standard::size,standard::symlink-target,unix::uid,unix::gid,unix::mode,time::modified,time::access,time::created`;var o=class{path;_enumerator;_closed=!1;constructor(e,t){this.path=e,this._enumerator=t}_assertOpen(){if(this._closed){let e=Error(`Directory handle was closed`);throw e.code=`ERR_DIR_CLOSED`,e}}readSync(){this._assertOpen();try{let e=this._enumerator.next_file(null);if(e===null)return null;let n=e.get_name(),r=e.get_file_type();return new t(this.path.endsWith(`/`)?this.path+n:this.path+`/`+n,n,r)}catch(e){throw n(e,`readdir`,this.path)}}read(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this._assertOpen();let t=this.readSync();Promise.resolve().then(()=>e(null,t))}catch(t){Promise.resolve().then(()=>e(t,null))}return}return new Promise((e,t)=>{try{this._assertOpen(),e(this.readSync())}catch(e){t(e)}})}closeSync(){this._assertOpen(),this._closed=!0;try{this._enumerator.close(null)}catch{}this._enumerator=null}close(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this.closeSync(),Promise.resolve().then(()=>e(null))}catch(t){Promise.resolve().then(()=>e(t))}return}return new Promise((e,t)=>{try{this.closeSync(),e()}catch(e){t(e)}})}async*[Symbol.asyncIterator](){try{for(;;){let e=await this.read();if(e===null)break;yield e}}finally{this._closed||await this.close()}}};function s(e){let t=i.File.new_for_path(e),r;try{r=t.enumerate_children(a,i.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){throw n(t,`opendir`,e)}return new o(e,r)}function c(t){return s(e(t))}function l(e,t,n){let r;if(r=typeof t==`function`?t:n,typeof r!=`function`)throw TypeError(`The "callback" argument must be of type function`);Promise.resolve().then(()=>{try{let t=c(e);r(null,t)}catch(e){r(e,null)}})}async function u(t,s){return new Promise((s,c)=>{let l=e(t),u=i.File.new_for_path(l);u.enumerate_children_async(a,i.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,r.PRIORITY_DEFAULT,null,(e,t)=>{try{s(new o(l,u.enumerate_children_finish(t)))}catch(e){c(n(e,`opendir`,l))}})})}export{o as Dir,l as opendir,u as opendirAsync,c as opendirSync};
1
+ import{normalizePath as e}from"./utils.js";import{Dirent as t}from"./dirent.js";import{createNodeError as n}from"./errors.js";import r from"@girs/glib-2.0";import i from"@girs/gio-2.0";const a=`standard::name,standard::type,standard::is-symlink,standard::size,standard::symlink-target,unix::uid,unix::gid,unix::mode,time::modified,time::access,time::created`;var Dir=class{path;_enumerator;_closed=!1;constructor(e,t){this.path=e,this._enumerator=t}_assertOpen(){if(this._closed){let e=Error(`Directory handle was closed`);throw e.code=`ERR_DIR_CLOSED`,e}}readSync(){this._assertOpen();try{let e=this._enumerator.next_file(null);if(e===null)return null;let n=e.get_name(),r=e.get_file_type();return new t(this.path.endsWith(`/`)?this.path+n:this.path+`/`+n,n,r)}catch(e){throw n(e,`readdir`,this.path)}}read(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this._assertOpen();let t=this.readSync();Promise.resolve().then(()=>e(null,t))}catch(t){Promise.resolve().then(()=>e(t,null))}return}return new Promise((e,t)=>{try{this._assertOpen(),e(this.readSync())}catch(e){t(e)}})}closeSync(){this._assertOpen(),this._closed=!0;try{this._enumerator.close(null)}catch{}this._enumerator=null}close(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this.closeSync(),Promise.resolve().then(()=>e(null))}catch(t){Promise.resolve().then(()=>e(t))}return}return new Promise((e,t)=>{try{this.closeSync(),e()}catch(e){t(e)}})}async*[Symbol.asyncIterator](){try{for(;;){let e=await this.read();if(e===null)break;yield e}}finally{this._closed||await this.close()}}};function _openDir(e){let t=i.File.new_for_path(e),r;try{r=t.enumerate_children(a,i.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){throw n(t,`opendir`,e)}return new Dir(e,r)}function opendirSync(t){return _openDir(e(t))}function opendir(e,t,n){let r;if(r=typeof t==`function`?t:n,typeof r!=`function`)throw TypeError(`The "callback" argument must be of type function`);Promise.resolve().then(()=>{try{let t=opendirSync(e);r(null,t)}catch(e){r(e,null)}})}async function opendirAsync(t,o){return new Promise((o,s)=>{let c=e(t),l=i.File.new_for_path(c);l.enumerate_children_async(a,i.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,r.PRIORITY_DEFAULT,null,(e,t)=>{try{o(new Dir(c,l.enumerate_children_finish(t)))}catch(e){s(n(e,`opendir`,c))}})})}export{Dir,opendir,opendirAsync,opendirSync};
package/lib/esm/dirent.js CHANGED
@@ -1 +1 @@
1
- import e from"@girs/gio-2.0";import{basename as t,dirname as n}from"node:path";var r=class{name;parentPath;_isFile=!1;_isDirectory=!1;_isBlockDevice=!1;_isCharacterDevice=!1;_isSymbolicLink=!1;_isFIFO=!1;_isSocket=!1;_file;constructor(r,i,a){switch(i||=t(r),this.name=i,this.parentPath=n(r),this._file=e.File.new_for_path(r),a??this._file.query_file_type(e.FileQueryInfoFlags.NONE,null)){case e.FileType.DIRECTORY:this._isDirectory=!0;break;case e.FileType.MOUNTABLE:break;case e.FileType.REGULAR:this._isFile=!0;break;case e.FileType.SYMBOLIC_LINK:case e.FileType.SHORTCUT:this._isSymbolicLink=!0;break;case e.FileType.SPECIAL:this._classifySpecialFile(r);break}}_classifySpecialFile(t){try{let n=e.File.new_for_path(t).query_info(`unix::mode`,e.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null).get_attribute_uint32(`unix::mode`);if(n===0)return;switch(n&61440){case 24576:this._isBlockDevice=!0;break;case 8192:this._isCharacterDevice=!0;break;case 49152:this._isSocket=!0;break;case 4096:this._isFIFO=!0;break}}catch{}}isFile(){return this._isFile}isDirectory(){return this._isDirectory}isBlockDevice(){return this._isBlockDevice}isCharacterDevice(){return this._isCharacterDevice}isSymbolicLink(){return this._isSymbolicLink}isFIFO(){return this._isFIFO}isSocket(){return this._isSocket}};export{r as Dirent};
1
+ import e from"@girs/gio-2.0";import{basename as t,dirname as n}from"node:path";var Dirent=class{name;parentPath;_isFile=!1;_isDirectory=!1;_isBlockDevice=!1;_isCharacterDevice=!1;_isSymbolicLink=!1;_isFIFO=!1;_isSocket=!1;_file;constructor(r,i,a){switch(i||=t(r),this.name=i,this.parentPath=n(r),this._file=e.File.new_for_path(r),a??this._file.query_file_type(e.FileQueryInfoFlags.NONE,null)){case e.FileType.DIRECTORY:this._isDirectory=!0;break;case e.FileType.MOUNTABLE:break;case e.FileType.REGULAR:this._isFile=!0;break;case e.FileType.SYMBOLIC_LINK:case e.FileType.SHORTCUT:this._isSymbolicLink=!0;break;case e.FileType.SPECIAL:this._classifySpecialFile(r);break}}_classifySpecialFile(t){try{let n=e.File.new_for_path(t).query_info(`unix::mode`,e.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null).get_attribute_uint32(`unix::mode`);if(n===0)return;switch(n&61440){case 24576:this._isBlockDevice=!0;break;case 8192:this._isCharacterDevice=!0;break;case 49152:this._isSocket=!0;break;case 4096:this._isFIFO=!0;break}}catch{}}isFile(){return this._isFile}isDirectory(){return this._isDirectory}isBlockDevice(){return this._isBlockDevice}isCharacterDevice(){return this._isCharacterDevice}isSymbolicLink(){return this._isSymbolicLink}isFIFO(){return this._isFIFO}isSocket(){return this._isSocket}};export{Dirent};
@@ -1 +1 @@
1
- import{Buffer as e}from"node:buffer";function t(e={encoding:null,flag:`r`},t=`utf8`){return e===null?t:typeof e==`string`?e:typeof e==`object`&&typeof e.encoding==`string`?e.encoding:t}function n(t,n){return t===`buffer`?e.from(n):new TextDecoder(t).decode(n)}function r(e,t){if(t){let n=new TextDecoder(t),r=new TextEncoder;return n.decode(r.encode(e))}else return e}export{r as decode,n as encodeUint8Array,t as getEncodingFromOptions};
1
+ import{Buffer as e}from"node:buffer";function getEncodingFromOptions(e={encoding:null,flag:`r`},t=`utf8`){return e===null?t:typeof e==`string`?e:typeof e==`object`&&typeof e.encoding==`string`?e.encoding:t}function encodeUint8Array(t,n){return t===`buffer`?e.from(n):new TextDecoder(t).decode(n)}function decode(e,t){if(t){let n=new TextDecoder(t),r=new TextEncoder;return n.decode(r.encode(e))}else return e}export{decode,encodeUint8Array,getEncodingFromOptions};
package/lib/esm/errors.js CHANGED
@@ -1 +1 @@
1
- import{createNodeError as e,isNotFoundError as t}from"@gjsify/utils";function n(t,n,r,i){return e(t,n,{path:r.toString(),dest:i?.toString()})}export{n as createNodeError,t as isNotFoundError};
1
+ import{createNodeError as e,isNotFoundError as t}from"@gjsify/utils";function createNodeError(t,n,r,i){return e(t,n,{path:r.toString(),dest:i?.toString()})}export{createNodeError,t as isNotFoundError};
package/lib/esm/fd-ops.js CHANGED
@@ -1 +1 @@
1
- import{normalizePath as e}from"./utils.js";import{FileHandle as t}from"./file-handle.js";import{chmodSync as n,chownSync as r,readFileSync as i,statSync as a,truncateSync as o}from"./sync.js";import{utimesSync as s}from"./utimes.js";function c(e){return e instanceof t?t.getInstance(e.fd):t.getInstance(e)}function l(t,n){return a(e(c(t).options.path),n)}function u(e,t,n){typeof t==`function`&&(n=t,t={}),Promise.resolve().then(()=>l(e,t)).then(e=>n(null,e),n)}async function d(e,t){return l(e,t)}function f(t,n=0){o(e(c(t).options.path),n)}function p(e,t,n){typeof t==`function`&&(n=t,t=0),Promise.resolve().then(()=>f(e,t)).then(()=>n(null),n)}async function m(e,t=0){f(e,t)}function h(e){c(e)._flushSync()}function g(e,t){Promise.resolve().then(()=>h(e)).then(()=>t(null),t)}async function _(e){h(e)}function v(e){c(e)._flushSync()}function y(e,t){Promise.resolve().then(()=>v(e)).then(()=>t(null),t)}async function b(e){v(e)}function x(t,r){n(e(c(t).options.path),r)}function S(e,t,n){Promise.resolve().then(()=>x(e,t)).then(()=>n(null),n)}async function C(e,t){x(e,t)}function w(t,n,i){r(e(c(t).options.path),n,i)}function T(e,t,n,r){Promise.resolve().then(()=>w(e,t,n)).then(()=>r(null),r)}async function E(e,t,n){w(e,t,n)}function D(t,n,r){s(e(c(t).options.path),n,r)}function O(e,t,n,r){Promise.resolve().then(()=>D(e,t,n)).then(()=>r(null),r)}async function k(e,t,n){D(e,t,n)}function A(e){c(e)._closeSync()}function j(e,t,n,r,i){let a=0;return typeof n==`object`&&n?(a=n.offset??0,r=n.length??t.byteLength,i=n.position??null):(a=n??0,r??=t.byteLength-a),c(e)._readSync(t,a,r,i??null)}function M(e,t,n,r,i){let a;if(typeof t==`string`)a=new TextEncoder().encode(t),typeof n==`number`&&(i=n);else{let e=typeof n==`number`?n:0,i=typeof r==`number`?r:t.byteLength-e;a=new Uint8Array(t.buffer,t.byteOffset+e,i)}return c(e)._writeSync(a,i??null)}function N(e,t,n){let r=0;for(let i of t){let t=j(e,i,0,i.byteLength,n==null?null:n+r);if(r+=t,t<i.byteLength)break}return r}function P(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesRead:N(e,t,n),buffers:t})).then(e=>r(null,e.bytesRead,e.buffers),r)}async function F(e,t,n){return{bytesRead:N(e,t,n),buffers:t}}function I(e,t,n){let r=0;for(let i of t){let t=M(e,i,0,i.byteLength,n==null?null:n+r);r+=t}return r}function L(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesWritten:I(e,t,n),buffers:t})).then(e=>r(null,e.bytesWritten,e.buffers),r)}async function R(e,t,n){return{bytesWritten:I(e,t,n),buffers:t}}function z(t,n){try{a(e(t)),n(!0)}catch{n(!1)}}async function B(t,n){let r=i(e(t));return new Blob([r],{type:n?.type??``})}export{A as closeSync,z as exists,S as fchmod,C as fchmodAsync,x as fchmodSync,T as fchown,E as fchownAsync,w as fchownSync,g as fdatasync,_ as fdatasyncAsync,h as fdatasyncSync,u as fstat,d as fstatAsync,l as fstatSync,y as fsync,b as fsyncAsync,v as fsyncSync,p as ftruncate,m as ftruncateAsync,f as ftruncateSync,O as futimes,k as futimesAsync,D as futimesSync,B as openAsBlob,j as readSync,P as readv,F as readvAsync,N as readvSync,M as writeSync,L as writev,R as writevAsync,I as writevSync};
1
+ import{normalizePath as e}from"./utils.js";import{FileHandle as t}from"./file-handle.js";import{chmodSync as n,chownSync as r,readFileSync as i,statSync as a,truncateSync as o}from"./sync.js";import{utimesSync as s}from"./utimes.js";function getFH(e){return e instanceof t?t.getInstance(e.fd):t.getInstance(e)}function fstatSync(t,n){return a(e(getFH(t).options.path),n)}function fstat(e,t,n){typeof t==`function`&&(n=t,t={}),Promise.resolve().then(()=>fstatSync(e,t)).then(e=>n(null,e),n)}async function fstatAsync(e,t){return fstatSync(e,t)}function ftruncateSync(t,n=0){o(e(getFH(t).options.path),n)}function ftruncate(e,t,n){typeof t==`function`&&(n=t,t=0),Promise.resolve().then(()=>ftruncateSync(e,t)).then(()=>n(null),n)}async function ftruncateAsync(e,t=0){ftruncateSync(e,t)}function fdatasyncSync(e){getFH(e)._flushSync()}function fdatasync(e,t){Promise.resolve().then(()=>fdatasyncSync(e)).then(()=>t(null),t)}async function fdatasyncAsync(e){fdatasyncSync(e)}function fsyncSync(e){getFH(e)._flushSync()}function fsync(e,t){Promise.resolve().then(()=>fsyncSync(e)).then(()=>t(null),t)}async function fsyncAsync(e){fsyncSync(e)}function fchmodSync(t,r){n(e(getFH(t).options.path),r)}function fchmod(e,t,n){Promise.resolve().then(()=>fchmodSync(e,t)).then(()=>n(null),n)}async function fchmodAsync(e,t){fchmodSync(e,t)}function fchownSync(t,n,i){r(e(getFH(t).options.path),n,i)}function fchown(e,t,n,r){Promise.resolve().then(()=>fchownSync(e,t,n)).then(()=>r(null),r)}async function fchownAsync(e,t,n){fchownSync(e,t,n)}function futimesSync(t,n,r){s(e(getFH(t).options.path),n,r)}function futimes(e,t,n,r){Promise.resolve().then(()=>futimesSync(e,t,n)).then(()=>r(null),r)}async function futimesAsync(e,t,n){futimesSync(e,t,n)}function closeSync(e){getFH(e)._closeSync()}function readSync(e,t,n,r,i){let a=0;return typeof n==`object`&&n?(a=n.offset??0,r=n.length??t.byteLength,i=n.position??null):(a=n??0,r??=t.byteLength-a),getFH(e)._readSync(t,a,r,i??null)}function writeSync(e,t,n,r,i){let a;if(typeof t==`string`)a=new TextEncoder().encode(t),typeof n==`number`&&(i=n);else{let e=typeof n==`number`?n:0,i=typeof r==`number`?r:t.byteLength-e;a=new Uint8Array(t.buffer,t.byteOffset+e,i)}return getFH(e)._writeSync(a,i??null)}function readvSync(e,t,n){let r=0;for(let i of t){let t=readSync(e,i,0,i.byteLength,n==null?null:n+r);if(r+=t,t<i.byteLength)break}return r}function readv(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesRead:readvSync(e,t,n),buffers:t})).then(e=>r(null,e.bytesRead,e.buffers),r)}async function readvAsync(e,t,n){return{bytesRead:readvSync(e,t,n),buffers:t}}function writevSync(e,t,n){let r=0;for(let i of t){let t=writeSync(e,i,0,i.byteLength,n==null?null:n+r);r+=t}return r}function writev(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesWritten:writevSync(e,t,n),buffers:t})).then(e=>r(null,e.bytesWritten,e.buffers),r)}async function writevAsync(e,t,n){return{bytesWritten:writevSync(e,t,n),buffers:t}}function exists(t,n){try{a(e(t)),n(!0)}catch{n(!1)}}async function openAsBlob(t,n){let r=i(e(t));return new Blob([r],{type:n?.type??``})}export{closeSync,exists,fchmod,fchmodAsync,fchmodSync,fchown,fchownAsync,fchownSync,fdatasync,fdatasyncAsync,fdatasyncSync,fstat,fstatAsync,fstatSync,fsync,fsyncAsync,fsyncSync,ftruncate,ftruncateAsync,ftruncateSync,futimes,futimesAsync,futimesSync,openAsBlob,readSync,readv,readvAsync,readvSync,writeSync,writev,writevAsync,writevSync};
@@ -1 +1 @@
1
- import{encodeUint8Array as e,getEncodingFromOptions as t}from"./encoding.js";import{normalizePath as n}from"./utils.js";import{ReadStream as r}from"./read-stream.js";import{WriteStream as i}from"./write-stream.js";import{BigIntStats as a,STAT_ATTRIBUTES as o,Stats as s}from"./stats.js";import{chmodSync as c,chownSync as l}from"./sync.js";import u from"@girs/glib-2.0";import d from"@girs/gio-2.0";import{Buffer as f}from"node:buffer";import{createGLibFileError as p}from"@gjsify/utils";import{createInterface as m}from"node:readline";function h(e){if(e==null)return`r`;if(typeof e==`number`){let t=(e&2)!=0,n=(e&1)!=0,r=(e&1024)!=0,i=(e&512)!=0;return t?i?`w+`:`r+`:n?r?`a`:`w`:`r`}switch(e){case`ax`:case`wx`:return`w`;case`ax+`:case`wx+`:return`w+`;case`as`:case`rs+`:return`r+`;case`as+`:return`a+`;default:return e}}function g(e,t,n){try{return u.IOChannel.new_file(e,t)}catch(r){if(n&&t===`r+`&&r?.code===u.FileError.NOENT)return u.file_set_contents(e,new Uint8Array),u.IOChannel.new_file(e,t);throw r}}function _(e,t){return p(e,`open`,{path:t})}var v=class p{options;_file;_ioStream=null;_readStream=null;_gFile;_ioMode;_ioLock=Promise.resolve();static instances={};constructor(e){this.options=e,this.options.flags||=`r`,this.options.mode||=438;let t=n(e.path),r=typeof e.flags==`number`&&(e.flags&64)!=0,i=h(e.flags);try{this._file=g(t,i,r)}catch(e){throw _(e,t)}return this._file.set_encoding(null),this.fd=this._file.unix_get_fd(),this._gFile=d.File.new_for_path(t),this._ioMode=i,p.instances[this.fd]=this,p.getInstance(this.fd)}_getReadStream(){return this._ioStream?{input:this._ioStream.get_input_stream(),seekable:this._ioStream}:this._ioMode===`r`?(this._readStream||=this._gFile.read(null),{input:this._readStream,seekable:this._readStream}):(this._ioStream=this._gFile.open_readwrite(null),{input:this._ioStream.get_input_stream(),seekable:this._ioStream})}_getWriteStream(){if(this._ioStream)return this._ioStream;if(this._ioMode===`r`)throw Error(`FileHandle opened read-only; cannot write`);return this._ioStream=this._gFile.open_readwrite(null),this._ioStream}_serialize(e){let t=this._ioLock.catch(()=>{}).then(e);return this._ioLock=t,t}fd;static getInstance(e){if(!p.instances[e])throw Error(`No instance found for fd!`);return p.instances[e]}async appendFile(e,n){let r=t(n);typeof e==`string`&&(e=f.from(e)),r&&this._file.set_encoding(r);let[i,a]=this._file.write_chars(e,e.length);if(i===u.IOStatus.ERROR)throw Error(`Error on append to file!`)}async chown(e,t){l(n(this.options.path),e,t)}async chmod(e){c(n(this.options.path),e)}createReadStream(e){return new r(this.options.path,e)}createWriteStream(e){return new i(this.options.path,e)}async datasync(){this._file.flush()}async sync(){this._file.flush()}async read(...e){let t,n,r,i;if(typeof e[0]==`object`&&!(e[0]instanceof Uint8Array)&&!(e[0]instanceof f)){let a=e[0];t=a.buffer,n=a.offset,r=a.length,i=a.position}else t=e[0],n=e[1],r=e[2],i=e[3];let a=t,o=n??0,s=r??a?.byteLength??65536,c=i??0;return this._serialize(async()=>{let{input:e,seekable:n}=this._getReadStream();n.seek(BigInt(c),u.SeekType.SET,null);let r=e.read_bytes(s,null).get_data(),i=r?.length??0;return a&&r&&i>0&&a.set(r,o),{bytesRead:i,buffer:t}})}readableWebStream(){let e=globalThis.ReadableStream;if(typeof e!=`function`)throw Error(`readableWebStream() requires a global ReadableStream. Import "node:stream/web" or "@gjsify/streams" before calling this method.`);return new e}async readFile(n){let r=t(n,`buffer`);r&&this._file.set_encoding(r);let[i,a]=this._file.read_to_end();if(i===u.IOStatus.ERROR)throw Error(`Error on read from file!`);return e(r,a)}readLines(e){return m({input:this.createReadStream(e),crlfDelay:1/0})}async stat(e){let t=await new Promise((e,t)=>{this._gFile.query_info_async(o,d.FileQueryInfoFlags.NONE,u.PRIORITY_DEFAULT,null,(n,r)=>{try{e(this._gFile.query_info_finish(r))}catch(e){t(e)}})}),r=n(this.options.path);return e?.bigint?new a(t,r):new s(t,r)}async truncate(e=0){let t=Math.max(0,e);this._file.flush(),this._getWriteStream().get_output_stream().truncate(t,null)}async utimes(e,t){let{utimesSync:r}=await import(`./utimes.js`);r(n(this.options.path),e,t)}async writeFile(e,n){let r=t(n),i;i=typeof e==`string`?f.from(e,r||`utf8`):e,this._file.seek_position(0,u.SeekType.SET);let[a]=this._file.write_chars(i,i.length);if(a===u.IOStatus.ERROR)throw Error(`Error writing to file!`);this._file.flush()}async write(e,...n){let r=null,i=null,a=null,o=null;typeof e==`string`?(r=n[0],i=n[1]):(a=n[0],o=n[1],r=n[2]),i=t(i,typeof e==`string`?`utf8`:null);let s;s=typeof e==`string`?new TextEncoder().encode(e):e;let c=a??0,l=o??s.byteLength-c,d=s.slice(c,c+l),f=r??0;return{bytesWritten:await this._serialize(async()=>{let e=this._getWriteStream();e.seek(BigInt(f),u.SeekType.SET,null);let t=e.get_output_stream(),n=await new Promise((e,n)=>{t.write_bytes_async(new u.Bytes(d),u.PRIORITY_DEFAULT,null,(r,i)=>{try{e(t.write_bytes_finish(i))}catch(e){n(e)}})});return await new Promise((e,n)=>{t.flush_async(u.PRIORITY_DEFAULT,null,(r,i)=>{try{t.flush_finish(i),e()}catch(e){n(e)}})}),n}),buffer:e}}async writev(e,t){let n=0;for(let r of e){let e=f.from(r.buffer,r.byteOffset,r.byteLength),i=await this.write(e,0,e.byteLength,t==null?null:t+n);n+=i.bytesWritten}return{bytesWritten:n,buffers:e}}async readv(e,t){let n=0;for(let r of e){let e=await this.read({buffer:f.from(r.buffer,r.byteOffset,r.byteLength),position:t==null?null:t+n});if(n+=e.bytesRead,e.bytesRead<r.byteLength)break}return{bytesRead:n,buffers:e}}_flushSync(){this._file.flush()}_closeSync(){try{this._ioStream?.close(null)}catch{}try{this._readStream?.close(null)}catch{}this._ioStream=null,this._readStream=null;try{this._file.shutdown(!0)}catch{}delete p.instances[this.fd]}_readSync(e,t,n,r){let i=this._gFile.read(null);try{r!==null&&r>=0&&i.seek(r,u.SeekType.SET,null);let a=i.read_bytes(n,null).get_data();return new Uint8Array(e.buffer,e.byteOffset+t).set(a.subarray(0,a.length)),a.length}finally{i.close(null)}}_writeSync(e,t){let n=this._gFile.open_readwrite(null);try{return t!==null&&t>=0&&n.seek(t,u.SeekType.SET,null),n.get_output_stream().write_bytes(u.Bytes.new(e),null)}finally{n.close(null)}}async close(){try{this._ioStream?.close(null)}catch{}try{this._readStream?.close(null)}catch{}this._ioStream=null,this._readStream=null;try{this._file.shutdown(!0)}catch{}}async[Symbol.asyncDispose](){await this.close()}};export{v as FileHandle};
1
+ import{encodeUint8Array as e,getEncodingFromOptions as t}from"./encoding.js";import{normalizePath as n}from"./utils.js";import{ReadStream as r}from"./read-stream.js";import{WriteStream as i}from"./write-stream.js";import{BigIntStats as a,STAT_ATTRIBUTES as o,Stats as s}from"./stats.js";import{chmodSync as c,chownSync as l}from"./sync.js";import u from"@girs/glib-2.0";import d from"@girs/gio-2.0";import{Buffer as f}from"node:buffer";import{createGLibFileError as p}from"@gjsify/utils";import{createInterface as m}from"node:readline";function resolveIOMode(e){if(e==null)return`r`;if(typeof e==`number`){let t=(e&2)!=0,n=(e&1)!=0,r=(e&1024)!=0,i=(e&512)!=0;return t?i?`w+`:`r+`:n?r?`a`:`w`:`r`}switch(e){case`ax`:case`wx`:return`w`;case`ax+`:case`wx+`:return`w+`;case`as`:case`rs+`:return`r+`;case`as+`:return`a+`;default:return e}}function openIOChannel(e,t,n){try{return u.IOChannel.new_file(e,t)}catch(r){if(n&&t===`r+`&&r?.code===u.FileError.NOENT)return u.file_set_contents(e,new Uint8Array),u.IOChannel.new_file(e,t);throw r}}function mapOpenError(e,t){return p(e,`open`,{path:t})}var h=class FileHandle{options;_file;_ioStream=null;_readStream=null;_gFile;_ioMode;_ioLock=Promise.resolve();static instances={};constructor(e){this.options=e,this.options.flags||=`r`,this.options.mode||=438;let t=n(e.path),r=typeof e.flags==`number`&&(e.flags&64)!=0,i=resolveIOMode(e.flags);try{this._file=openIOChannel(t,i,r)}catch(e){throw mapOpenError(e,t)}return this._file.set_encoding(null),this.fd=this._file.unix_get_fd(),this._gFile=d.File.new_for_path(t),this._ioMode=i,FileHandle.instances[this.fd]=this,FileHandle.getInstance(this.fd)}_getReadStream(){return this._ioStream?{input:this._ioStream.get_input_stream(),seekable:this._ioStream}:this._ioMode===`r`?(this._readStream||=this._gFile.read(null),{input:this._readStream,seekable:this._readStream}):(this._ioStream=this._gFile.open_readwrite(null),{input:this._ioStream.get_input_stream(),seekable:this._ioStream})}_getWriteStream(){if(this._ioStream)return this._ioStream;if(this._ioMode===`r`)throw Error(`FileHandle opened read-only; cannot write`);return this._ioStream=this._gFile.open_readwrite(null),this._ioStream}_serialize(e){let t=this._ioLock.catch(()=>{}).then(e);return this._ioLock=t,t}fd;static getInstance(e){if(!FileHandle.instances[e])throw Error(`No instance found for fd!`);return FileHandle.instances[e]}async appendFile(e,n){let r=t(n);typeof e==`string`&&(e=f.from(e)),r&&this._file.set_encoding(r);let[i,a]=this._file.write_chars(e,e.length);if(i===u.IOStatus.ERROR)throw Error(`Error on append to file!`)}async chown(e,t){l(n(this.options.path),e,t)}async chmod(e){c(n(this.options.path),e)}createReadStream(e){return new r(this.options.path,e)}createWriteStream(e){return new i(this.options.path,e)}async datasync(){this._file.flush()}async sync(){this._file.flush()}async read(...e){let t,n,r,i;if(typeof e[0]==`object`&&!(e[0]instanceof Uint8Array)&&!(e[0]instanceof f)){let a=e[0];t=a.buffer,n=a.offset,r=a.length,i=a.position}else t=e[0],n=e[1],r=e[2],i=e[3];let a=t,o=n??0,s=r??a?.byteLength??65536,c=i??0;return this._serialize(async()=>{let{input:e,seekable:n}=this._getReadStream();n.seek(BigInt(c),u.SeekType.SET,null);let r=e.read_bytes(s,null).get_data(),i=r?.length??0;return a&&r&&i>0&&a.set(r,o),{bytesRead:i,buffer:t}})}readableWebStream(){let e=globalThis.ReadableStream;if(typeof e!=`function`)throw Error(`readableWebStream() requires a global ReadableStream. Import "node:stream/web" or "@gjsify/streams" before calling this method.`);return new e}async readFile(n){let r=t(n,`buffer`);r&&this._file.set_encoding(r);let[i,a]=this._file.read_to_end();if(i===u.IOStatus.ERROR)throw Error(`Error on read from file!`);return e(r,a)}readLines(e){return m({input:this.createReadStream(e),crlfDelay:1/0})}async stat(e){let t=await new Promise((e,t)=>{this._gFile.query_info_async(o,d.FileQueryInfoFlags.NONE,u.PRIORITY_DEFAULT,null,(n,r)=>{try{e(this._gFile.query_info_finish(r))}catch(e){t(e)}})}),r=n(this.options.path);return e?.bigint?new a(t,r):new s(t,r)}async truncate(e=0){let t=Math.max(0,e);this._file.flush(),this._getWriteStream().get_output_stream().truncate(t,null)}async utimes(e,t){let{utimesSync:r}=await import(`./utimes.js`);r(n(this.options.path),e,t)}async writeFile(e,n){let r=t(n),i;i=typeof e==`string`?f.from(e,r||`utf8`):e,this._file.seek_position(0,u.SeekType.SET);let[a]=this._file.write_chars(i,i.length);if(a===u.IOStatus.ERROR)throw Error(`Error writing to file!`);this._file.flush()}async write(e,...n){let r=null,i=null,a=null,o=null;typeof e==`string`?(r=n[0],i=n[1]):(a=n[0],o=n[1],r=n[2]),i=t(i,typeof e==`string`?`utf8`:null);let s;s=typeof e==`string`?new TextEncoder().encode(e):e;let c=a??0,l=o??s.byteLength-c,d=s.slice(c,c+l),f=r??0;return{bytesWritten:await this._serialize(async()=>{let e=this._getWriteStream();e.seek(BigInt(f),u.SeekType.SET,null);let t=e.get_output_stream(),n=await new Promise((e,n)=>{t.write_bytes_async(new u.Bytes(d),u.PRIORITY_DEFAULT,null,(r,i)=>{try{e(t.write_bytes_finish(i))}catch(e){n(e)}})});return await new Promise((e,n)=>{t.flush_async(u.PRIORITY_DEFAULT,null,(r,i)=>{try{t.flush_finish(i),e()}catch(e){n(e)}})}),n}),buffer:e}}async writev(e,t){let n=0;for(let r of e){let e=f.from(r.buffer,r.byteOffset,r.byteLength),i=await this.write(e,0,e.byteLength,t==null?null:t+n);n+=i.bytesWritten}return{bytesWritten:n,buffers:e}}async readv(e,t){let n=0;for(let r of e){let e=await this.read({buffer:f.from(r.buffer,r.byteOffset,r.byteLength),position:t==null?null:t+n});if(n+=e.bytesRead,e.bytesRead<r.byteLength)break}return{bytesRead:n,buffers:e}}_flushSync(){this._file.flush()}_closeSync(){try{this._ioStream?.close(null)}catch{}try{this._readStream?.close(null)}catch{}this._ioStream=null,this._readStream=null;try{this._file.shutdown(!0)}catch{}delete FileHandle.instances[this.fd]}_readSync(e,t,n,r){let i=this._gFile.read(null);try{r!==null&&r>=0&&i.seek(r,u.SeekType.SET,null);let a=i.read_bytes(n,null).get_data();return new Uint8Array(e.buffer,e.byteOffset+t).set(a.subarray(0,a.length)),a.length}finally{i.close(null)}}_writeSync(e,t){let n=this._gFile.open_readwrite(null);try{return t!==null&&t>=0&&n.seek(t,u.SeekType.SET,null),n.get_output_stream().write_bytes(u.Bytes.new(e),null)}finally{n.close(null)}}async close(){try{this._ioStream?.close(null)}catch{}try{this._readStream?.close(null)}catch{}this._ioStream=null,this._readStream=null;try{this._file.shutdown(!0)}catch{}}async[Symbol.asyncDispose](){await this.close()}};export{h as FileHandle};
@@ -1 +1 @@
1
- import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";import{EventEmitter as r}from"node:events";const i=new WeakMap;var a=class extends r{constructor(r,a,s){super(),(!a||typeof a!=`object`)&&(a={persistent:!0});let c=a.persistent!==!1,l=n.Cancellable.new(),u=e(r),d=n.File.new_for_path(u).monitor(n.FileMonitorFlags.NONE,l);d.connect(`changed`,o.bind(this));let f=null;c&&(f=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),i.set(this,{persistent:c,cancellable:l,sourceId:f,watcher:d}),s&&this.on(`change`,s)}close(){let e=i.get(this);e.cancellable.is_cancelled()||(e.cancellable.cancel(),e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null))}ref(){let e=i.get(this);return!e.persistent&&!e.cancellable.is_cancelled()&&(e.persistent=!0,e.sourceId=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),this}unref(){let e=i.get(this);return e.persistent&&(e.persistent=!1,e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null)),this}};function o(e,t,r,i){switch(i){case n.FileMonitorEvent.CHANGES_DONE_HINT:this.emit(`change`,`change`,t.get_basename());break;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:this.emit(`rename`,`rename`,t.get_basename());break}}function s(e){switch(e){case n.FileMonitorEvent.CHANGES_DONE_HINT:return`change`;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:return`rename`;default:return null}}async function*c(t,r){let i=r?.signal;if(i?.aborted)return;let a=e(t),o=n.File.new_for_path(a),c=n.Cancellable.new(),l;try{l=o.monitor(n.FileMonitorFlags.NONE,c)}catch{return}let u=[],d=[],f=!1;function p(e){f||(d.length>0?d.shift().resolve({value:e,done:!1}):u.push(e))}function m(){if(!f)for(f=!0,c.is_cancelled()||c.cancel();d.length>0;)d.shift().resolve({value:void 0,done:!0})}let h=l.connect(`changed`,(e,t,n,r)=>{let i=s(r);i!==null&&p({eventType:i,filename:t?.get_basename()??null})}),g=()=>m();i?.addEventListener(`abort`,g);try{for(;!f;){if(u.length>0){yield u.shift();continue}let e=await new Promise(e=>{d.push({resolve:e})});if(e.done)break;yield e.value}}finally{i?.removeEventListener(`abort`,g);try{l.disconnect(h)}catch{}c.is_cancelled()||c.cancel()}}export{a as FSWatcher,a as default,c as watchAsync};
1
+ import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";import{EventEmitter as r}from"node:events";const i=new WeakMap;var FSWatcher=class extends r{constructor(r,a,o){super(),(!a||typeof a!=`object`)&&(a={persistent:!0});let s=a.persistent!==!1,c=n.Cancellable.new(),l=e(r),u=n.File.new_for_path(l).monitor(n.FileMonitorFlags.NONE,c);u.connect(`changed`,changed.bind(this));let d=null;s&&(d=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),i.set(this,{persistent:s,cancellable:c,sourceId:d,watcher:u}),o&&this.on(`change`,o)}close(){let e=i.get(this);e.cancellable.is_cancelled()||(e.cancellable.cancel(),e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null))}ref(){let e=i.get(this);return!e.persistent&&!e.cancellable.is_cancelled()&&(e.persistent=!0,e.sourceId=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),this}unref(){let e=i.get(this);return e.persistent&&(e.persistent=!1,e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null)),this}};function changed(e,t,r,i){switch(i){case n.FileMonitorEvent.CHANGES_DONE_HINT:this.emit(`change`,`change`,t.get_basename());break;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:this.emit(`rename`,`rename`,t.get_basename());break}}function gioEventToNodeType(e){switch(e){case n.FileMonitorEvent.CHANGES_DONE_HINT:return`change`;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:return`rename`;default:return null}}async function*watchAsync(t,r){let i=r?.signal;if(i?.aborted)return;let a=e(t),o=n.File.new_for_path(a),s=n.Cancellable.new(),c;try{c=o.monitor(n.FileMonitorFlags.NONE,s)}catch{return}let l=[],u=[],d=!1;function enqueue(e){d||(u.length>0?u.shift().resolve({value:e,done:!1}):l.push(e))}function terminate(){if(!d)for(d=!0,s.is_cancelled()||s.cancel();u.length>0;)u.shift().resolve({value:void 0,done:!0})}let f=c.connect(`changed`,(e,t,n,r)=>{let i=gioEventToNodeType(r);i!==null&&enqueue({eventType:i,filename:t?.get_basename()??null})}),abortHandler=()=>terminate();i?.addEventListener(`abort`,abortHandler);try{for(;!d;){if(l.length>0){yield l.shift();continue}let e=await new Promise(e=>{u.push({resolve:e})});if(e.done)break;yield e.value}}finally{i?.removeEventListener(`abort`,abortHandler);try{c.disconnect(f)}catch{}s.is_cancelled()||s.cancel()}}export{FSWatcher,FSWatcher as default,watchAsync};
package/lib/esm/glob.js CHANGED
@@ -1 +1 @@
1
- import{normalizePath as e}from"./utils.js";import{readdirSync as t}from"./sync.js";function n(e){let t=/^([!*+?@])\((.+)\)$/.exec(e);if(t){let[,e,r]=t,i=r.split(`|`).map(e=>n(e)),a=`(?:`+i.join(`|`)+`)`;switch(e){case`!`:return`(?!(?:`+i.join(`|`)+`))[^/]*`;case`*`:return a+`*`;case`+`:return a+`+`;case`?`:return a+`?`;case`@`:return a}}let r=``,i=0;for(;i<e.length;){let t=e[i];if(t===`*`){r+=`[^/]*`,i++;continue}if(t===`?`){r+=`[^/]`,i++;continue}if(t===`[`){let t=e.indexOf(`]`,i+1);if(t===-1){r+=`\\[`,i++;continue}r+=e.slice(i,t+1),i=t+1;continue}if(t===`{`){let t=e.indexOf(`}`,i+1);if(t===-1){r+=`\\{`,i++;continue}let a=e.slice(i+1,t).split(`,`).map(e=>n(e.trim()));r+=`(?:`+a.join(`|`)+`)`,i=t+1;continue}`.+^$|()[]{}`.includes(t)?r+=`\\`+t:r+=t,i++}return r}function r(e){e=e.replace(/\/+/g,`/`).replace(/^\.\//,``);let t=e.split(`/`),r=[];for(let e=0;e<t.length;e++){let i=t[e],a=e===t.length-1;i===`**`?a?r.length>0&&r[r.length-1]===`/`?(r.pop(),r.push(`(?:/.+)?`)):r.push(`(?:.+)?`):r.push(`(?:[^/]+/)*`):(r.push(n(i)),a||r.push(`/`))}return RegExp(`^(?:`+r.join(``)+`)$`)}function i(e){if(!e)return null;if(typeof e==`function`)return e;let t=(Array.isArray(e)?e:[e]).map(e=>r(e));return e=>t.some(t=>t.test(e))}function a(e,n,a){let o=r(e),s=i(a),c;try{c=t(n,{recursive:!0})}catch{return[]}let l=[`.`,...c],u=[];for(let e of l){let t=e.replace(/\\/g,`/`);o.test(t)&&(s&&s(t)||u.push(e))}return u}function o(t,n){let r=Array.isArray(t)?t:[t],i=n?.cwd?e(n.cwd):globalThis.process?.cwd?.()??`/`,o=n?.exclude,s=new Set,c=[];for(let e of r)for(let t of a(e,i,o))s.has(t)||(s.add(t),c.push(t));return c}function s(e,t,n){let r,i;typeof t==`function`?(i=t,r={}):(i=n,r=t||{}),Promise.resolve().then(()=>{try{let t=o(e,r);i(null,t)}catch(e){i(e,[])}})}async function*c(e,t){let n=o(e,t);for(let e of n)yield e}export{s as glob,c as globAsync,o as globSync};
1
+ import{normalizePath as e}from"./utils.js";import{readdirSync as t}from"./sync.js";function segmentToRegexSrc(e){let t=/^([!*+?@])\((.+)\)$/.exec(e);if(t){let[,e,n]=t,r=n.split(`|`).map(e=>segmentToRegexSrc(e)),i=`(?:`+r.join(`|`)+`)`;switch(e){case`!`:return`(?!(?:`+r.join(`|`)+`))[^/]*`;case`*`:return i+`*`;case`+`:return i+`+`;case`?`:return i+`?`;case`@`:return i}}let n=``,r=0;for(;r<e.length;){let t=e[r];if(t===`*`){n+=`[^/]*`,r++;continue}if(t===`?`){n+=`[^/]`,r++;continue}if(t===`[`){let t=e.indexOf(`]`,r+1);if(t===-1){n+=`\\[`,r++;continue}n+=e.slice(r,t+1),r=t+1;continue}if(t===`{`){let t=e.indexOf(`}`,r+1);if(t===-1){n+=`\\{`,r++;continue}let i=e.slice(r+1,t).split(`,`).map(e=>segmentToRegexSrc(e.trim()));n+=`(?:`+i.join(`|`)+`)`,r=t+1;continue}`.+^$|()[]{}`.includes(t)?n+=`\\`+t:n+=t,r++}return n}function globToRegex(e){e=e.replace(/\/+/g,`/`).replace(/^\.\//,``);let t=e.split(`/`),n=[];for(let e=0;e<t.length;e++){let r=t[e],i=e===t.length-1;r===`**`?i?n.length>0&&n[n.length-1]===`/`?(n.pop(),n.push(`(?:/.+)?`)):n.push(`(?:.+)?`):n.push(`(?:[^/]+/)*`):(n.push(segmentToRegexSrc(r)),i||n.push(`/`))}return RegExp(`^(?:`+n.join(``)+`)$`)}function buildExcludePredicate(e){if(!e)return null;if(typeof e==`function`)return e;let t=(Array.isArray(e)?e:[e]).map(e=>globToRegex(e));return e=>t.some(t=>t.test(e))}function matchAll(e,n,r){let i=globToRegex(e),a=buildExcludePredicate(r),o;try{o=t(n,{recursive:!0})}catch{return[]}let s=[`.`,...o],c=[];for(let e of s){let t=e.replace(/\\/g,`/`);i.test(t)&&(a&&a(t)||c.push(e))}return c}function globSync(t,n){let r=Array.isArray(t)?t:[t],i=n?.cwd?e(n.cwd):globalThis.process?.cwd?.()??`/`,a=n?.exclude,o=new Set,s=[];for(let e of r)for(let t of matchAll(e,i,a))o.has(t)||(o.add(t),s.push(t));return s}function glob(e,t,n){let r,i;typeof t==`function`?(i=t,r={}):(i=n,r=t||{}),Promise.resolve().then(()=>{try{let t=globSync(e,r);i(null,t)}catch(e){i(e,[])}})}async function*globAsync(e,t){let n=globSync(e,t);for(let e of n)yield e}export{glob,globAsync,globSync};
@@ -1 +1 @@
1
- import{__exportAll as e}from"./_virtual/_rolldown/runtime.js";import{decode as t,encodeUint8Array as n,getEncodingFromOptions as r}from"./encoding.js";import{normalizePath as i,tempDirPath as a}from"./utils.js";import{watchAsync as o}from"./fs-watcher.js";import{Dirent as s}from"./dirent.js";import{BigIntStats as c,STAT_ATTRIBUTES as ee,Stats as te}from"./stats.js";import{FileHandle as l}from"./file-handle.js";import{createNodeError as u}from"./errors.js";import{accessSync as ne,appendFileSync as re,chmodSync as ie,chownSync as ae,copyFileSync as oe,linkSync as se,readdirSync as ce,readlinkSync as le,realpathSync as ue,renameSync as de,truncateSync as fe}from"./sync.js";import{cpAsync as d}from"./cp.js";import{opendirAsync as f}from"./dir.js";import{globAsync as p}from"./glob.js";import{statfsAsync as m}from"./statfs.js";import{lchmodAsync as h,lchownAsync as g,lutimesAsync as _,utimesAsync as v}from"./utimes.js";import{fchmodAsync as y,fchownAsync as b,fdatasyncAsync as x,fstatAsync as S,fsyncAsync as C,ftruncateAsync as w,futimesAsync as T,openAsBlob as E,readvAsync as D,writevAsync as O}from"./fd-ops.js";import k from"@girs/glib-2.0";import A from"@girs/gio-2.0";import{dirname as pe,join as me}from"node:path";var he=e({access:()=>q,appendFile:()=>J,chmod:()=>Z,chown:()=>Q,copyFile:()=>K,cp:()=>d,default:()=>be,fchmod:()=>y,fchown:()=>b,fdatasync:()=>x,fstat:()=>S,fsync:()=>C,ftruncate:()=>w,futimes:()=>T,glob:()=>p,lchmod:()=>h,lchown:()=>g,link:()=>$,lstat:()=>B,lutimes:()=>_,mkdir:()=>j,mkdtemp:()=>N,open:()=>L,openAsBlob:()=>E,opendir:()=>f,readFile:()=>M,readdir:()=>V,readlink:()=>Y,readv:()=>D,realpath:()=>H,rename:()=>G,rm:()=>W,rmdir:()=>F,stat:()=>z,statfs:()=>m,symlink:()=>U,truncate:()=>X,unlink:()=>I,utimes:()=>v,watch:()=>o,write:()=>R,writeFile:()=>P,writev:()=>O});async function j(e,t){let n;typeof t==`object`&&(t.recursive&&(n=t.recursive),t.mode&&t.mode);let r=i(e);if(n)return ge(r);let a=A.File.new_for_path(r);return new Promise((e,t)=>{a.make_directory_async(k.PRIORITY_DEFAULT,null,(n,i)=>{try{a.make_directory_finish(i),e(void 0)}catch(e){t(u(e,`mkdir`,r))}})})}async function ge(e){let t=A.File.new_for_path(e);try{return await new Promise((e,n)=>{t.make_directory_async(k.PRIORITY_DEFAULT,null,(r,i)=>{try{t.make_directory_finish(i),e()}catch(e){n(e)}})}),e}catch(t){let n=t;if(n.code===A.IOErrorEnum.EXISTS)return;if(n.code===A.IOErrorEnum.NOT_FOUND){let n=pe(e);if(n===e)throw u(t,`mkdir`,e);let r=await ge(n),i=A.File.new_for_path(e);return await new Promise((t,n)=>{i.make_directory_async(k.PRIORITY_DEFAULT,null,(r,a)=>{try{i.make_directory_finish(a),t()}catch(t){n(u(t,`mkdir`,e))}})}),r??e}throw u(t,`mkdir`,e)}}async function M(e,t={encoding:null,flag:`r`}){let a=i(e),o=A.File.new_for_path(a),s,c;try{[s,c]=await new Promise((e,t)=>{o.load_contents_async(null,(n,r)=>{try{e(o.load_contents_finish(r))}catch(e){t(e)}})})}catch(e){throw u(e,`open`,a)}if(!s)throw u(Error(`failed to read file`),`open`,a);return n(r(t,`buffer`),c)}async function N(e,n){let i=r(n),o=a(e);return await j(o,{recursive:!1,mode:448}),t(o,i)}async function P(e,t){let n=i(e),r=A.File.new_for_path(n),a;a=typeof t==`string`?new TextEncoder().encode(t):t instanceof Uint8Array?t:new TextEncoder().encode(String(t));let o=await new Promise((e,t)=>{r.replace_async(null,!1,A.FileCreateFlags.REPLACE_DESTINATION,k.PRIORITY_DEFAULT,null,(i,a)=>{try{e(r.replace_finish(a))}catch(e){t(u(e,`open`,n))}})});if(a.length>0){let e=new k.Bytes(a);await new Promise((t,r)=>{o.write_bytes_async(e,k.PRIORITY_DEFAULT,null,(e,i)=>{try{o.write_bytes_finish(i),t()}catch(e){r(u(e,`write`,n))}})})}await new Promise((e,t)=>{o.close_async(k.PRIORITY_DEFAULT,null,(r,i)=>{try{o.close_finish(i),e()}catch(e){t(u(e,`close`,n))}})})}async function F(e,t){let n=i(e),r=A.File.new_for_path(n);if((await new Promise((e,t)=>{r.query_info_async(`standard::type`,A.FileQueryInfoFlags.NONE,k.PRIORITY_DEFAULT,null,(i,a)=>{try{e(r.query_info_finish(a))}catch(e){t(u(e,`rmdir`,n))}})})).get_file_type()!==A.FileType.DIRECTORY)throw u(Object.assign(Error(),{code:4}),`rmdir`,n);if((await new Promise((e,t)=>{r.enumerate_children_async(`standard::name`,A.FileQueryInfoFlags.NONE,k.PRIORITY_DEFAULT,null,(i,a)=>{try{e(r.enumerate_children_finish(a))}catch(e){t(u(e,`rmdir`,n))}})})).next_file(null)!==null)throw u(Object.assign(Error(),{code:5}),`rmdir`,n);await new Promise((e,t)=>{r.delete_async(k.PRIORITY_DEFAULT,null,(i,a)=>{try{r.delete_finish(a),e()}catch(e){t(u(e,`rmdir`,n))}})})}async function I(e){let t=i(e),n=A.File.new_for_path(t);await new Promise((e,r)=>{n.delete_async(k.PRIORITY_DEFAULT,null,(i,a)=>{try{n.delete_finish(a),e()}catch(e){r(u(e,`unlink`,t))}})})}async function L(e,t,n){return new l({path:e,flags:t,mode:n})}async function R(e,t,n,r,i){return typeof t==`string`?ve(e,t,n,r):_e(e,t,n,r,i)}async function _e(e,t,n,r,i){return{bytesWritten:(await l.getInstance(e).write(t,n,r,i)).bytesWritten,buffer:t}}async function ve(e,t,n,r){return{bytesWritten:(await l.getInstance(e).write(t,n,r)).bytesWritten,buffer:t}}function ye(e,t,n,r){let a=i(e);return new Promise((e,i)=>{let o=A.File.new_for_path(a);o.query_info_async(ee,t,k.PRIORITY_DEFAULT,null,(t,s)=>{try{let t=o.query_info_finish(s);e(r?.bigint?new c(t,a):new te(t,a))}catch(e){i(u(e,n,a))}})})}async function z(e,t){return ye(e,A.FileQueryInfoFlags.NONE,`stat`,t)}async function B(e,t){return ye(e,A.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,t)}async function V(e,t){try{return ce(e,t)}catch(t){throw u(t,`scandir`,e)}}async function H(e){return ue(e)}async function U(e,t,n){let r=i(t),a=i(e);return new Promise((e,t)=>{let n=A.File.new_for_path(r);n.make_symbolic_link_async(a,k.PRIORITY_DEFAULT,null,(i,o)=>{try{n.make_symbolic_link_finish(o),e()}catch(e){t(u(e,`symlink`,a,r))}})})}async function W(e,t){let n=i(e),r=A.File.new_for_path(n),a=t?.recursive||!1,o=t?.force||!1,c;try{c=new s(n)}catch(t){if(o)return;throw u(t,`rm`,e)}if(c.isDirectory()){let r=await V(e,{withFileTypes:!0});if(!a&&r.length)throw u(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)typeof e!=`string`&&await W(me(n,e.name),t)}await new Promise((t,n)=>{r.delete_async(k.PRIORITY_DEFAULT,null,(i,a)=>{try{r.delete_finish(a),t()}catch(r){if(o){t();return}n(u(r,`rm`,e))}})})}async function G(e,t){de(e,t)}async function K(e,t,n){oe(e,t,n)}async function q(e,t){ne(e,t)}async function J(e,t,n){re(e,t,n)}async function Y(e,t){return le(e,t)}async function X(e,t){fe(e,t)}async function Z(e,t){ie(e,t)}async function Q(e,t,n){ae(e,t,n)}async function $(e,t){se(e,t)}var be={readFile:M,mkdir:j,mkdtemp:N,realpath:H,readdir:V,writeFile:P,rmdir:F,unlink:I,open:L,write:R,rm:W,lstat:B,symlink:U,stat:z,rename:G,copyFile:K,access:q,appendFile:J,readlink:Y,truncate:X,chmod:Z,chown:Q,link:$,cp:d,opendir:f,glob:p,watch:o,statfs:m,utimes:v,lutimes:_,lchown:g,lchmod:h,fstat:S,ftruncate:w,fdatasync:x,fsync:C,fchmod:y,fchown:b,futimes:T,readv:D,writev:O,openAsBlob:E};export{q as access,J as appendFile,Z as chmod,Q as chown,K as copyFile,d as cp,be as default,y as fchmod,b as fchown,x as fdatasync,S as fstat,C as fsync,w as ftruncate,T as futimes,p as glob,h as lchmod,g as lchown,$ as link,B as lstat,_ as lutimes,j as mkdir,N as mkdtemp,L as open,E as openAsBlob,f as opendir,he as promises_exports,M as readFile,V as readdir,Y as readlink,D as readv,H as realpath,G as rename,W as rm,F as rmdir,z as stat,m as statfs,U as symlink,X as truncate,I as unlink,v as utimes,o as watch,R as write,P as writeFile,O as writev};
1
+ import{__exportAll as e}from"./_virtual/_rolldown/runtime.js";import{decode as t,encodeUint8Array as n,getEncodingFromOptions as r}from"./encoding.js";import{normalizePath as i,tempDirPath as a}from"./utils.js";import{watchAsync as o}from"./fs-watcher.js";import{Dirent as s}from"./dirent.js";import{BigIntStats as c,STAT_ATTRIBUTES as l,Stats as u}from"./stats.js";import{FileHandle as d}from"./file-handle.js";import{createNodeError as f}from"./errors.js";import{accessSync as p,appendFileSync as m,chmodSync as h,chownSync as g,copyFileSync as _,linkSync as v,readdirSync as y,readlinkSync as b,realpathSync as x,renameSync as S,truncateSync as C}from"./sync.js";import{cpAsync as w}from"./cp.js";import{opendirAsync as T}from"./dir.js";import{globAsync as E}from"./glob.js";import{statfsAsync as D}from"./statfs.js";import{lchmodAsync as O,lchownAsync as k,lutimesAsync as A,utimesAsync as j}from"./utimes.js";import{fchmodAsync as M,fchownAsync as N,fdatasyncAsync as P,fstatAsync as F,fsyncAsync as I,ftruncateAsync as L,futimesAsync as R,openAsBlob as z,readvAsync as B,writevAsync as V}from"./fd-ops.js";import H from"@girs/glib-2.0";import U from"@girs/gio-2.0";import{dirname as W,join as G}from"node:path";var K=e({access:()=>access,appendFile:()=>appendFile,chmod:()=>chmod,chown:()=>chown,copyFile:()=>copyFile,cp:()=>w,default:()=>q,fchmod:()=>M,fchown:()=>N,fdatasync:()=>P,fstat:()=>F,fsync:()=>I,ftruncate:()=>L,futimes:()=>R,glob:()=>E,lchmod:()=>O,lchown:()=>k,link:()=>link,lstat:()=>lstat,lutimes:()=>A,mkdir:()=>mkdir,mkdtemp:()=>mkdtemp,open:()=>open,openAsBlob:()=>z,opendir:()=>T,readFile:()=>readFile,readdir:()=>readdir,readlink:()=>readlink,readv:()=>B,realpath:()=>realpath,rename:()=>rename,rm:()=>rm,rmdir:()=>rmdir,stat:()=>stat,statfs:()=>D,symlink:()=>symlink,truncate:()=>truncate,unlink:()=>unlink,utimes:()=>j,watch:()=>o,write:()=>write,writeFile:()=>writeFile,writev:()=>V});async function mkdir(e,t){let n;typeof t==`object`&&(t.recursive&&(n=t.recursive),t.mode&&t.mode);let r=i(e);if(n)return mkdirRecursiveAsync(r);let a=U.File.new_for_path(r);return new Promise((e,t)=>{a.make_directory_async(H.PRIORITY_DEFAULT,null,(n,i)=>{try{a.make_directory_finish(i),e(void 0)}catch(e){t(f(e,`mkdir`,r))}})})}async function mkdirRecursiveAsync(e){let t=U.File.new_for_path(e);try{return await new Promise((e,n)=>{t.make_directory_async(H.PRIORITY_DEFAULT,null,(r,i)=>{try{t.make_directory_finish(i),e()}catch(e){n(e)}})}),e}catch(t){let n=t;if(n.code===U.IOErrorEnum.EXISTS)return;if(n.code===U.IOErrorEnum.NOT_FOUND){let n=W(e);if(n===e)throw f(t,`mkdir`,e);let r=await mkdirRecursiveAsync(n),i=U.File.new_for_path(e);return await new Promise((t,n)=>{i.make_directory_async(H.PRIORITY_DEFAULT,null,(r,a)=>{try{i.make_directory_finish(a),t()}catch(t){n(f(t,`mkdir`,e))}})}),r??e}throw f(t,`mkdir`,e)}}async function readFile(e,t={encoding:null,flag:`r`}){let a=i(e),o=U.File.new_for_path(a),s,c;try{[s,c]=await new Promise((e,t)=>{o.load_contents_async(null,(n,r)=>{try{e(o.load_contents_finish(r))}catch(e){t(e)}})})}catch(e){throw f(e,`open`,a)}if(!s)throw f(Error(`failed to read file`),`open`,a);return n(r(t,`buffer`),c)}async function mkdtemp(e,n){let i=r(n),o=a(e);return await mkdir(o,{recursive:!1,mode:448}),t(o,i)}async function writeFile(e,t){let n=i(e),r=U.File.new_for_path(n),a;a=typeof t==`string`?new TextEncoder().encode(t):t instanceof Uint8Array?t:new TextEncoder().encode(String(t));let o=await new Promise((e,t)=>{r.replace_async(null,!1,U.FileCreateFlags.REPLACE_DESTINATION,H.PRIORITY_DEFAULT,null,(i,a)=>{try{e(r.replace_finish(a))}catch(e){t(f(e,`open`,n))}})});if(a.length>0){let e=new H.Bytes(a);await new Promise((t,r)=>{o.write_bytes_async(e,H.PRIORITY_DEFAULT,null,(e,i)=>{try{o.write_bytes_finish(i),t()}catch(e){r(f(e,`write`,n))}})})}await new Promise((e,t)=>{o.close_async(H.PRIORITY_DEFAULT,null,(r,i)=>{try{o.close_finish(i),e()}catch(e){t(f(e,`close`,n))}})})}async function rmdir(e,t){let n=i(e),r=U.File.new_for_path(n);if((await new Promise((e,t)=>{r.query_info_async(`standard::type`,U.FileQueryInfoFlags.NONE,H.PRIORITY_DEFAULT,null,(i,a)=>{try{e(r.query_info_finish(a))}catch(e){t(f(e,`rmdir`,n))}})})).get_file_type()!==U.FileType.DIRECTORY)throw f(Object.assign(Error(),{code:4}),`rmdir`,n);if((await new Promise((e,t)=>{r.enumerate_children_async(`standard::name`,U.FileQueryInfoFlags.NONE,H.PRIORITY_DEFAULT,null,(i,a)=>{try{e(r.enumerate_children_finish(a))}catch(e){t(f(e,`rmdir`,n))}})})).next_file(null)!==null)throw f(Object.assign(Error(),{code:5}),`rmdir`,n);await new Promise((e,t)=>{r.delete_async(H.PRIORITY_DEFAULT,null,(i,a)=>{try{r.delete_finish(a),e()}catch(e){t(f(e,`rmdir`,n))}})})}async function unlink(e){let t=i(e),n=U.File.new_for_path(t);await new Promise((e,r)=>{n.delete_async(H.PRIORITY_DEFAULT,null,(i,a)=>{try{n.delete_finish(a),e()}catch(e){r(f(e,`unlink`,t))}})})}async function open(e,t,n){return new d({path:e,flags:t,mode:n})}async function write(e,t,n,r,i){return typeof t==`string`?_writeStr(e,t,n,r):_writeBuf(e,t,n,r,i)}async function _writeBuf(e,t,n,r,i){return{bytesWritten:(await d.getInstance(e).write(t,n,r,i)).bytesWritten,buffer:t}}async function _writeStr(e,t,n,r){return{bytesWritten:(await d.getInstance(e).write(t,n,r)).bytesWritten,buffer:t}}function queryInfoAsync(e,t,n,r){let a=i(e);return new Promise((e,i)=>{let o=U.File.new_for_path(a);o.query_info_async(l,t,H.PRIORITY_DEFAULT,null,(t,s)=>{try{let t=o.query_info_finish(s);e(r?.bigint?new c(t,a):new u(t,a))}catch(e){i(f(e,n,a))}})})}async function stat(e,t){return queryInfoAsync(e,U.FileQueryInfoFlags.NONE,`stat`,t)}async function lstat(e,t){return queryInfoAsync(e,U.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,t)}async function readdir(e,t){try{return y(e,t)}catch(t){throw f(t,`scandir`,e)}}async function realpath(e){return x(e)}async function symlink(e,t,n){let r=i(t),a=i(e);return new Promise((e,t)=>{let n=U.File.new_for_path(r);n.make_symbolic_link_async(a,H.PRIORITY_DEFAULT,null,(i,o)=>{try{n.make_symbolic_link_finish(o),e()}catch(e){t(f(e,`symlink`,a,r))}})})}async function rm(e,t){let n=i(e),r=U.File.new_for_path(n),a=t?.recursive||!1,o=t?.force||!1,c;try{c=new s(n)}catch(t){if(o)return;throw f(t,`rm`,e)}if(c.isDirectory()){let r=await readdir(e,{withFileTypes:!0});if(!a&&r.length)throw f(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)typeof e!=`string`&&await rm(G(n,e.name),t)}await new Promise((t,n)=>{r.delete_async(H.PRIORITY_DEFAULT,null,(i,a)=>{try{r.delete_finish(a),t()}catch(r){if(o){t();return}n(f(r,`rm`,e))}})})}async function rename(e,t){S(e,t)}async function copyFile(e,t,n){_(e,t,n)}async function access(e,t){p(e,t)}async function appendFile(e,t,n){m(e,t,n)}async function readlink(e,t){return b(e,t)}async function truncate(e,t){C(e,t)}async function chmod(e,t){h(e,t)}async function chown(e,t,n){g(e,t,n)}async function link(e,t){v(e,t)}var q={readFile,mkdir,mkdtemp,realpath,readdir,writeFile,rmdir,unlink,open,write,rm,lstat,symlink,stat,rename,copyFile,access,appendFile,readlink,truncate,chmod,chown,link,cp:w,opendir:T,glob:E,watch:o,statfs:D,utimes:j,lutimes:A,lchown:k,lchmod:O,fstat:F,ftruncate:L,fdatasync:P,fsync:I,fchmod:M,fchown:N,futimes:R,readv:B,writev:V,openAsBlob:z};export{access,appendFile,chmod,chown,copyFile,w as cp,q as default,M as fchmod,N as fchown,P as fdatasync,F as fstat,I as fsync,L as ftruncate,R as futimes,E as glob,O as lchmod,k as lchown,link,lstat,A as lutimes,mkdir,mkdtemp,open,z as openAsBlob,T as opendir,K as promises_exports,readFile,readdir,readlink,B as readv,realpath,rename,rm,rmdir,stat,D as statfs,symlink,truncate,unlink,j as utimes,o as watch,write,writeFile,V as writev};
@@ -1 +1 @@
1
- import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";import{Buffer as r}from"node:buffer";import{Readable as i}from"node:stream";var a=class extends i{bytesRead=0;path;pending=!0;fd=null;_gioFile;_inputStream=null;_cancellable=new n.Cancellable;_start;_end;_pos;close(e){this._cancellable.cancel(),this._inputStream&&=(this._inputStream.close_async(t.PRIORITY_DEFAULT,null,()=>{}),null),this.destroy(),e&&e(null)}constructor(t,r){let i=e(t);super({highWaterMark:r?.highWaterMark??64*1024,encoding:r?.encoding,objectMode:!1}),this.path=i,this._gioFile=n.File.new_for_path(i),this._start=r?.start??0,this._end=r?.end??1/0,this._pos=this._start}_construct(e){this._gioFile.read_async(t.PRIORITY_DEFAULT,this._cancellable,(n,r)=>{if(this.destroyed){e();return}try{this._inputStream=this._gioFile.read_finish(r),this.pending=!1,this.emit(`open`,0),this.emit(`ready`),this._start>0&&this._inputStream.can_seek()&&this._inputStream.seek(this._start,t.SeekType.SET,null),e()}catch(t){this._cancellable.is_cancelled()||e(t)}})}_read(e){this._doRead(e)}_doRead(e){let n=e;if(this._end!==1/0){let t=this._end-this._pos+1;if(t<=0){this.push(null);return}n=Math.min(e,t)}let i=this._inputStream;i.read_bytes_async(n,t.PRIORITY_DEFAULT,this._cancellable,(e,t)=>{try{let e=i.read_bytes_finish(t).get_data();if(!e||e.length===0){this.push(null);return}this.bytesRead+=e.length,this._pos+=e.length,this.push(r.from(e))}catch(e){this._cancellable.is_cancelled()||this.destroy(e)}})}_destroy(e,n){this._cancellable.cancel(),this._inputStream&&=(this._inputStream.close_async(t.PRIORITY_DEFAULT,null,()=>{}),null),n(e)}};function o(e,t){return new a(e,t)}export{a as ReadStream,o as createReadStream};
1
+ import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";import{Buffer as r}from"node:buffer";import{Readable as i}from"node:stream";var ReadStream=class extends i{bytesRead=0;path;pending=!0;fd=null;_gioFile;_inputStream=null;_cancellable=new n.Cancellable;_start;_end;_pos;close(e){this._cancellable.cancel(),this._inputStream&&=(this._inputStream.close_async(t.PRIORITY_DEFAULT,null,()=>{}),null),this.destroy(),e&&e(null)}constructor(t,r){let i=e(t);super({highWaterMark:r?.highWaterMark??64*1024,encoding:r?.encoding,objectMode:!1}),this.path=i,this._gioFile=n.File.new_for_path(i),this._start=r?.start??0,this._end=r?.end??1/0,this._pos=this._start}_construct(e){this._gioFile.read_async(t.PRIORITY_DEFAULT,this._cancellable,(n,r)=>{if(this.destroyed){e();return}try{this._inputStream=this._gioFile.read_finish(r),this.pending=!1,this.emit(`open`,0),this.emit(`ready`),this._start>0&&this._inputStream.can_seek()&&this._inputStream.seek(this._start,t.SeekType.SET,null),e()}catch(t){this._cancellable.is_cancelled()||e(t)}})}_read(e){this._doRead(e)}_doRead(e){let n=e;if(this._end!==1/0){let t=this._end-this._pos+1;if(t<=0){this.push(null);return}n=Math.min(e,t)}let i=this._inputStream;i.read_bytes_async(n,t.PRIORITY_DEFAULT,this._cancellable,(e,t)=>{try{let e=i.read_bytes_finish(t).get_data();if(!e||e.length===0){this.push(null);return}this.bytesRead+=e.length,this._pos+=e.length,this.push(r.from(e))}catch(e){this._cancellable.is_cancelled()||this.destroy(e)}})}_destroy(e,n){this._cancellable.cancel(),this._inputStream&&=(this._inputStream.close_async(t.PRIORITY_DEFAULT,null,()=>{}),null),n(e)}};function createReadStream(e,t){return new ReadStream(e,t)}export{ReadStream,createReadStream};
@@ -1 +1 @@
1
- import{statSync as e}from"./sync.js";import{EventEmitter as t}from"node:events";function n(){return{dev:0,ino:0,mode:0,nlink:0,uid:0,gid:0,rdev:0,size:0,blksize:0,blocks:0,atimeMs:0,mtimeMs:0,ctimeMs:0,birthtimeMs:0,atime:new Date(0),mtime:new Date(0),ctime:new Date(0),birthtime:new Date(0),isFile:()=>!1,isDirectory:()=>!1,isBlockDevice:()=>!1,isCharacterDevice:()=>!1,isSymbolicLink:()=>!1,isFIFO:()=>!1,isSocket:()=>!1}}var r=class extends t{_path;_interval;_timerId=null;_prev;_changeCount=0;constructor(e,t){super(),this._path=e,this._interval=t,this._prev=n()}start(){try{this._prev=e(this._path)}catch{}this._timerId=setInterval(()=>{let t;try{t=e(this._path)}catch{t=n()}let r=this._prev;(t.mtimeMs!==r.mtimeMs||t.size!==r.size||t.ino!==r.ino)&&(this._prev=t,this.emit(`change`,t,r))},this._interval)}stop(){this._timerId!==null&&(clearInterval(this._timerId),this._timerId=null),this.emit(`stop`)}addChangeListener(e){this._changeCount++,this.on(`change`,e)}removeChangeListener(e){this._changeCount--,this.removeListener(`change`,e)}removeAllChangeListeners(){this._changeCount=0,this.removeAllListeners(`change`)}get changeListenerCount(){return this._changeCount}};const i=new Map;function a(e,t,n){typeof t==`function`&&(n=t,t={});let a=t.interval??5007,o=e.toString(),s=i.get(o);return s||(s=new r(o,a),s.start(),i.set(o,s)),n&&s.addChangeListener(n),s}function o(e,t){let n=e.toString(),r=i.get(n);r&&(t?r.removeChangeListener(t):r.removeAllChangeListeners(),r.changeListenerCount===0&&(r.stop(),i.delete(n)))}export{r as StatWatcher,o as unwatchFile,a as watchFile};
1
+ import{statSync as e}from"./sync.js";import{EventEmitter as t}from"node:events";function zeroedStat(){return{dev:0,ino:0,mode:0,nlink:0,uid:0,gid:0,rdev:0,size:0,blksize:0,blocks:0,atimeMs:0,mtimeMs:0,ctimeMs:0,birthtimeMs:0,atime:new Date(0),mtime:new Date(0),ctime:new Date(0),birthtime:new Date(0),isFile:()=>!1,isDirectory:()=>!1,isBlockDevice:()=>!1,isCharacterDevice:()=>!1,isSymbolicLink:()=>!1,isFIFO:()=>!1,isSocket:()=>!1}}var StatWatcher=class extends t{_path;_interval;_timerId=null;_prev;_changeCount=0;constructor(e,t){super(),this._path=e,this._interval=t,this._prev=zeroedStat()}start(){try{this._prev=e(this._path)}catch{}this._timerId=setInterval(()=>{let t;try{t=e(this._path)}catch{t=zeroedStat()}let n=this._prev;(t.mtimeMs!==n.mtimeMs||t.size!==n.size||t.ino!==n.ino)&&(this._prev=t,this.emit(`change`,t,n))},this._interval)}stop(){this._timerId!==null&&(clearInterval(this._timerId),this._timerId=null),this.emit(`stop`)}addChangeListener(e){this._changeCount++,this.on(`change`,e)}removeChangeListener(e){this._changeCount--,this.removeListener(`change`,e)}removeAllChangeListeners(){this._changeCount=0,this.removeAllListeners(`change`)}get changeListenerCount(){return this._changeCount}};const n=new Map;function watchFile(e,t,r){typeof t==`function`&&(r=t,t={});let i=t.interval??5007,a=e.toString(),o=n.get(a);return o||(o=new StatWatcher(a,i),o.start(),n.set(a,o)),r&&o.addChangeListener(r),o}function unwatchFile(e,t){let r=e.toString(),i=n.get(r);i&&(t?i.removeChangeListener(t):i.removeAllChangeListeners(),i.changeListenerCount===0&&(i.stop(),n.delete(r)))}export{StatWatcher,unwatchFile,watchFile};
package/lib/esm/statfs.js CHANGED
@@ -1 +1 @@
1
- import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";const r=[`filesystem::size`,`filesystem::free`].join(`,`),i=4096;function a(e){let t=Number(e.get_attribute_uint64(`filesystem::size`)??0),n=Number(e.get_attribute_uint64(`filesystem::free`)??0),r=Math.floor(t/i),a=Math.floor(n/i);return{type:0,bsize:i,blocks:r,bfree:a,bavail:a,files:0,ffree:0}}function o(e){let t=BigInt(e.get_attribute_uint64(`filesystem::size`)??0),n=BigInt(e.get_attribute_uint64(`filesystem::free`)??0),r=BigInt(i),a=t/r,o=n/r;return{type:0n,bsize:r,blocks:a,bfree:o,bavail:o,files:0n,ffree:0n}}function s(t,i){let s=n.File.new_for_path(e(t)).query_filesystem_info(r,null);return i?.bigint===!0?o(s):a(s)}function c(i,s){return new Promise((c,l)=>{let u=n.File.new_for_path(e(i));u.query_filesystem_info_async(r,t.PRIORITY_DEFAULT,null,(e,t)=>{try{let e=u.query_filesystem_info_finish(t);c(s?o(e):a(e))}catch(e){l(e)}})})}function l(e,t,n){typeof t==`function`&&(n=t,t={}),c(e,t?.bigint===!0).then(e=>n(null,e),e=>n(e,null))}async function u(e,t){return c(e,t?.bigint===!0)}export{l as statfs,u as statfsAsync,s as statfsSync};
1
+ import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";const r=[`filesystem::size`,`filesystem::free`].join(`,`),i=4096;function buildStatFs(e){let t=Number(e.get_attribute_uint64(`filesystem::size`)??0),n=Number(e.get_attribute_uint64(`filesystem::free`)??0),r=Math.floor(t/i),a=Math.floor(n/i);return{type:0,bsize:i,blocks:r,bfree:a,bavail:a,files:0,ffree:0}}function buildBigIntStatFs(e){let t=BigInt(e.get_attribute_uint64(`filesystem::size`)??0),n=BigInt(e.get_attribute_uint64(`filesystem::free`)??0),r=BigInt(i),a=t/r,o=n/r;return{type:0n,bsize:r,blocks:a,bfree:o,bavail:o,files:0n,ffree:0n}}function statfsSync(t,i){let a=n.File.new_for_path(e(t)).query_filesystem_info(r,null);return i?.bigint===!0?buildBigIntStatFs(a):buildStatFs(a)}function queryFsInfoAsync(i,a){return new Promise((o,s)=>{let c=n.File.new_for_path(e(i));c.query_filesystem_info_async(r,t.PRIORITY_DEFAULT,null,(e,t)=>{try{let e=c.query_filesystem_info_finish(t);o(a?buildBigIntStatFs(e):buildStatFs(e))}catch(e){s(e)}})})}function statfs(e,t,n){typeof t==`function`&&(n=t,t={}),queryFsInfoAsync(e,t?.bigint===!0).then(e=>n(null,e),e=>n(e,null))}async function statfsAsync(e,t){return queryFsInfoAsync(e,t?.bigint===!0)}export{statfs,statfsAsync,statfsSync};
package/lib/esm/stats.js CHANGED
@@ -1 +1 @@
1
- import{Dirent as e}from"./dirent.js";import t from"@girs/gio-2.0";import{basename as n}from"node:path";const r=`standard::*,time::*,unix::*`;function i(e){let t=e.get_attribute_uint64(`time::access`),n=e.get_attribute_uint32(`time::access-usec`)||0,r=e.get_attribute_uint64(`time::modified`),i=e.get_attribute_uint32(`time::modified-usec`)||0,a=e.get_attribute_uint64(`time::changed`),o=e.get_attribute_uint32(`time::changed-usec`)||0,s=e.get_attribute_uint64(`time::created`),c=e.get_attribute_uint32(`time::created-usec`)||0,l=t*1e3+n/1e3,u=r*1e3+i/1e3,d=a?a*1e3+o/1e3:u,f=s?s*1e3+c/1e3:d;return{dev:e.get_attribute_uint32(`unix::device`)||0,ino:Number(e.get_attribute_uint64(`unix::inode`)||0),mode:e.get_attribute_uint32(`unix::mode`)||0,nlink:e.get_attribute_uint32(`unix::nlink`)||0,uid:e.get_attribute_uint32(`unix::uid`)||0,gid:e.get_attribute_uint32(`unix::gid`)||0,rdev:e.get_attribute_uint32(`unix::rdev`)||0,size:Number(e.get_size()||0),blksize:e.get_attribute_uint32(`unix::block-size`)||4096,blocks:Number(e.get_attribute_uint64(`unix::blocks`)||0),atimeMs:l,mtimeMs:u,ctimeMs:d,birthtimeMs:f,atime:new Date(l),mtime:new Date(u),ctime:new Date(d),birthtime:new Date(f)}}var a=class extends e{dev;ino;mode;nlink;uid;gid;rdev;size;blksize;blocks;atimeMs;mtimeMs;ctimeMs;birthtimeMs;atime;mtime;ctime;birthtime;_info;constructor(e,a,o){let s,c;e instanceof t.FileInfo?(s=e,c=a.toString(),o||=n(c)):(c=e.toString(),typeof a==`string`&&(o=a),o||=n(c),s=t.File.new_for_path(c).query_info(r,t.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)),super(c,o,s.get_file_type()),this._info=s;let l=i(s);this.dev=l.dev,this.ino=l.ino,this.mode=l.mode,this.nlink=l.nlink,this.uid=l.uid,this.gid=l.gid,this.rdev=l.rdev,this.size=l.size,this.blksize=l.blksize,this.blocks=l.blocks,this.atimeMs=l.atimeMs,this.mtimeMs=l.mtimeMs,this.ctimeMs=l.ctimeMs,this.birthtimeMs=l.birthtimeMs,this.atime=l.atime,this.mtime=l.mtime,this.ctime=l.ctime,this.birthtime=l.birthtime}},o=class extends e{dev;ino;mode;nlink;uid;gid;rdev;size;blksize;blocks;atimeMs;mtimeMs;ctimeMs;birthtimeMs;atimeNs;mtimeNs;ctimeNs;birthtimeNs;atime;mtime;ctime;birthtime;_info;constructor(e,a,o){let s,c;e instanceof t.FileInfo?(s=e,c=a.toString(),o||=n(c)):(c=e.toString(),typeof a==`string`&&(o=a),o||=n(c),s=t.File.new_for_path(c).query_info(r,t.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)),super(c,o,s.get_file_type()),this._info=s;let l=i(s);this.dev=BigInt(l.dev),this.ino=BigInt(l.ino),this.mode=BigInt(l.mode),this.nlink=BigInt(l.nlink),this.uid=BigInt(l.uid),this.gid=BigInt(l.gid),this.rdev=BigInt(l.rdev),this.size=BigInt(l.size),this.blksize=BigInt(l.blksize),this.blocks=BigInt(l.blocks),this.atimeMs=BigInt(Math.trunc(l.atimeMs)),this.mtimeMs=BigInt(Math.trunc(l.mtimeMs)),this.ctimeMs=BigInt(Math.trunc(l.ctimeMs)),this.birthtimeMs=BigInt(Math.trunc(l.birthtimeMs)),this.atimeNs=this.atimeMs*1000000n,this.mtimeNs=this.mtimeMs*1000000n,this.ctimeNs=this.ctimeMs*1000000n,this.birthtimeNs=this.birthtimeMs*1000000n,this.atime=l.atime,this.mtime=l.mtime,this.ctime=l.ctime,this.birthtime=l.birthtime}};export{o as BigIntStats,r as STAT_ATTRIBUTES,a as Stats};
1
+ import{Dirent as e}from"./dirent.js";import t from"@girs/gio-2.0";import{basename as n}from"node:path";const r=`standard::*,time::*,unix::*`;function populateFromInfo(e){let t=e.get_attribute_uint64(`time::access`),n=e.get_attribute_uint32(`time::access-usec`)||0,r=e.get_attribute_uint64(`time::modified`),i=e.get_attribute_uint32(`time::modified-usec`)||0,a=e.get_attribute_uint64(`time::changed`),o=e.get_attribute_uint32(`time::changed-usec`)||0,s=e.get_attribute_uint64(`time::created`),c=e.get_attribute_uint32(`time::created-usec`)||0,l=t*1e3+n/1e3,u=r*1e3+i/1e3,d=a?a*1e3+o/1e3:u,f=s?s*1e3+c/1e3:d;return{dev:e.get_attribute_uint32(`unix::device`)||0,ino:Number(e.get_attribute_uint64(`unix::inode`)||0),mode:e.get_attribute_uint32(`unix::mode`)||0,nlink:e.get_attribute_uint32(`unix::nlink`)||0,uid:e.get_attribute_uint32(`unix::uid`)||0,gid:e.get_attribute_uint32(`unix::gid`)||0,rdev:e.get_attribute_uint32(`unix::rdev`)||0,size:Number(e.get_size()||0),blksize:e.get_attribute_uint32(`unix::block-size`)||4096,blocks:Number(e.get_attribute_uint64(`unix::blocks`)||0),atimeMs:l,mtimeMs:u,ctimeMs:d,birthtimeMs:f,atime:new Date(l),mtime:new Date(u),ctime:new Date(d),birthtime:new Date(f)}}var Stats=class extends e{dev;ino;mode;nlink;uid;gid;rdev;size;blksize;blocks;atimeMs;mtimeMs;ctimeMs;birthtimeMs;atime;mtime;ctime;birthtime;_info;constructor(e,i,a){let o,s;e instanceof t.FileInfo?(o=e,s=i.toString(),a||=n(s)):(s=e.toString(),typeof i==`string`&&(a=i),a||=n(s),o=t.File.new_for_path(s).query_info(r,t.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)),super(s,a,o.get_file_type()),this._info=o;let c=populateFromInfo(o);this.dev=c.dev,this.ino=c.ino,this.mode=c.mode,this.nlink=c.nlink,this.uid=c.uid,this.gid=c.gid,this.rdev=c.rdev,this.size=c.size,this.blksize=c.blksize,this.blocks=c.blocks,this.atimeMs=c.atimeMs,this.mtimeMs=c.mtimeMs,this.ctimeMs=c.ctimeMs,this.birthtimeMs=c.birthtimeMs,this.atime=c.atime,this.mtime=c.mtime,this.ctime=c.ctime,this.birthtime=c.birthtime}},BigIntStats=class extends e{dev;ino;mode;nlink;uid;gid;rdev;size;blksize;blocks;atimeMs;mtimeMs;ctimeMs;birthtimeMs;atimeNs;mtimeNs;ctimeNs;birthtimeNs;atime;mtime;ctime;birthtime;_info;constructor(e,i,a){let o,s;e instanceof t.FileInfo?(o=e,s=i.toString(),a||=n(s)):(s=e.toString(),typeof i==`string`&&(a=i),a||=n(s),o=t.File.new_for_path(s).query_info(r,t.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)),super(s,a,o.get_file_type()),this._info=o;let c=populateFromInfo(o);this.dev=BigInt(c.dev),this.ino=BigInt(c.ino),this.mode=BigInt(c.mode),this.nlink=BigInt(c.nlink),this.uid=BigInt(c.uid),this.gid=BigInt(c.gid),this.rdev=BigInt(c.rdev),this.size=BigInt(c.size),this.blksize=BigInt(c.blksize),this.blocks=BigInt(c.blocks),this.atimeMs=BigInt(Math.trunc(c.atimeMs)),this.mtimeMs=BigInt(Math.trunc(c.mtimeMs)),this.ctimeMs=BigInt(Math.trunc(c.ctimeMs)),this.birthtimeMs=BigInt(Math.trunc(c.birthtimeMs)),this.atimeNs=this.atimeMs*1000000n,this.mtimeNs=this.mtimeMs*1000000n,this.ctimeNs=this.ctimeMs*1000000n,this.birthtimeNs=this.birthtimeMs*1000000n,this.atime=c.atime,this.mtime=c.mtime,this.ctime=c.ctime,this.birthtime=c.birthtime}};export{BigIntStats,r as STAT_ATTRIBUTES,Stats};
package/lib/esm/sync.js CHANGED
@@ -1 +1 @@
1
- import{decode as e,encodeUint8Array as t,getEncodingFromOptions as n}from"./encoding.js";import{normalizePath as r,tempDirPath as i}from"./utils.js";import{FSWatcher as a}from"./fs-watcher.js";import{Dirent as o}from"./dirent.js";import{BigIntStats as s,STAT_ATTRIBUTES as c,Stats as l}from"./stats.js";import{FileHandle as u}from"./file-handle.js";import{createNodeError as d,isNotFoundError as f}from"./errors.js";import p from"@girs/glib-2.0";import m from"@girs/gio-2.0";import{join as h}from"node:path";import{Buffer as g}from"node:buffer";import{existsSync as _}from"@gjsify/utils";function v(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NONE,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`stat`,n)}}function y(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`lstat`,n)}}function b(e,t){let n=r(e),i=m.File.new_for_path(n).enumerate_children(`standard::name,standard::type`,m.FileQueryInfoFlags.NONE,null),a=[],s=i.next_file(null);for(;s!==null;){let e=s.get_name(),r=h(n,e);if(t?.withFileTypes?a.push(new o(r,e)):a.push(e),t?.recursive&&s.get_file_type()===m.FileType.DIRECTORY){let n=b(r,t);for(let t of n)typeof t==`string`?a.push(h(e,t)):a.push(t)}s=i.next_file(null)}return a}function x(e){let t=r(e),n=m.File.new_for_path(t),i=0;for(;;){let e=n.query_info(`standard::is-symlink,standard::symlink-target`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);if(!e.get_is_symlink())return n.get_path();let r=e.get_symlink_target(),a=n.get_parent();if(n=a?a.resolve_relative_path(r):m.File.new_for_path(r),++i>40)throw Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`)}}x.native=x;function S(e,t,n){let i=r(t),a=r(e);m.File.new_for_path(i).make_symbolic_link(a,null)}function C(e,i={encoding:null,flag:`r`}){let a=r(e),o=m.File.new_for_path(a);try{let[e,r]=o.load_contents(null);if(!e)throw d(Error(`failed to read file`),`read`,a);return t(n(i,`buffer`),r)}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`read`,a)}}function w(e,t){let n=!1,i=511;if(typeof t==`object`?(t?.recursive&&(n=t.recursive),t?.mode&&(i=t.mode)):i=t||511,e=r(e),typeof i==`string`)throw TypeError(`mode as string is currently not supported!`);if(n)return T(e,i);let a=m.File.new_for_path(e);try{a.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}}function T(e,t){let n=m.File.new_for_path(e);try{return n.make_directory(null),e}catch(n){let r=n;if(r.code===m.IOErrorEnum.EXISTS)return;if(r.code===m.IOErrorEnum.NOT_FOUND){let r=h(e,`..`),i=m.File.new_for_path(r).get_path();if(i===e)throw d(n,`mkdir`,e);let a=T(i,t),o=m.File.new_for_path(e);try{o.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}return a??e}throw d(n,`mkdir`,e)}}function E(e,t){let n=r(e),i=m.File.new_for_path(n);try{if(i.query_info(`standard::type`,m.FileQueryInfoFlags.NONE,null).get_file_type()!==m.FileType.DIRECTORY)throw d(Object.assign(Error(),{code:4}),`rmdir`,n);if(i.enumerate_children(`standard::name`,m.FileQueryInfoFlags.NONE,null).next_file(null)!==null)throw d(Object.assign(Error(),{code:5}),`rmdir`,n);i.delete(null)}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`rmdir`,n)}}function D(e){let t=r(e),n=m.File.new_for_path(t);try{n.delete(null)}catch(e){throw d(e,`unlink`,t)}}function O(e,t){p.file_set_contents(r(e),t)}function k(e,t){let n=r(e),i=r(t),a=m.File.new_for_path(n),o=m.File.new_for_path(i);try{a.move(o,m.FileCopyFlags.OVERWRITE,null,null)}catch(e){throw d(e,`rename`,n,i)}}function A(e,t,n){let i=r(e),a=r(t),o=m.File.new_for_path(i),s=m.File.new_for_path(a),c=m.FileCopyFlags.NONE;n&&!(n&1)?c=m.FileCopyFlags.OVERWRITE:n||(c=m.FileCopyFlags.OVERWRITE);try{o.copy(s,c,null,null)}catch(e){throw d(e,`copyfile`,i,a)}}function j(e,t){let n=r(e),i=m.File.new_for_path(n);try{let e=i.query_info(`access::*`,m.FileQueryInfoFlags.NONE,null);if(t!==void 0&&t!==0){let r={code:14,message:`permission denied, access '${n}'`};if(t&4&&!e.get_attribute_boolean(`access::can-read`)||t&2&&!e.get_attribute_boolean(`access::can-write`)||t&1&&!e.get_attribute_boolean(`access::can-execute`))throw d(r,`access`,n)}}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`access`,n)}}function M(e,t,n){let i=r(e),a=m.File.new_for_path(i),o;o=typeof t==`string`?new TextEncoder().encode(t):t;try{let e=a.append_to(m.FileCreateFlags.NONE,null);o.length>0&&e.write_bytes(new p.Bytes(o),null),e.close(null)}catch(e){throw d(e,`appendfile`,i)}}function N(e,t){let n=r(e),i=m.File.new_for_path(n);try{let e=i.query_info(`standard::symlink-target`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null).get_symlink_target();if(!e)throw Object.assign(Error(`EINVAL: invalid argument, readlink '${n}'`),{code:`EINVAL`,errno:-22,syscall:`readlink`,path:n});return(typeof t==`string`?t:t?.encoding)===`buffer`?g.from(e):e}catch(e){throw typeof e.code==`string`?e:d(e,`readlink`,n)}}function P(e,t){let n=r(e),i=r(t);if(!p.spawn_command_line_sync(`ln ${n} ${i}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, link '${n}' -> '${i}'`),{code:`EPERM`,errno:-1,syscall:`link`,path:n,dest:i})}function F(e,t){let n=r(e),i=m.File.new_for_path(n);try{let e=i.replace(null,!1,m.FileCreateFlags.NONE,null);if(t&&t>0){let[,n]=i.load_contents(null),r=n.slice(0,t);r.length>0&&e.write_bytes(new p.Bytes(r),null)}e.close(null)}catch(e){throw d(e,`truncate`,n)}}function I(e,t){let n=r(e),i=typeof t==`string`?parseInt(t,8):t;if(!p.spawn_command_line_sync(`chmod ${i.toString(8)} ${n}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, chmod '${n}'`),{code:`EPERM`,errno:-1,syscall:`chmod`,path:n})}function L(e,t,n){let i=r(e);if(!p.spawn_command_line_sync(`chown ${t}:${n} ${i}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, chown '${i}'`),{code:`EPERM`,errno:-1,syscall:`chown`,path:i})}function R(e,t,n){return new a(r(e),t,n)}function z(e,t,n){return new u({path:e,flags:t,mode:n})}function B(t,r){let a=n(r),o=i(t);return w(o,{recursive:!1,mode:511}),e(o,a)}function V(e,t){let n=r(e),i=m.File.new_for_path(n),a=t?.recursive||!1,s=t?.force||!1,c;try{c=new o(n)}catch(t){if(s&&f(t))return;throw d(t,`rm`,e)}if(c.isDirectory()){let r=b(e,{withFileTypes:!0});if(!a&&r.length)throw d(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)typeof e!=`string`&&V(h(n,e.name),t)}try{i.delete(null)}catch(t){if(s&&f(t))return;throw d(t,`rm`,e)}}export{j as accessSync,M as appendFileSync,I as chmodSync,L as chownSync,A as copyFileSync,_ as existsSync,P as linkSync,y as lstatSync,w as mkdirSync,B as mkdtempSync,z as openSync,C as readFileSync,b as readdirSync,N as readlinkSync,x as realpathSync,k as renameSync,V as rmSync,E as rmdirSync,v as statSync,S as symlinkSync,F as truncateSync,D as unlinkSync,R as watch,O as writeFileSync};
1
+ import{decode as e,encodeUint8Array as t,getEncodingFromOptions as n}from"./encoding.js";import{normalizePath as r,tempDirPath as i}from"./utils.js";import{FSWatcher as a}from"./fs-watcher.js";import{Dirent as o}from"./dirent.js";import{BigIntStats as s,STAT_ATTRIBUTES as c,Stats as l}from"./stats.js";import{FileHandle as u}from"./file-handle.js";import{createNodeError as d,isNotFoundError as f}from"./errors.js";import p from"@girs/glib-2.0";import m from"@girs/gio-2.0";import{join as h}from"node:path";import{Buffer as g}from"node:buffer";import{existsSync as _}from"@gjsify/utils";function statSync(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NONE,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`stat`,n)}}function lstatSync(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`lstat`,n)}}function readdirSync(e,t){let n=r(e),i=m.File.new_for_path(n).enumerate_children(`standard::name,standard::type`,m.FileQueryInfoFlags.NONE,null),a=[],s=i.next_file(null);for(;s!==null;){let e=s.get_name(),r=h(n,e);if(t?.withFileTypes?a.push(new o(r,e)):a.push(e),t?.recursive&&s.get_file_type()===m.FileType.DIRECTORY){let n=readdirSync(r,t);for(let t of n)typeof t==`string`?a.push(h(e,t)):a.push(t)}s=i.next_file(null)}return a}function realpathSync(e){let t=r(e),n=m.File.new_for_path(t),i=0;for(;;){let e=n.query_info(`standard::is-symlink,standard::symlink-target`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);if(!e.get_is_symlink())return n.get_path();let r=e.get_symlink_target(),a=n.get_parent();if(n=a?a.resolve_relative_path(r):m.File.new_for_path(r),++i>40)throw Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`)}}realpathSync.native=realpathSync;function symlinkSync(e,t,n){let i=r(t),a=r(e);m.File.new_for_path(i).make_symbolic_link(a,null)}function readFileSync(e,i={encoding:null,flag:`r`}){let a=r(e),o=m.File.new_for_path(a);try{let[e,r]=o.load_contents(null);if(!e)throw d(Error(`failed to read file`),`read`,a);return t(n(i,`buffer`),r)}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`read`,a)}}function mkdirSync(e,t){let n=!1,i=511;if(typeof t==`object`?(t?.recursive&&(n=t.recursive),t?.mode&&(i=t.mode)):i=t||511,e=r(e),typeof i==`string`)throw TypeError(`mode as string is currently not supported!`);if(n)return mkdirSyncRecursive(e,i);let a=m.File.new_for_path(e);try{a.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}}function mkdirSyncRecursive(e,t){let n=m.File.new_for_path(e);try{return n.make_directory(null),e}catch(n){let r=n;if(r.code===m.IOErrorEnum.EXISTS)return;if(r.code===m.IOErrorEnum.NOT_FOUND){let r=h(e,`..`),i=m.File.new_for_path(r).get_path();if(i===e)throw d(n,`mkdir`,e);let a=mkdirSyncRecursive(i,t),o=m.File.new_for_path(e);try{o.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}return a??e}throw d(n,`mkdir`,e)}}function rmdirSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{if(i.query_info(`standard::type`,m.FileQueryInfoFlags.NONE,null).get_file_type()!==m.FileType.DIRECTORY)throw d(Object.assign(Error(),{code:4}),`rmdir`,n);if(i.enumerate_children(`standard::name`,m.FileQueryInfoFlags.NONE,null).next_file(null)!==null)throw d(Object.assign(Error(),{code:5}),`rmdir`,n);i.delete(null)}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`rmdir`,n)}}function unlinkSync(e){let t=r(e),n=m.File.new_for_path(t);try{n.delete(null)}catch(e){throw d(e,`unlink`,t)}}function writeFileSync(e,t){p.file_set_contents(r(e),t)}function renameSync(e,t){let n=r(e),i=r(t),a=m.File.new_for_path(n),o=m.File.new_for_path(i);try{a.move(o,m.FileCopyFlags.OVERWRITE,null,null)}catch(e){throw d(e,`rename`,n,i)}}function copyFileSync(e,t,n){let i=r(e),a=r(t),o=m.File.new_for_path(i),s=m.File.new_for_path(a),c=m.FileCopyFlags.NONE;n&&!(n&1)?c=m.FileCopyFlags.OVERWRITE:n||(c=m.FileCopyFlags.OVERWRITE);try{o.copy(s,c,null,null)}catch(e){throw d(e,`copyfile`,i,a)}}function accessSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{let e=i.query_info(`access::*`,m.FileQueryInfoFlags.NONE,null);if(t!==void 0&&t!==0){let r={code:14,message:`permission denied, access '${n}'`};if(t&4&&!e.get_attribute_boolean(`access::can-read`)||t&2&&!e.get_attribute_boolean(`access::can-write`)||t&1&&!e.get_attribute_boolean(`access::can-execute`))throw d(r,`access`,n)}}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`access`,n)}}function appendFileSync(e,t,n){let i=r(e),a=m.File.new_for_path(i),o;o=typeof t==`string`?new TextEncoder().encode(t):t;try{let e=a.append_to(m.FileCreateFlags.NONE,null);o.length>0&&e.write_bytes(new p.Bytes(o),null),e.close(null)}catch(e){throw d(e,`appendfile`,i)}}function readlinkSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{let e=i.query_info(`standard::symlink-target`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null).get_symlink_target();if(!e)throw Object.assign(Error(`EINVAL: invalid argument, readlink '${n}'`),{code:`EINVAL`,errno:-22,syscall:`readlink`,path:n});return(typeof t==`string`?t:t?.encoding)===`buffer`?g.from(e):e}catch(e){throw typeof e.code==`string`?e:d(e,`readlink`,n)}}function linkSync(e,t){let n=r(e),i=r(t);if(!p.spawn_command_line_sync(`ln ${n} ${i}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, link '${n}' -> '${i}'`),{code:`EPERM`,errno:-1,syscall:`link`,path:n,dest:i})}function truncateSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{let e=i.replace(null,!1,m.FileCreateFlags.NONE,null);if(t&&t>0){let[,n]=i.load_contents(null),r=n.slice(0,t);r.length>0&&e.write_bytes(new p.Bytes(r),null)}e.close(null)}catch(e){throw d(e,`truncate`,n)}}function chmodSync(e,t){let n=r(e),i=typeof t==`string`?parseInt(t,8):t;if(!p.spawn_command_line_sync(`chmod ${i.toString(8)} ${n}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, chmod '${n}'`),{code:`EPERM`,errno:-1,syscall:`chmod`,path:n})}function chownSync(e,t,n){let i=r(e);if(!p.spawn_command_line_sync(`chown ${t}:${n} ${i}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, chown '${i}'`),{code:`EPERM`,errno:-1,syscall:`chown`,path:i})}function watch(e,t,n){return new a(r(e),t,n)}function openSync(e,t,n){return new u({path:e,flags:t,mode:n})}function mkdtempSync(t,r){let a=n(r),o=i(t);return mkdirSync(o,{recursive:!1,mode:511}),e(o,a)}function rmSync(e,t){let n=r(e),i=m.File.new_for_path(n),a=t?.recursive||!1,s=t?.force||!1,c;try{c=new o(n)}catch(t){if(s&&f(t))return;throw d(t,`rm`,e)}if(c.isDirectory()){let r=readdirSync(e,{withFileTypes:!0});if(!a&&r.length)throw d(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)typeof e!=`string`&&rmSync(h(n,e.name),t)}try{i.delete(null)}catch(t){if(s&&f(t))return;throw d(t,`rm`,e)}}export{accessSync,appendFileSync,chmodSync,chownSync,copyFileSync,_ as existsSync,linkSync,lstatSync,mkdirSync,mkdtempSync,openSync,readFileSync,readdirSync,readlinkSync,realpathSync,renameSync,rmSync,rmdirSync,statSync,symlinkSync,truncateSync,unlinkSync,watch,writeFileSync};
package/lib/esm/utils.js CHANGED
@@ -1 +1 @@
1
- import{existsSync as e}from"./sync.js";import{URL as t,fileURLToPath as n}from"node:url";function r(e){return e instanceof URL||e instanceof t?n(e):typeof e==`string`?e:e.toString()}function i(){return[...[,,,,,,]].map(()=>`0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`[Math.floor(Math.random()*62)]).join(``)}function a(t){let n;do n=t+i();while(e(n));return n}export{r as normalizePath,i as randomName,a as tempDirPath};
1
+ import{existsSync as e}from"./sync.js";import{URL as t,fileURLToPath as n}from"node:url";function normalizePath(e){return e instanceof URL||e instanceof t?n(e):typeof e==`string`?e:e.toString()}function randomName(){return[...[,,,,,,]].map(()=>`0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`[Math.floor(Math.random()*62)]).join(``)}function tempDirPath(t){let n;do n=t+randomName();while(e(n));return n}export{normalizePath,randomName,tempDirPath};
package/lib/esm/utimes.js CHANGED
@@ -1 +1 @@
1
- import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";function r(e){let n=e instanceof Date?e.getTime():typeof e==`bigint`?Number(e):typeof e==`string`?Date.parse(e):e*1e3;return t.DateTime.new_from_unix_utc(Math.floor(n/1e3))}function i(e,t,i,a){let o=n.File.new_for_path(e),s=new n.FileInfo;s.set_modification_date_time(r(i)),s.set_access_date_time(r(t)),o.set_attributes_from_info(s,a,null)}function a(t,r,a){i(e(t),r,a,n.FileQueryInfoFlags.NONE)}function o(e,t,n,r){Promise.resolve().then(()=>a(e,t,n)).then(()=>r(null),r)}async function s(e,t,n){a(e,t,n)}function c(t,r,a){i(e(t),r,a,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)}function l(e,t,n,r){Promise.resolve().then(()=>c(e,t,n)).then(()=>r(null),r)}async function u(e,t,n){c(e,t,n)}function d(n,r,i){t.spawn_command_line_sync(`chown -h ${r}:${i} ${e(n)}`)}function f(e,t,n,r){Promise.resolve().then(()=>d(e,t,n)).then(()=>r(null),r)}async function p(e,t,n){d(e,t,n)}function m(e,t){}function h(e,t,n){n(null)}async function g(e,t){}export{h as lchmod,g as lchmodAsync,m as lchmodSync,f as lchown,p as lchownAsync,d as lchownSync,l as lutimes,u as lutimesAsync,c as lutimesSync,o as utimes,s as utimesAsync,a as utimesSync};
1
+ import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";function toGLibDateTime(e){let n=e instanceof Date?e.getTime():typeof e==`bigint`?Number(e):typeof e==`string`?Date.parse(e):e*1e3;return t.DateTime.new_from_unix_utc(Math.floor(n/1e3))}function setTimestamps(e,t,r,i){let a=n.File.new_for_path(e),o=new n.FileInfo;o.set_modification_date_time(toGLibDateTime(r)),o.set_access_date_time(toGLibDateTime(t)),a.set_attributes_from_info(o,i,null)}function utimesSync(t,r,i){setTimestamps(e(t),r,i,n.FileQueryInfoFlags.NONE)}function utimes(e,t,n,r){Promise.resolve().then(()=>utimesSync(e,t,n)).then(()=>r(null),r)}async function utimesAsync(e,t,n){utimesSync(e,t,n)}function lutimesSync(t,r,i){setTimestamps(e(t),r,i,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)}function lutimes(e,t,n,r){Promise.resolve().then(()=>lutimesSync(e,t,n)).then(()=>r(null),r)}async function lutimesAsync(e,t,n){lutimesSync(e,t,n)}function lchownSync(n,r,i){t.spawn_command_line_sync(`chown -h ${r}:${i} ${e(n)}`)}function lchown(e,t,n,r){Promise.resolve().then(()=>lchownSync(e,t,n)).then(()=>r(null),r)}async function lchownAsync(e,t,n){lchownSync(e,t,n)}function lchmodSync(e,t){}function lchmod(e,t,n){n(null)}async function lchmodAsync(e,t){}export{lchmod,lchmodAsync,lchmodSync,lchown,lchownAsync,lchownSync,lutimes,lutimesAsync,lutimesSync,utimes,utimesAsync,utimesSync};
@@ -1 +1 @@
1
- import{normalizePath as e}from"./utils.js";import{close as t,open as n,write as r}from"./callback.js";import{Writable as i}from"node:stream";const a=Symbol(`kIsPerformingIO`),o=Symbol(`kIoDone`);function s(t){return e(t)}var c=class extends i{close(e,n=null){this.fd?(t(this.fd,t=>{e(t||n)}),this.fd=null):e(n)}bytesWritten=0;path;pending;fd=null;flags=`w`;mode=438;pos=0;[a]=!1;constructor(e,t={}){super(t),this.path=s(e),t.encoding&&this.setDefaultEncoding(t.encoding)}_construct(e){n(this.path.toString(),this.flags,this.mode,(t,n)=>{if(t){e(t);return}this.fd=n,e(),this.emit(`open`,this.fd),this.emit(`ready`)})}_write(e,t,n){this[a]=!0,r(this.fd,e,0,e.length,this.pos,(e,t)=>{if(this[a]=!1,this.destroyed)return n(e),this.emit(o,e);if(e)return n(e);this.bytesWritten+=t,n()}),this.pos!==void 0&&(this.pos+=e.length)}_destroy(e,t){this[a]?this.once(o,n=>this.close(t,e||n)):this.close(t,e)}};function l(e,t){return new c(e,t)}export{c as WriteStream,l as createWriteStream,s as toPathIfFileURL};
1
+ import{normalizePath as e}from"./utils.js";import{close as t,open as n,write as r}from"./callback.js";import{Writable as i}from"node:stream";const a=Symbol(`kIsPerformingIO`),o=Symbol(`kIoDone`);function toPathIfFileURL(t){return e(t)}var WriteStream=class extends i{close(e,n=null){this.fd?(t(this.fd,t=>{e(t||n)}),this.fd=null):e(n)}bytesWritten=0;path;pending;fd=null;flags=`w`;mode=438;pos=0;[a]=!1;constructor(e,t={}){super(t),this.path=toPathIfFileURL(e),t.encoding&&this.setDefaultEncoding(t.encoding)}_construct(e){n(this.path.toString(),this.flags,this.mode,(t,n)=>{if(t){e(t);return}this.fd=n,e(),this.emit(`open`,this.fd),this.emit(`ready`)})}_write(e,t,n){this[a]=!0,r(this.fd,e,0,e.length,this.pos,(e,t)=>{if(this[a]=!1,this.destroyed)return n(e),this.emit(o,e);if(e)return n(e);this.bytesWritten+=t,n()}),this.pos!==void 0&&(this.pos+=e.length)}_destroy(e,t){this[a]?this.once(o,n=>this.close(t,e||n)):this.close(t,e)}};function createWriteStream(e,t){return new WriteStream(e,t)}export{WriteStream,createWriteStream,toPathIfFileURL};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/fs",
3
- "version": "0.3.20",
3
+ "version": "0.3.21",
4
4
  "description": "Node.js fs module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -34,18 +34,18 @@
34
34
  "fs"
35
35
  ],
36
36
  "devDependencies": {
37
- "@gjsify/cli": "^0.3.20",
38
- "@gjsify/unit": "^0.3.20",
37
+ "@gjsify/cli": "^0.3.21",
38
+ "@gjsify/unit": "^0.3.21",
39
39
  "@types/node": "^25.6.2",
40
40
  "typescript": "^6.0.3"
41
41
  },
42
42
  "dependencies": {
43
43
  "@girs/gio-2.0": "2.88.0-4.0.0-rc.14",
44
44
  "@girs/glib-2.0": "2.88.0-4.0.0-rc.14",
45
- "@gjsify/buffer": "^0.3.20",
46
- "@gjsify/events": "^0.3.20",
47
- "@gjsify/stream": "^0.3.20",
48
- "@gjsify/url": "^0.3.20",
49
- "@gjsify/utils": "^0.3.20"
45
+ "@gjsify/buffer": "^0.3.21",
46
+ "@gjsify/events": "^0.3.21",
47
+ "@gjsify/stream": "^0.3.21",
48
+ "@gjsify/url": "^0.3.21",
49
+ "@gjsify/utils": "^0.3.21"
50
50
  }
51
51
  }