@gjsify/fs 0.31.0 → 0.32.0

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
- import"./_virtual/_rolldown/runtime.js";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,linkSync as d,mkdirSync as f,readFileSync as p,readdirSync as m,readlinkSync as h,realpathSync as g,renameSync as _,rmdirSync as v,truncateSync as y,writeFileSync as b}from"./sync.js";import{open as x,rm as S}from"./promises.js";import C from"@girs/glib-2.0";import w from"@girs/gio-2.0";import{Buffer as T}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=w.File.new_for_path(u);d.query_info_async(n,o,C.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,w.FileQueryInfoFlags.NONE,`stat`,r,i)}function lstat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,w.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,m(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,g(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=w.File.new_for_path(s);l.make_symbolic_link_async(c,C.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}x(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,T.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,T.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]),S(e,n).then(()=>{r(null)}).catch(e=>{r(e)})}function rename(e,t,n){Promise.resolve().then(()=>{try{_(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,h(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{y(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{f(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{v(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{let e=typeof a==`string`?{encoding:a,flag:`r`}:{encoding:a?.encoding??null,flag:a?.flag??`r`};i(null,p(o,e))}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{b(o,n),a(null)}catch(e){a(e)}})}function link(e,t,n){Promise.resolve().then(()=>{try{d(e,t),n(null)}catch(e){n(e)}})}function unlink(t,n){let r=e(t);Promise.resolve().then(()=>{C.unlink(r),n(null)})}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};
1
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{createNodeError as t}from"./errors.js";import{STAT_ATTRIBUTES as n,statsFrom as r}from"./stats.js";import{FileHandle as i}from"./file-handle.js";import{accessSync as a,appendFileSync as o,chmodSync as s,chownSync as c,copyFileSync as l,linkSync 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 withHandle(e,t,n){try{return i.getInstance(e,t)}catch(e){return Promise.resolve().then(()=>n(e)),null}}function parseOptsCb(e,t){return typeof e==`function`?{options:{},callback:e}:{options:e??{},callback:t}}function statImpl(i,a,o,s,c){let l=e(i),u=C.File.new_for_path(l);u.query_info_async(n,a,S.PRIORITY_DEFAULT,null,(e,n)=>{try{c(null,r(u.query_info_finish(n),l,o,s?.bigint))}catch(e){c(t(e,o,l))}})}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,n,r){let{options:i,callback:a}=parseOptsCb(n,r);Promise.resolve().then(()=>{try{a(null,p(e,i))}catch(n){a(t(n,`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(n,r,i,a){let o=typeof i==`function`?i:a;if(typeof o!=`function`)throw TypeError(`Callback must be a function. Received `+typeof o);let s=e(r),c=e(n),l=C.File.new_for_path(s);l.make_symbolic_link_async(c,S.PRIORITY_DEFAULT,null,(e,n)=>{try{l.make_symbolic_link_finish(n),o(null)}catch(e){o(t(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=withHandle(e,`write`,e=>{let r=n[n.length-1];typeof r==`function`&&(typeof t==`string`?r(e,0,``):r(e,0,w.from([])))});if(!r)return;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 i=n[n.length-1],a=n[0],o=n[1],s=n[2];r.write(t,a,o,s).then(e=>{i(null,e.bytesWritten,e.buffer)}).catch(e=>{i(e,0,w.from([]))})}function read(e,...t){let n=t[t.length-1],r=withHandle(e,`read`,e=>{typeof n==`function`&&n(e,0,w.from([]))});if(!r)return;let i,a,o,s;if(!(t.length<=1))if(typeof t[0]==`object`&&!ArrayBuffer.isView(t[0])){let e=t[0];i=e.buffer,a=e.offset,o=e.length,s=e.position}else i=t[0],a=t[1],o=t[2],s=t[3];r.read(i,a,o,s).then(e=>{n(null,e.bytesRead,e.buffer)}).catch(e=>{n(e,0,w.from([]))})}function close(e,t){let done=e=>{typeof t==`function`&&t(e)},n=withHandle(e,`close`,done);n&&n.close().then(()=>done(null)).catch(e=>done(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{l(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{a(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{o(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{s(e,t),n(null)}catch(e){n(e)}})}function chown(e,t,n,r){Promise.resolve().then(()=>{try{c(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(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{let t=typeof i==`string`?{encoding:i,flag:`r`}:{encoding:i?.encoding??null,flag:i?.flag??`r`};r(null,f(e,t))}catch(e){r(e,null)}})}function writeFile(e,t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n;Promise.resolve().then(()=>{try{y(e,t,a),i(null)}catch(e){i(e)}})}function link(e,t,n){Promise.resolve().then(()=>{try{u(e,t),n(null)}catch(e){n(e)}})}function unlink(t,n){let r=e(t);Promise.resolve().then(()=>{S.unlink(r),n(null)})}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/dirent.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";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
+ import"./_virtual/_rolldown/runtime.js";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,o){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,o);break}}_classifySpecialFile(t,n){try{let r=n?.has_attribute(`unix::mode`)===!0?n:e.File.new_for_path(t).query_info(`unix::mode`,e.FileQueryInfoFlags.NONE,null),i=r.has_attribute(`unix::mode`)?r.get_attribute_uint32(`unix::mode`):0;if(i===0)return;switch(i&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};
package/lib/esm/errors.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{createNodeError as e,isNotFoundError as t}from"@gjsify/utils/core";function createNodeError(t,n,r,i){return e(t,n,{path:r.toString(),dest:i?.toString()})}export{createNodeError,t as isNotFoundError};
1
+ import"./_virtual/_rolldown/runtime.js";import{createNodeError as e,isNotFoundError as t}from"@gjsify/utils/core";function createNodeError(t,n,r,i){return typeof t?.code==`string`?t:e(t,n,{path:r.toString(),dest:i?.toString()})}export{createNodeError,t as isNotFoundError};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{createNodeError as e}from"./errors.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";import r from"@girs/giounix-2.0";const i={EPERM:-1,ENOENT:-2,EIO:-5,ENXIO:-6,EBADF:-9,EACCES:-13,EEXIST:-17,ENOTDIR:-20,EISDIR:-21,EINVAL:-22,ENFILE:-23,EMFILE:-24,ETXTBSY:-26,ENOSPC:-28,ESPIPE:-29,EROFS:-30,ENAMETOOLONG:-36,ENOTEMPTY:-39,ELOOP:-40};function fsError(e,t,n,r){let a=`${e}: ${describe(e)}, ${t}`;n&&(a+=` '${n}'`),r&&(a+=` -> '${r}'`);let o=Error(a);return o.code=e,o.errno=i[e]??-1,o.syscall=t,n&&(o.path=n),r&&(o.dest=r),o}function describe(e){switch(e){case`ENOENT`:return`no such file or directory`;case`EEXIST`:return`file already exists`;case`EACCES`:return`permission denied`;case`EISDIR`:return`illegal operation on a directory`;case`ENOTDIR`:return`not a directory`;case`EBADF`:return`bad file descriptor`;case`EPERM`:return`operation not permitted`;case`EINVAL`:return`invalid argument`;case`ELOOP`:return`too many symbolic links encountered`;case`ENAMETOOLONG`:return`name too long`;case`EMFILE`:return`too many open files`;case`ENFILE`:return`file table overflow`;case`EROFS`:return`read-only file system`;case`ESPIPE`:return`invalid seek`;case`ENXIO`:return`no such device or address`;default:return`i/o error`}}let a=null;function hasProcFd(){return a===null&&(a=t.file_test(`/proc/self/fd`,t.FileTest.IS_DIR)),a}function fdPath(e){return hasProcFd()?`/proc/self/fd/${e}`:null}function openFd(e,n,r){let i=t.open(e,n.posix,r);if(i<0)throw classifyOpenFailure(e,n);return i}function closeFd(e){t.close(e)}function classifyOpenFailure(e,t){let r=nameTooLong(e,`open`);if(r)return r;let i=n.File.new_for_path(e),a=null,o=!1;try{let e=i.query_info(`standard::type,standard::symlink-target,unix::mode,access::can-read,access::can-write`,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);answered(e)?a=e:o=!0}catch{a=null}if(o)return refusalNotAboutThePath(e,t,i,null);if(a){if(t.excl)return fsError(`EEXIST`,`open`,e);if(a.get_file_type()===n.FileType.SYMBOLIC_LINK&&!t.nofollow){let n=walkSymlinkChain(i);if(n===`loop`)return fsError(`ELOOP`,`open`,e);if(n===`too-long`)return fsError(`ENAMETOOLONG`,`open`,e);if(n===`dangling`&&!t.creat)return fsError(`ENOENT`,`open`,e)}return a.get_file_type()===n.FileType.DIRECTORY&&t.writable?fsError(`EISDIR`,`open`,e):t.directory&&a.get_file_type()!==n.FileType.DIRECTORY?fsError(`ENOTDIR`,`open`,e):refusalNotAboutThePath(e,t,i,a)}if(ancestorIsNotADirectory(i))return fsError(`ENOTDIR`,`open`,e);if(!t.creat)return fsError(`ENOENT`,`open`,e);let s=i.get_parent();if(!s)return fsError(`ENOENT`,`open`,e);try{s.query_info(`standard::type`,n.FileQueryInfoFlags.NONE,null)}catch{return fsError(`ENOENT`,`open`,e)}return refusalNotAboutThePath(e,t,i,null)}function ancestorIsNotADirectory(e){for(let t=e.get_parent();t;t=t.get_parent()){let e;try{e=t.query_info(`standard::type`,n.FileQueryInfoFlags.NONE,null)}catch{continue}return answered(e)?e.get_file_type()!==n.FileType.DIRECTORY:!1}return!1}function answered(e){return e!==null&&e.has_attribute(`standard::type`)}function nameTooLong(e,t){let n=new TextEncoder;if(n.encode(e).length>4096)return fsError(`ENAMETOOLONG`,t,e);for(let r of e.split(`/`))if(n.encode(r).length>255)return fsError(`ENAMETOOLONG`,t,e);return null}function walkSymlinkChain(e){let t=new TextEncoder,r=e;for(let e=0;e<40;e++){let e;try{e=r.query_info(`standard::type,standard::symlink-target`,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch{return`dangling`}if(!answered(e)||e.get_file_type()!==n.FileType.SYMBOLIC_LINK)return`resolved`;let i=e.get_symlink_target();if(!i)return`dangling`;if(t.encode(i).length>4096)return`too-long`;let a=r.get_parent();r=i.startsWith(`/`)?n.File.new_for_path(i):a?.resolve_relative_path(i)??n.File.new_for_path(i)}return`loop`}function refusalNotAboutThePath(e,n,r,i){let a=t.open(`/dev/null`,0,0);if(a<0)return fsError(`EMFILE`,`open`,e);t.close(a);let o=i!==null&&(i.get_attribute_uint32(`unix::mode`)&146)==0;if((n.writable||n.creat)&&!o)try{if(r.query_filesystem_info(`filesystem::readonly`,null).get_attribute_boolean(`filesystem::readonly`))return fsError(`EROFS`,`open`,e)}catch{}return i&&nothingOnTheOtherEnd(n,i)?fsError(`ENXIO`,`open`,e):fsError(`EACCES`,`open`,e)}function nothingOnTheOtherEnd(e,t){if(!t.has_attribute(`unix::mode`))return!1;let n=t.get_attribute_uint32(`unix::mode`)&61440;if(!(n===8192||n===24576||n===4096))return!1;let permits=e=>t.has_attribute(e)&&t.get_attribute_boolean(e);return!(e.readable&&!permits(`access::can-read`)||e.writable&&!permits(`access::can-write`))}function classifyMkdirFailure(e){let t=nameTooLong(e,`mkdir`);if(t)return t;let r=n.File.new_for_path(e);try{return answered(r.query_info(`standard::type`,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null))?fsError(`EEXIST`,`mkdir`,e):fsError(`EACCES`,`mkdir`,e)}catch{}let i=r.get_parent();if(!i)return fsError(`ENOENT`,`mkdir`,e);try{let t=i.query_info(`standard::type`,n.FileQueryInfoFlags.NONE,null);if(answered(t)&&t.get_file_type()!==n.FileType.DIRECTORY)return fsError(`ENOTDIR`,`mkdir`,e)}catch{return fsError(`ENOENT`,`mkdir`,e)}return fsError(`EACCES`,`mkdir`,e)}const o=new Map,s=new Map,c=new Map;function seekHandle(e){let n=o.get(e);return n||(n=t.IOChannel.unix_new(e),n.set_encoding(null),n.set_buffered(!1),n.set_close_on_unref(!1),o.set(e,n)),n}function input(e){let t=s.get(e);return t||(t=r.InputStream.new(e,!1),s.set(e,t)),t}function output(e){let t=c.get(e);return t||(t=r.OutputStream.new(e,!1),c.set(e,t)),t}const l=new Map;function isSeekableFd(e,t){let n=l.get(e);return n===void 0&&(n=probeSeekable(e,t),l.set(e,n)),n}function probeSeekable(e,r){try{let t=n.File.new_for_path(fdPath(e)??r).query_info(`unix::mode`,n.FileQueryInfoFlags.NONE,null);if(t.has_attribute(`unix::mode`)){let e=t.get_attribute_uint32(`unix::mode`)&61440;if(e===4096||e===49152)return!1}}catch{}try{return seekHandle(e).seek_position(0,t.SeekType.CUR),!0}catch{return!1}}function seekFd(e,n){seekHandle(e).seek_position(n,t.SeekType.SET)}function tellFd(e){if(!hasProcFd())return null;try{let[n,r]=t.file_get_contents(`/proc/self/fdinfo/${e}`);if(!n)return null;let i=/^pos:\s*(\d+)/m.exec(new TextDecoder().decode(r));return i?Number(i[1]):null}catch{return null}}function readFd(e,t){return t<=0?new Uint8Array:input(e).read_bytes(t,null).get_data()??new Uint8Array}function writeFd(e,t){if(t.length===0)return 0;let[,n]=output(e).write_all(t,null);return n}function fsyncFd(e){output(e).flush(null),t.fsync(e)}function releaseFd(e){let t=c.get(e);if(t)try{t.flush(null)}catch{}o.delete(e),s.delete(e),c.delete(e),l.delete(e)}function sizeOfFd(e,t){let r=fdPath(e)??t,i=n.File.new_for_path(r).query_info(`standard::size`,n.FileQueryInfoFlags.NONE,null);return Number(i.get_size())}function truncateFd(t,r,i){let a=n.File.new_for_path(fdPath(t)??i),o;try{let e=a.append_to(n.FileCreateFlags.NONE,null);try{e.truncate(r,null)}finally{e.close(null)}return}catch(e){o=e}try{let e=a.open_readwrite(null);try{e.get_output_stream().truncate(r,null)}finally{e.close(null)}return}catch{}throw e(o,`ftruncate`,i)}export{answered,classifyMkdirFailure,classifyOpenFailure,closeFd,fdPath,fsError,fsyncFd,hasProcFd,isSeekableFd,openFd,readFd,releaseFd,seekFd,sizeOfFd,tellFd,truncateFd,writeFd};
package/lib/esm/fd-ops.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{FileHandle as t}from"./file-handle.js";import{isStdFd as n,readStdFdSync as r,writeStdFdSync as i}from"./std-fd.js";import{chmodSync as a,chownSync as o,readFileSync as s,statSync as c,truncateSync as l}from"./sync.js";import{utimesSync as u}from"./utimes.js";function getFH(e){return e instanceof t?t.getInstance(e.fd):t.getInstance(e)}function fstatSync(t,n){return c(e(getFH(t).options.path),n)}function fstat(e,t,n){let r=typeof t==`function`?t:n;fstatAsync(e,typeof t==`function`?{}:t).then(e=>r(null,e),e=>r(e,void 0))}async function fstatAsync(e,t){return t?.bigint,fstatSync(e,t)}function ftruncateSync(t,n=0){l(e(getFH(t).options.path),n)}function ftruncate(e,t,n){let r=typeof t==`function`?t:n;ftruncateAsync(e,typeof t==`function`?0:t).then(()=>r(null),r)}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,n){a(e(getFH(t).options.path),n)}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,r){o(e(getFH(t).options.path),n,r)}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){u(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){n(e)||getFH(e)._closeSync()}function readSync(e,t,i,a,o){let s=0;return typeof i==`object`&&i?(s=i.offset??0,a=i.length??t.byteLength,o=i.position??null):(s=i??0,a??=t.byteLength-s),n(e)?r(e,t,s,a):getFH(e)._readSync(t,s,a,o??null)}function writeSync(e,t,r,a,o){let s;if(typeof t==`string`)s=new TextEncoder().encode(t),typeof r==`number`&&(o=r);else{let e=typeof r==`number`?r:0,n=typeof a==`number`?a:t.byteLength-e;s=new Uint8Array(t.buffer,t.byteOffset+e,n)}return n(e)?i(e,s):getFH(e)._writeSync(s,o??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){let i=typeof n==`function`?n:r;readvAsync(e,t,typeof n==`function`?null:n).then(e=>i(null,e.bytesRead,e.buffers),e=>i(e,0,t))}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){let i=typeof n==`function`?n:r;writevAsync(e,t,typeof n==`function`?null:n).then(e=>i(null,e.bytesWritten,e.buffers),e=>i(e,0,t))}async function writevAsync(e,t,n){return{bytesWritten:writevSync(e,t,n),buffers:t}}function exists(t,n){try{c(e(t)),n(!0)}catch{n(!1)}}async function openAsBlob(t,n){let r=s(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
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{utimesSync as t}from"./utimes.js";import{isStdFd as n,readStdFdSync as r,writeStdFdSync as i}from"./std-fd.js";import{FileHandle as a}from"./file-handle.js";import{chmodSync as o,chownSync as s,readFileSync as c,statSync as l}from"./sync.js";function getFH(e,t){return a.getInstance(e,t)}function fstatSync(e,t){return l(getFH(e,`fstat`)._fdStatTarget(),t)}function fstat(e,t,n){let r=typeof t==`function`?t:n;fstatAsync(e,typeof t==`function`?{}:t).then(e=>r(null,e),e=>r(e,void 0))}async function fstatAsync(e,t){return t?.bigint,fstatSync(e,t)}function ftruncateSync(e,t=0){getFH(e,`ftruncate`)._truncateSync(t)}function ftruncate(e,t,n){let r=typeof t==`function`?t:n;ftruncateAsync(e,typeof t==`function`?0:t).then(()=>r(null),r)}async function ftruncateAsync(e,t=0){ftruncateSync(e,t)}function fdatasyncSync(e){getFH(e,`fdatasync`)._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,`fsync`)._flushSync()}function fsync(e,t){Promise.resolve().then(()=>fsyncSync(e)).then(()=>t(null),t)}async function fsyncAsync(e){fsyncSync(e)}function fchmodSync(e,t){o(getFH(e,`fchmod`)._fdStatTarget(),t)}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,r){s(e(getFH(t,`fchown`).options.path),n,r)}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(n,r,i){t(e(getFH(n,`futimes`).options.path),r,i)}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){n(e)||getFH(e,`close`)._closeSync()}function readSync(e,t,i,a,o){let s=0;return typeof i==`object`&&i?(s=i.offset??0,a=i.length??t.byteLength-s,o=i.position??null):(s=i??0,a??=t.byteLength-s),n(e)?r(e,t,s,a):getFH(e,`read`)._readSync(t,s,a,o??null)}function writeSync(e,t,r,a,o){let s;if(typeof t==`string`)s=new TextEncoder().encode(t),typeof r==`number`&&(o=r);else{let e=typeof r==`number`?r:0,n=typeof a==`number`?a:t.byteLength-e;s=new Uint8Array(t.buffer,t.byteOffset+e,n)}return n(e)?i(e,s):getFH(e,`write`)._writeSync(s,o??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){let i=typeof n==`function`?n:r;readvAsync(e,t,typeof n==`function`?null:n).then(e=>i(null,e.bytesRead,e.buffers),e=>i(e,0,t))}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){let i=typeof n==`function`?n:r;writevAsync(e,t,typeof n==`function`?null:n).then(e=>i(null,e.bytesWritten,e.buffers),e=>i(e,0,t))}async function writevAsync(e,t,n){return{bytesWritten:writevSync(e,t,n),buffers:t}}function exists(t,n){try{l(e(t)),n(!0)}catch{n(!1)}}async function openAsBlob(t,n){let r=c(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"./_virtual/_rolldown/runtime.js";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{mapOpenError as c,openIOChannel as l,resolveIOMode as u,shouldCreate as d}from"./file-handle-open.js";import{chmodSync as f,chownSync as p}from"./sync.js";import m from"@girs/glib-2.0";import h from"@girs/gio-2.0";import{Buffer as g}from"node:buffer";import{createInterface as _}from"node:readline";var v=class FileHandle{options;_file;_ioStream=null;_readStream=null;_gFile;_ioMode;_readPos=0;_ioLock=Promise.resolve();static instances={};constructor(e){this.options=e,this.options.flags||=`r`,this.options.mode||=438;let t=n(e.path),r=d(e.flags),i=u(e.flags);try{this._file=l(t,i,r)}catch(e){throw c(e,t)}return this._file.set_encoding(null),this.fd=this._file.unix_get_fd(),this._gFile=h.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=g.from(e)),r&&this._file.set_encoding(r);let[i,a]=this._file.write_chars(e,e.length);if(i===m.IOStatus.ERROR)throw Error(`Error on append to file!`)}async chown(e,t){p(n(this.options.path),e,t)}async chmod(e){f(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 g)){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),m.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===m.IOStatus.ERROR)throw Error(`Error on read from file!`);return e(r,a)}readLines(e){return _({input:this.createReadStream(e),crlfDelay:1/0})}async stat(e){let t=await new Promise((e,t)=>{this._gFile.query_info_async(o,h.FileQueryInfoFlags.NONE,m.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`?g.from(e,r||`utf8`):e,this._file.seek_position(0,m.SeekType.SET);let[a]=this._file.write_chars(i,i.length);if(a===m.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,u=s.slice(c,c+l),d=r??0;return{bytesWritten:await this._serialize(async()=>{let e=this._getWriteStream();e.seek(BigInt(d),m.SeekType.SET,null);let t=e.get_output_stream(),n=await new Promise((e,n)=>{t.write_bytes_async(new m.Bytes(u),m.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(m.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=g.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:g.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{}let e=FileHandle;delete e.instances[this.fd]}_readSync(e,t,n,r){let i=this._gFile.read(null);try{let a=r!==null&&r>=0,o=a?r:this._readPos;o>0&&i.seek(o,m.SeekType.SET,null);let s=i.read_bytes(n,null).get_data()??new Uint8Array;return new Uint8Array(e.buffer,e.byteOffset+t).set(s.subarray(0,s.length)),a||(this._readPos+=s.length),s.length}finally{i.close(null)}}_writeSync(e,t){let n=this._gFile.open_readwrite(null);try{return t!==null&&t>=0&&n.seek(t,m.SeekType.SET,null),n.get_output_stream().write_bytes(m.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()}pull(...e){throw Error('FileHandle.pull() is not implemented in @gjsify/fs yet — requires `node:stream/iter` (Node 25.9+) which @gjsify/stream has not ported. Track gjsify Open TODO "Node 25 stream/iter integration".')}writer(e){throw Error('FileHandle.writer() is not implemented in @gjsify/fs yet — requires `node:stream/iter` (Node 25.9+) which @gjsify/stream has not ported. Track gjsify Open TODO "Node 25 stream/iter integration".')}};export{v as FileHandle};
1
+ import"./_virtual/_rolldown/runtime.js";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{normalizeMode as i,parseOpenFlags as a}from"./posix-flags.js";import{WriteStream as o}from"./write-stream.js";import{closeFd as s,fdPath as c,fsError as l,fsyncFd as u,isSeekableFd as d,openFd as f,readFd as p,releaseFd as m,seekFd as h,sizeOfFd as g,tellFd as _,truncateFd as v,writeFd as y}from"./fd-io.js";import{STAT_ATTRIBUTES as b,statsFrom as x}from"./stats.js";import{chmodSync as S,chownSync as C}from"./sync.js";import w from"@girs/glib-2.0";import T from"@girs/gio-2.0";import{Buffer as E}from"node:buffer";import{createInterface as D}from"node:readline";var O=class FileHandle{options;_gFile;_pathStr;_spec;_pos=0;_closed=!1;static instances={};constructor(e){this.options=e,this.options.flags??=`r`;let t=n(e.path);this._spec=a(this.options.flags),this.options.mode??=438;let r=i(this.options.mode,438);return this.fd=f(t,this._spec,r),this._pathStr=t,this._gFile=T.File.new_for_path(t),FileHandle.instances[this.fd]=this,FileHandle.getInstance(this.fd)}_readCore(e,t,n,r){if(this._assertOpen(`read`),!this._spec.readable)throw l(`EBADF`,`read`,this._pathStr);if(n>e.byteLength-t){let r=RangeError(`The value of "length" is out of range. It must be <= ${e.byteLength-t}. Received ${n}`);throw r.code=`ERR_OUT_OF_RANGE`,r}let i=r!=null&&r>=0,a=d(this.fd,this._pathStr);if(i&&!a)throw l(`ESPIPE`,`read`,this._pathStr);let o=i?r:this._pos;a&&h(this.fd,o);let s=p(this.fd,n);return s.length>0&&new Uint8Array(e.buffer,e.byteOffset+t,s.length).set(s),!i&&a&&(this._pos=o+s.length),s.length}_writeCore(e,t){if(this._assertOpen(`write`),!this._spec.writable)throw l(`EBADF`,`write`,this._pathStr);if(this._spec.append){let t=y(this.fd,e);return this._pos=_(this.fd)??g(this.fd,this._pathStr),t}let n=t!=null&&t>=0,r=d(this.fd,this._pathStr);if(n&&!r)throw l(`ESPIPE`,`write`,this._pathStr);let i=n?t:this._pos;r&&h(this.fd,i);let a=y(this.fd,e);return!n&&r&&(this._pos=i+a),a}_assertOpen(e){if(this._closed)throw l(`EBADF`,e,this._pathStr)}_truncateCore(e){if(this._assertOpen(`ftruncate`),!this._spec.writable)throw l(`EINVAL`,`ftruncate`,this._pathStr);v(this.fd,Math.max(0,e),this._pathStr)}_readToEnd(){let e=[],t=0;for(;;){let n=new Uint8Array(64*1024),r=this._readCore(n,0,n.length,null);if(r===0)break;e.push(n.subarray(0,r)),t+=r}let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}_fdTarget(){return c(this.fd)??this._pathStr}fd;static getInstance(e,t=`read`){let n=e instanceof FileHandle?e.fd:e,r=FileHandle.instances[n];if(!r)throw l(`EBADF`,t);return r}async appendFile(e,t){await this.writeFile(e,t)}async chown(e,t){this._assertOpen(`fchown`),C(n(this.options.path),e,t)}async chmod(e){this._assertOpen(`fchmod`),S(this._fdTarget(),e)}createReadStream(e){return new r(this.options.path,{...e,fd:this.fd})}createWriteStream(e){return new o(this.options.path,{...e,fd:this.fd,fdFromHandle:!0})}async datasync(){this._assertOpen(`fdatasync`),u(this.fd)}async sync(){this._assertOpen(`fsync`),u(this.fd)}async read(...e){let t,n,r,i;if(typeof e[0]==`object`&&!(e[0]instanceof Uint8Array)&&!(e[0]instanceof E)){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?a.byteLength-o:65536);return{bytesRead:this._readCore(t,o,s,i??null),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){return e(t(n,`buffer`),this._readToEnd())}readLines(e){return D({input:this.createReadStream(e),crlfDelay:1/0})}async stat(e){this._assertOpen(`fstat`);let t=T.File.new_for_path(this._fdTarget());return x(await new Promise((e,n)=>{t.query_info_async(b,T.FileQueryInfoFlags.NONE,w.PRIORITY_DEFAULT,null,(r,i)=>{try{e(t.query_info_finish(i))}catch(e){n(e)}})}),this._pathStr,`fstat`,e?.bigint)}async truncate(e=0){this._truncateCore(e)}async utimes(e,t){this._assertOpen(`futimes`);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`?E.from(e,r||`utf8`):e,this._writeCore(i,null)}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,u=s.subarray(c,c+l);return{bytesWritten:this._writeCore(u,r??null),buffer:e}}async writev(e,t){let n=0;for(let r of e){let e=E.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:E.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(){u(this.fd)}_closeSync(){this._teardown()}_readSync(e,t,n,r){return this._readCore(e,t,n,r)}_writeSync(e,t){return this._writeCore(e,t)}_readToEndSync(){return this._readToEnd()}_truncateSync(e){this._truncateCore(e)}_fdStatTarget(){return this._fdTarget()}_teardown(){if(this._closed)return;this._closed=!0,m(this.fd),s(this.fd);let e=FileHandle;delete e.instances[this.fd]}async close(){this._teardown()}async[Symbol.asyncDispose](){await this.close()}pull(...e){throw Error('FileHandle.pull() is not implemented in @gjsify/fs yet — requires `node:stream/iter` (Node 25.9+) which @gjsify/stream has not ported. Track gjsify Open TODO "Node 25 stream/iter integration".')}writer(e){throw Error('FileHandle.writer() is not implemented in @gjsify/fs yet — requires `node:stream/iter` (Node 25.9+) which @gjsify/stream has not ported. Track gjsify Open TODO "Node 25 stream/iter integration".')}};export{O as FileHandle};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{FSWatcher as e}from"./fs-watcher.js";import{ReadStream as t,createReadStream as n}from"./read-stream.js";import{WriteStream as r,createWriteStream as i}from"./write-stream.js";import{Dirent as a}from"./dirent.js";import{BigIntStats as o,Stats as s}from"./stats.js";import{accessSync as c,appendFileSync as l,chmodSync as u,chownSync as d,copyFileSync as f,existsSync as p,linkSync as m,lstatSync as h,mkdirSync as g,mkdtempSync as _,openSync as v,readFileSync as y,readdirSync as b,readlinkSync as x,realpathSync as S,renameSync as C,rmSync as w,rmdirSync as T,statSync as E,symlinkSync as D,truncateSync as O,unlinkSync as k,watch as A,writeFileSync as j}from"./sync.js";import{cp as M,cpSync as N}from"./cp.js";import{Dir as P,opendir as F,opendirSync as I}from"./dir.js";import{glob as L,globSync as R}from"./glob.js";import{statfs as z,statfsSync as B}from"./statfs.js";import{lchmod as V,lchmodSync as H,lchown as U,lchownSync as W,lutimes as G,lutimesSync as K,utimes as q,utimesSync as J}from"./utimes.js";import{closeSync as Y,exists as X,fchmod as Z,fchmodSync as Q,fchown as $,fchownSync as ee,fdatasync as te,fdatasyncSync as ne,fstat as re,fstatSync as ie,fsync as ae,fsyncSync as oe,ftruncate as se,ftruncateSync as ce,futimes as le,futimesSync as ue,openAsBlob as de,readSync as fe,readv as pe,readvSync as me,writeSync as he,writev as ge,writevSync as _e}from"./fd-ops.js";import{promises_exports as ve}from"./promises.js";import{access as ye,appendFile as be,chmod as xe,chown as Se,close as Ce,copyFile as we,link as Te,lstat as Ee,mkdir as De,open as Oe,read as ke,readFile as Ae,readdir as je,readlink as Me,realpath as Ne,rename as Pe,rm as Fe,rmdir as Ie,stat as Le,symlink as Re,truncate as ze,unlink as Be,write as Ve,writeFile as He}from"./callback.js";import{StatWatcher as Ue,unwatchFile as We,watchFile as Ge}from"./stat-watcher.js";const Ke={F_OK:0,R_OK:4,W_OK:2,X_OK:1,COPYFILE_EXCL:1,COPYFILE_FICLONE:2,COPYFILE_FICLONE_FORCE:4,O_RDONLY:0,O_WRONLY:1,O_RDWR:2,O_CREAT:64,O_EXCL:128,O_TRUNC:512,O_APPEND:1024,O_SYNC:1052672,O_NONBLOCK:2048,O_DIRECTORY:65536,O_NOFOLLOW:131072,S_IFMT:61440,S_IFREG:32768,S_IFDIR:16384,S_IFCHR:8192,S_IFBLK:24576,S_IFIFO:4096,S_IFLNK:40960,S_IFSOCK:49152,S_IRWXU:448,S_IRUSR:256,S_IWUSR:128,S_IXUSR:64,S_IRWXG:56,S_IRGRP:32,S_IWGRP:16,S_IXGRP:8,S_IRWXO:7,S_IROTH:4,S_IWOTH:2,S_IXOTH:1};var qe={FSWatcher:e,StatWatcher:Ue,Stats:s,BigIntStats:o,Dirent:a,Dir:P,constants:Ke,existsSync:p,readdirSync:b,readFileSync:y,writeFileSync:j,mkdirSync:g,rmdirSync:T,unlinkSync:k,mkdtempSync:_,rmSync:w,statSync:E,openSync:v,realpathSync:S,symlinkSync:D,lstatSync:h,renameSync:C,copyFileSync:f,accessSync:c,appendFileSync:l,readlinkSync:x,linkSync:m,truncateSync:O,chmodSync:u,chownSync:d,cpSync:N,opendirSync:I,globSync:R,glob:L,watch:A,watchFile:Ge,unwatchFile:We,statfsSync:B,statfs:z,utimesSync:J,utimes:q,lutimesSync:K,lutimes:G,lchownSync:W,lchown:U,lchmodSync:H,lchmod:V,fstatSync:ie,fstat:re,ftruncateSync:ce,ftruncate:se,fdatasyncSync:ne,fdatasync:te,fsyncSync:oe,fsync:ae,fchmodSync:Q,fchmod:Z,fchownSync:ee,fchown:$,futimesSync:ue,futimes:le,closeSync:Y,readSync:fe,writeSync:he,readvSync:me,readv:pe,writevSync:_e,writev:ge,exists:X,openAsBlob:de,createReadStream:n,ReadStream:t,createWriteStream:i,WriteStream:r,promises:ve,open:Oe,close:Ce,read:ke,write:Ve,rm:Fe,realpath:Ne,readdir:je,symlink:Re,lstat:Ee,stat:Le,rename:Pe,copyFile:we,cp:M,access:ye,appendFile:be,readlink:Me,truncate:ze,chmod:xe,chown:Se,mkdir:De,rmdir:Ie,readFile:Ae,writeFile:He,unlink:Be,link:Te,opendir:F};export{o as BigIntStats,P as Dir,a as Dirent,e as FSWatcher,t as ReadStream,Ue as StatWatcher,s as Stats,r as WriteStream,ye as access,c as accessSync,be as appendFile,l as appendFileSync,xe as chmod,u as chmodSync,Se as chown,d as chownSync,Ce as close,Y as closeSync,Ke as constants,we as copyFile,f as copyFileSync,M as cp,N as cpSync,n as createReadStream,i as createWriteStream,qe as default,X as exists,p as existsSync,Z as fchmod,Q as fchmodSync,$ as fchown,ee as fchownSync,te as fdatasync,ne as fdatasyncSync,re as fstat,ie as fstatSync,ae as fsync,oe as fsyncSync,se as ftruncate,ce as ftruncateSync,le as futimes,ue as futimesSync,L as glob,R as globSync,V as lchmod,H as lchmodSync,U as lchown,W as lchownSync,Te as link,m as linkSync,Ee as lstat,h as lstatSync,G as lutimes,K as lutimesSync,De as mkdir,g as mkdirSync,_ as mkdtempSync,Oe as open,de as openAsBlob,v as openSync,F as opendir,I as opendirSync,ve as promises,ke as read,Ae as readFile,y as readFileSync,fe as readSync,je as readdir,b as readdirSync,Me as readlink,x as readlinkSync,pe as readv,me as readvSync,Ne as realpath,S as realpathSync,Pe as rename,C as renameSync,Fe as rm,w as rmSync,Ie as rmdir,T as rmdirSync,Le as stat,E as statSync,z as statfs,B as statfsSync,Re as symlink,D as symlinkSync,ze as truncate,O as truncateSync,Be as unlink,k as unlinkSync,We as unwatchFile,q as utimes,J as utimesSync,A as watch,Ge as watchFile,Ve as write,He as writeFile,j as writeFileSync,he as writeSync,ge as writev,_e as writevSync};
1
+ import"./_virtual/_rolldown/runtime.js";import{FSWatcher as e}from"./fs-watcher.js";import{lchmod as t,lchmodSync as ee,lchown as n,lchownSync as r,lutimes as i,lutimesSync as a,utimes as o,utimesSync as s}from"./utimes.js";import{closeSync as c,exists as l,fchmod as u,fchmodSync as d,fchown as f,fchownSync as p,fdatasync as m,fdatasyncSync as h,fstat as g,fstatSync as _,fsync as v,fsyncSync as y,ftruncate as b,ftruncateSync as x,futimes as S,futimesSync as C,openAsBlob as w,readSync as T,readv as E,readvSync as D,writeSync as O,writev as k,writevSync as A}from"./fd-ops.js";import{ReadStream as j,createReadStream as M}from"./read-stream.js";import{openFlagValues as N}from"./posix-flags.js";import{WriteStream as P,createWriteStream as F}from"./write-stream.js";import{Dirent as I}from"./dirent.js";import{BigIntStats as L,Stats as R}from"./stats.js";import{accessSync as z,appendFileSync as B,chmodSync as V,chownSync as H,copyFileSync as U,existsSync as W,linkSync as G,lstatSync as K,mkdirSync as q,mkdtempSync as J,openSync as Y,readFileSync as X,readdirSync as Z,readlinkSync as Q,realpathSync as $,renameSync as te,rmSync as ne,rmdirSync as re,statSync as ie,symlinkSync as ae,truncateSync as oe,unlinkSync as se,watch as ce,writeFileSync as le}from"./sync.js";import{cp as ue,cpSync as de}from"./cp.js";import{Dir as fe,opendir as pe,opendirSync as me}from"./dir.js";import{glob as he,globSync as ge}from"./glob.js";import{statfs as _e,statfsSync as ve}from"./statfs.js";import{promises_exports as ye}from"./promises.js";import{access as be,appendFile as xe,chmod as Se,chown as Ce,close as we,copyFile as Te,link as Ee,lstat as De,mkdir as Oe,open as ke,read as Ae,readFile as je,readdir as Me,readlink as Ne,realpath as Pe,rename as Fe,rm as Ie,rmdir as Le,stat as Re,symlink as ze,truncate as Be,unlink as Ve,write as He,writeFile as Ue}from"./callback.js";import{StatWatcher as We,unwatchFile as Ge,watchFile as Ke}from"./stat-watcher.js";function openFlagDescriptors(){let e={};for(let t of Object.keys(N()))e[t]={enumerable:!0,configurable:!0,get:()=>N()[t]};return e}const qe=Object.defineProperties({F_OK:0,R_OK:4,W_OK:2,X_OK:1,COPYFILE_EXCL:1,COPYFILE_FICLONE:2,COPYFILE_FICLONE_FORCE:4,S_IFMT:61440,S_IFREG:32768,S_IFDIR:16384,S_IFCHR:8192,S_IFBLK:24576,S_IFIFO:4096,S_IFLNK:40960,S_IFSOCK:49152,S_IRWXU:448,S_IRUSR:256,S_IWUSR:128,S_IXUSR:64,S_IRWXG:56,S_IRGRP:32,S_IWGRP:16,S_IXGRP:8,S_IRWXO:7,S_IROTH:4,S_IWOTH:2,S_IXOTH:1},openFlagDescriptors());var Je={FSWatcher:e,StatWatcher:We,Stats:R,BigIntStats:L,Dirent:I,Dir:fe,constants:qe,existsSync:W,readdirSync:Z,readFileSync:X,writeFileSync:le,mkdirSync:q,rmdirSync:re,unlinkSync:se,mkdtempSync:J,rmSync:ne,statSync:ie,openSync:Y,realpathSync:$,symlinkSync:ae,lstatSync:K,renameSync:te,copyFileSync:U,accessSync:z,appendFileSync:B,readlinkSync:Q,linkSync:G,truncateSync:oe,chmodSync:V,chownSync:H,cpSync:de,opendirSync:me,globSync:ge,glob:he,watch:ce,watchFile:Ke,unwatchFile:Ge,statfsSync:ve,statfs:_e,utimesSync:s,utimes:o,lutimesSync:a,lutimes:i,lchownSync:r,lchown:n,lchmodSync:void 0,lchmod:void 0,fstatSync:_,fstat:g,ftruncateSync:x,ftruncate:b,fdatasyncSync:h,fdatasync:m,fsyncSync:y,fsync:v,fchmodSync:d,fchmod:u,fchownSync:p,fchown:f,futimesSync:C,futimes:S,closeSync:c,readSync:T,writeSync:O,readvSync:D,readv:E,writevSync:A,writev:k,exists:l,openAsBlob:w,createReadStream:M,ReadStream:j,createWriteStream:F,WriteStream:P,promises:ye,open:ke,close:we,read:Ae,write:He,rm:Ie,realpath:Pe,readdir:Me,symlink:ze,lstat:De,stat:Re,rename:Fe,copyFile:Te,cp:ue,access:be,appendFile:xe,readlink:Ne,truncate:Be,chmod:Se,chown:Ce,mkdir:Oe,rmdir:Le,readFile:je,writeFile:Ue,unlink:Ve,link:Ee,opendir:pe};export{L as BigIntStats,fe as Dir,I as Dirent,e as FSWatcher,j as ReadStream,We as StatWatcher,R as Stats,P as WriteStream,be as access,z as accessSync,xe as appendFile,B as appendFileSync,Se as chmod,V as chmodSync,Ce as chown,H as chownSync,we as close,c as closeSync,qe as constants,Te as copyFile,U as copyFileSync,ue as cp,de as cpSync,M as createReadStream,F as createWriteStream,Je as default,l as exists,W as existsSync,u as fchmod,d as fchmodSync,f as fchown,p as fchownSync,m as fdatasync,h as fdatasyncSync,g as fstat,_ as fstatSync,v as fsync,y as fsyncSync,b as ftruncate,x as ftruncateSync,S as futimes,C as futimesSync,he as glob,ge as globSync,t as lchmod,ee as lchmodSync,n as lchown,r as lchownSync,Ee as link,G as linkSync,De as lstat,K as lstatSync,i as lutimes,a as lutimesSync,Oe as mkdir,q as mkdirSync,J as mkdtempSync,ke as open,w as openAsBlob,Y as openSync,pe as opendir,me as opendirSync,ye as promises,Ae as read,je as readFile,X as readFileSync,T as readSync,Me as readdir,Z as readdirSync,Ne as readlink,Q as readlinkSync,E as readv,D as readvSync,Pe as realpath,$ as realpathSync,Fe as rename,te as renameSync,Ie as rm,ne as rmSync,Le as rmdir,re as rmdirSync,Re as stat,ie as statSync,_e as statfs,ve as statfsSync,ze as symlink,ae as symlinkSync,Be as truncate,oe as truncateSync,Ve as unlink,se as unlinkSync,Ge as unwatchFile,o as utimes,s as utimesSync,ce as watch,Ke as watchFile,He as write,Ue as writeFile,le as writeFileSync,O as writeSync,k as writev,A as writevSync};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{isDarwin as e,isWin32 as t}from"@gjsify/utils/core";const n={O_RDONLY:0,O_WRONLY:1,O_RDWR:2,O_CREAT:64,O_EXCL:128,O_NOCTTY:256,O_TRUNC:512,O_APPEND:1024,O_NONBLOCK:2048,O_DSYNC:4096,O_SYNC:1052672,O_DIRECTORY:65536,O_NOFOLLOW:131072},r={O_RDONLY:0,O_WRONLY:1,O_RDWR:2,O_CREAT:512,O_EXCL:2048,O_NOCTTY:131072,O_TRUNC:1024,O_APPEND:8,O_NONBLOCK:4,O_DSYNC:4194304,O_SYNC:128,O_DIRECTORY:1048576,O_NOFOLLOW:256},i={O_RDONLY:0,O_WRONLY:1,O_RDWR:2,O_CREAT:256,O_EXCL:1024,O_NOCTTY:0,O_TRUNC:512,O_APPEND:8,O_NONBLOCK:0,O_DSYNC:0,O_SYNC:0,O_DIRECTORY:0,O_NOFOLLOW:0};function openFlagValues(){return t()?i:e()?r:n}function stringFlagBits(e,t){switch(e){case`r`:return t.O_RDONLY;case`rs`:case`sr`:return t.O_RDONLY|t.O_SYNC;case`r+`:return t.O_RDWR;case`rs+`:case`sr+`:return t.O_RDWR|t.O_SYNC;case`w`:return t.O_TRUNC|t.O_CREAT|t.O_WRONLY;case`wx`:case`xw`:return t.O_TRUNC|t.O_CREAT|t.O_WRONLY|t.O_EXCL;case`w+`:return t.O_TRUNC|t.O_CREAT|t.O_RDWR;case`wx+`:case`xw+`:return t.O_TRUNC|t.O_CREAT|t.O_RDWR|t.O_EXCL;case`a`:return t.O_APPEND|t.O_CREAT|t.O_WRONLY;case`ax`:case`xa`:return t.O_APPEND|t.O_CREAT|t.O_WRONLY|t.O_EXCL;case`as`:case`sa`:return t.O_APPEND|t.O_CREAT|t.O_WRONLY|t.O_SYNC;case`a+`:return t.O_APPEND|t.O_CREAT|t.O_RDWR;case`ax+`:case`xa+`:return t.O_APPEND|t.O_CREAT|t.O_RDWR|t.O_EXCL;case`as+`:case`sa+`:return t.O_APPEND|t.O_CREAT|t.O_RDWR|t.O_SYNC;default:return}}function parseOpenFlags(e){let t=openFlagValues(),n;if(e==null)n=t.O_RDONLY;else if(typeof e==`number`)n=e;else{let r=stringFlagBits(e,t);if(r===void 0){let t=TypeError(`Unknown file open flag: ${e}`);throw t.code=`ERR_INVALID_ARG_VALUE`,t}n=r}let r=n&(t.O_RDONLY|t.O_WRONLY|t.O_RDWR);return{posix:n,readable:r===t.O_RDONLY||r===t.O_RDWR,writable:r===t.O_WRONLY||r===t.O_RDWR,append:(n&t.O_APPEND)!==0,creat:(n&t.O_CREAT)!==0,excl:(n&t.O_CREAT)!==0&&(n&t.O_EXCL)!==0,trunc:(n&t.O_TRUNC)!==0,nofollow:t.O_NOFOLLOW!==0&&(n&t.O_NOFOLLOW)!==0,directory:t.O_DIRECTORY!==0&&(n&t.O_DIRECTORY)!==0}}function normalizeMode(e,t){let n=e??t,r=n;if(typeof n==`string`){if(!/^[0-7]+$/.test(n))throw invalidMode(n);r=parseInt(n,8)}if(typeof r!=`number`)throw modeNotANumber(r);if(!Number.isInteger(r))throw modeOutOfRange(`an integer`,r);if(r<0||r>4294967295)throw modeOutOfRange(`>= 0 && <= 4294967295`,r);return r}function invalidMode(e){let t=TypeError(`The argument 'mode' must be a 32-bit unsigned integer or an octal string. Received '${e}'`);return t.code=`ERR_INVALID_ARG_VALUE`,t}function modeNotANumber(e){let t=e==null?String(e):`type ${typeof e} (${describeValue(e)})`,n=TypeError(`The "mode" argument must be of type number. Received ${t}`);return n.code=`ERR_INVALID_ARG_TYPE`,n}function describeValue(e){try{return typeof e==`object`?Object.prototype.toString.call(e):String(e)}catch{return`<unprintable>`}}function modeOutOfRange(e,t){let n=RangeError(`The value of "mode" is out of range. It must be ${e}. Received ${t}`);return n.code=`ERR_OUT_OF_RANGE`,n}export{normalizeMode,openFlagValues,parseOpenFlags};
@@ -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{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}from"./errors.js";import{accessSync as f,appendFileSync as p,chmodSync as m,chownSync as h,copyFileSync as g,linkSync as _,readdirSync as v,readlinkSync as y,realpathSync as b,renameSync as x,truncateSync as S}from"./sync.js";import{cpAsync as C}from"./cp.js";import{opendirAsync as w}from"./dir.js";import{globAsync as T}from"./glob.js";import{statfsAsync as E}from"./statfs.js";import{lchmodAsync as D,lchownAsync as O,lutimesAsync as k,utimesAsync as A}from"./utimes.js";import{fchmodAsync as j,fchownAsync as M,fdatasyncAsync as N,fstatAsync as P,fsyncAsync as F,ftruncateAsync as I,futimesAsync as L,openAsBlob as R,readvAsync as z,writevAsync as B}from"./fd-ops.js";import V from"@girs/glib-2.0";import H from"@girs/gio-2.0";import{dirname as U,join as W}from"node:path";var G=e({access:()=>access,appendFile:()=>appendFile,chmod:()=>chmod,chown:()=>chown,copyFile:()=>copyFile,cp:()=>C,default:()=>K,fchmod:()=>j,fchown:()=>M,fdatasync:()=>N,fstat:()=>P,fsync:()=>F,ftruncate:()=>I,futimes:()=>L,glob:()=>T,lchmod:()=>D,lchown:()=>O,link:()=>link,lstat:()=>lstat,lutimes:()=>k,mkdir:()=>mkdir,mkdtemp:()=>mkdtemp,open:()=>open,openAsBlob:()=>R,opendir:()=>w,readFile:()=>readFile,readdir:()=>readdir,readlink:()=>readlink,readv:()=>z,realpath:()=>realpath,rename:()=>rename,rm:()=>rm,rmdir:()=>rmdir,stat:()=>stat,statfs:()=>E,symlink:()=>symlink,truncate:()=>truncate,unlink:()=>unlink,utimes:()=>A,watch:()=>o,write:()=>write,writeFile:()=>writeFile,writev:()=>B});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=H.File.new_for_path(r);return new Promise((e,t)=>{a.make_directory_async(V.PRIORITY_DEFAULT,null,(n,i)=>{try{a.make_directory_finish(i),e(void 0)}catch(e){t(d(e,`mkdir`,r))}})})}async function mkdirRecursiveAsync(e){let t=H.File.new_for_path(e);try{return await new Promise((e,n)=>{t.make_directory_async(V.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===H.IOErrorEnum.EXISTS)return;if(n.code===H.IOErrorEnum.NOT_FOUND){let n=U(e);if(n===e)throw d(t,`mkdir`,e);let r=await mkdirRecursiveAsync(n),i=H.File.new_for_path(e);return await new Promise((t,n)=>{i.make_directory_async(V.PRIORITY_DEFAULT,null,(r,a)=>{try{i.make_directory_finish(a),t()}catch(t){n(d(t,`mkdir`,e))}})}),r??e}throw d(t,`mkdir`,e)}}async function readFile(e,t={encoding:null,flag:`r`}){let a=i(e),o=H.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 d(e,`open`,a)}if(!s)throw d(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=H.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,H.FileCreateFlags.REPLACE_DESTINATION,V.PRIORITY_DEFAULT,null,(i,a)=>{try{e(r.replace_finish(a))}catch(e){t(d(e,`open`,n))}})});if(a.length>0){let e=new V.Bytes(a);await new Promise((t,r)=>{o.write_bytes_async(e,V.PRIORITY_DEFAULT,null,(e,i)=>{try{o.write_bytes_finish(i),t()}catch(e){r(d(e,`write`,n))}})})}await new Promise((e,t)=>{o.close_async(V.PRIORITY_DEFAULT,null,(r,i)=>{try{o.close_finish(i),e()}catch(e){t(d(e,`close`,n))}})})}async function rmdir(e,t){let n=i(e),r=H.File.new_for_path(n);if((await new Promise((e,t)=>{r.query_info_async(`standard::type`,H.FileQueryInfoFlags.NONE,V.PRIORITY_DEFAULT,null,(i,a)=>{try{e(r.query_info_finish(a))}catch(e){t(d(e,`rmdir`,n))}})})).get_file_type()!==H.FileType.DIRECTORY)throw d(Object.assign(Error(),{code:4}),`rmdir`,n);if((await new Promise((e,t)=>{r.enumerate_children_async(`standard::name`,H.FileQueryInfoFlags.NONE,V.PRIORITY_DEFAULT,null,(i,a)=>{try{e(r.enumerate_children_finish(a))}catch(e){t(d(e,`rmdir`,n))}})})).next_file(null)!==null)throw d(Object.assign(Error(),{code:5}),`rmdir`,n);await new Promise((e,t)=>{r.delete_async(V.PRIORITY_DEFAULT,null,(i,a)=>{try{r.delete_finish(a),e()}catch(e){t(d(e,`rmdir`,n))}})})}async function unlink(e){let t=i(e),n=H.File.new_for_path(t);await new Promise((e,r)=>{n.delete_async(V.PRIORITY_DEFAULT,null,(i,a)=>{try{n.delete_finish(a),e()}catch(e){r(d(e,`unlink`,t))}})})}async function open(e,t,n){return new u({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 u.getInstance(e).write(t,n,r,i)).bytesWritten,buffer:t}}async function _writeStr(e,t,n,r){return{bytesWritten:(await u.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=H.File.new_for_path(a);o.query_info_async(c,t,V.PRIORITY_DEFAULT,null,(t,c)=>{try{let t=o.query_info_finish(c);e(r?.bigint?new s(t,a):new l(t,a))}catch(e){i(d(e,n,a))}})})}async function stat(e,t){return queryInfoAsync(e,H.FileQueryInfoFlags.NONE,`stat`,t)}async function lstat(e,t){return queryInfoAsync(e,H.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,t)}async function readdir(e,t){try{return v(e,t)}catch(t){throw d(t,`scandir`,e)}}async function realpath(e){return b(e)}async function symlink(e,t,n){let r=i(t),a=i(e);return new Promise((e,t)=>{let n=H.File.new_for_path(r);n.make_symbolic_link_async(a,V.PRIORITY_DEFAULT,null,(i,o)=>{try{n.make_symbolic_link_finish(o),e()}catch(e){t(d(e,`symlink`,a,r))}})})}async function rm(e,t){let n=i(e),r=H.File.new_for_path(n),a=t?.recursive||!1,o=t?.force||!1,s;try{s=r.query_file_type(H.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){if(o)return;throw d(t,`rm`,e)}if(s===H.FileType.SYMBOLIC_LINK){await new Promise((t,n)=>{r.delete_async(V.PRIORITY_DEFAULT,null,(i,a)=>{try{r.delete_finish(a),t()}catch(r){if(o){t();return}n(d(r,`rm`,e))}})});return}if(s===H.FileType.DIRECTORY){let r=await readdir(e,{withFileTypes:!0});if(!a&&r.length)throw d(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)typeof e!=`string`&&await rm(W(n,e.name),t)}await new Promise((t,n)=>{r.delete_async(V.PRIORITY_DEFAULT,null,(i,a)=>{try{r.delete_finish(a),t()}catch(r){if(o){t();return}n(d(r,`rm`,e))}})})}async function rename(e,t){x(e,t)}async function copyFile(e,t,n){g(e,t,n)}async function access(e,t){f(e,t)}async function appendFile(e,t,n){p(e,t,n)}async function readlink(e,t){return y(e,t)}async function truncate(e,t){S(e,t)}async function chmod(e,t){m(e,t)}async function chown(e,t,n){h(e,t,n)}async function link(e,t){_(e,t)}var K={readFile,mkdir,mkdtemp,realpath,readdir,writeFile,rmdir,unlink,open,write,rm,lstat,symlink,stat,rename,copyFile,access,appendFile,readlink,truncate,chmod,chown,link,cp:C,opendir:w,glob:T,watch:o,statfs:E,utimes:A,lutimes:k,lchown:O,lchmod:D,fstat:P,ftruncate:I,fdatasync:N,fsync:F,fchmod:j,fchown:M,futimes:L,readv:z,writev:B,openAsBlob:R};export{access,appendFile,chmod,chown,copyFile,C as cp,K as default,j as fchmod,M as fchown,N as fdatasync,P as fstat,F as fsync,I as ftruncate,L as futimes,T as glob,D as lchmod,O as lchown,link,lstat,k as lutimes,mkdir,mkdtemp,open,R as openAsBlob,w as opendir,G as promises_exports,readFile,readdir,readlink,z as readv,realpath,rename,rm,rmdir,stat,E as statfs,symlink,truncate,unlink,A as utimes,o as watch,write,writeFile,B 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}from"./utils.js";import{watchAsync as a}from"./fs-watcher.js";import{lchmodAsync as o,lchownAsync as s,lutimesAsync as c,utimesAsync as l}from"./utimes.js";import{fchmodAsync as u,fchownAsync as d,fdatasyncAsync as f,fstatAsync as p,fsyncAsync as m,ftruncateAsync as h,futimesAsync as g,openAsBlob as _,readvAsync as v,writevAsync as y}from"./fd-ops.js";import{createNodeError as b}from"./errors.js";import{STAT_ATTRIBUTES as x,statsFrom as S}from"./stats.js";import{FileHandle as C}from"./file-handle.js";import{accessSync as w,appendFileSync as T,chmodSync as E,chownSync as D,copyFileSync as O,linkSync as k,mkdirSync as A,mkdtempAt as j,readdirSync as M,readlinkSync as N,realpathSync as P,renameSync as F,truncateSync as I,writeFileSync as L}from"./sync.js";import{cpAsync as R}from"./cp.js";import{opendirAsync as z}from"./dir.js";import{globAsync as B}from"./glob.js";import{statfsAsync as V}from"./statfs.js";import H from"@girs/glib-2.0";import U from"@girs/gio-2.0";import{join as W}from"node:path";var G=e({access:()=>access,appendFile:()=>appendFile,chmod:()=>chmod,chown:()=>chown,copyFile:()=>copyFile,cp:()=>R,default:()=>K,fchmod:()=>u,fchown:()=>d,fdatasync:()=>f,fstat:()=>p,fsync:()=>m,ftruncate:()=>h,futimes:()=>g,glob:()=>B,lchmod:()=>o,lchown:()=>s,link:()=>link,lstat:()=>lstat,lutimes:()=>c,mkdir:()=>mkdir,mkdtemp:()=>mkdtemp,open:()=>open,openAsBlob:()=>_,opendir:()=>z,readFile:()=>readFile,readdir:()=>readdir,readlink:()=>readlink,readv:()=>v,realpath:()=>realpath,rename:()=>rename,rm:()=>rm,rmdir:()=>rmdir,stat:()=>stat,statfs:()=>V,symlink:()=>symlink,truncate:()=>truncate,unlink:()=>unlink,utimes:()=>l,watch:()=>a,write:()=>write,writeFile:()=>writeFile,writev:()=>y});async function mkdir(e,t){return A(i(e),t)}async function readFile(e,t={encoding:null,flag:`r`}){if(e instanceof C||typeof e==`number`){let i=C.getInstance(e,`read`);return n(r(t,`buffer`),i._readToEndSync())}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 b(e,`open`,a)}if(!s)throw b(Error(`failed to read file`),`open`,a);return n(r(t,`buffer`),c)}async function mkdtemp(e,n){let i=r(n);return t(j(e),i)}async function writeFile(e,t,n){L(e,typeof t==`string`||t instanceof Uint8Array?t:String(t),n??null)}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(b(e,`rmdir`,n))}})})).get_file_type()!==U.FileType.DIRECTORY)throw b(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(b(e,`rmdir`,n))}})})).next_file(null)!==null)throw b(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(b(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(b(e,`unlink`,t))}})})}async function open(e,t,n){return new C({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 C.getInstance(e,`write`).write(t,n,r,i)).bytesWritten,buffer:t}}async function _writeStr(e,t,n,r){return{bytesWritten:(await C.getInstance(e,`write`).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(x,t,H.PRIORITY_DEFAULT,null,(t,s)=>{try{e(S(o.query_info_finish(s),a,n,r?.bigint))}catch(e){i(b(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 M(e,t)}catch(t){throw b(t,`scandir`,e)}}async function realpath(e){return P(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(b(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,s;try{s=r.query_file_type(U.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){if(o)return;throw b(t,`rm`,e)}if(s===U.FileType.SYMBOLIC_LINK){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(b(r,`rm`,e))}})});return}if(s===U.FileType.DIRECTORY){let r=await readdir(e,{withFileTypes:!0});if(!a&&r.length)throw b(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)typeof e!=`string`&&await rm(W(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(b(r,`rm`,e))}})})}async function rename(e,t){F(e,t)}async function copyFile(e,t,n){O(e,t,n)}async function access(e,t){w(e,t)}async function appendFile(e,t,n){T(e,t,n)}async function readlink(e,t){return N(e,t)}async function truncate(e,t){I(e,t)}async function chmod(e,t){E(e,t)}async function chown(e,t,n){D(e,t,n)}async function link(e,t){k(e,t)}var K={readFile,mkdir,mkdtemp,realpath,readdir,writeFile,rmdir,unlink,open,write,rm,lstat,symlink,stat,rename,copyFile,access,appendFile,readlink,truncate,chmod,chown,link,cp:R,opendir:z,glob:B,watch:a,statfs:V,utimes:l,lutimes:c,lchown:s,lchmod:o,fstat:p,ftruncate:h,fdatasync:f,fsync:m,fchmod:u,fchown:d,futimes:g,readv:v,writev:y,openAsBlob:_};export{access,appendFile,chmod,chown,copyFile,R as cp,K as default,u as fchmod,d as fchown,f as fdatasync,p as fstat,m as fsync,h as ftruncate,g as futimes,B as glob,o as lchmod,s as lchown,link,lstat,c as lutimes,mkdir,mkdtemp,open,_ as openAsBlob,z as opendir,G as promises_exports,readFile,readdir,readlink,v as readv,realpath,rename,rm,rmdir,stat,V as statfs,symlink,truncate,unlink,l as utimes,a as watch,write,writeFile,y as writev};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";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
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{closeSync as t}from"./fd-ops.js";import{FileHandle as n}from"./file-handle.js";import r from"@girs/glib-2.0";import i from"@girs/gio-2.0";import{Buffer as a}from"node:buffer";import{Readable as o}from"node:stream";var ReadStream=class extends o{bytesRead=0;path;pending=!0;fd=null;_ownFd=null;_autoCloseFd=!0;_positional=!1;_gioFile;_inputStream=null;_cancellable=new i.Cancellable;_start;_end;_pos;_reading=!1;_readAgain=!1;_lastSize=64*1024;close(e){this._cancellable.cancel(),this._release(),this.destroy(),e&&e(null)}constructor(t,n){let r=e(t);super({highWaterMark:n?.highWaterMark??64*1024,encoding:n?.encoding,objectMode:!1}),this.path=r,this._gioFile=i.File.new_for_path(r),this._start=n?.start??0,this._end=n?.end??1/0,this._pos=this._start,this._positional=n?.start!==void 0,typeof n?.fd==`number`&&(this._ownFd=n.fd,this.fd=n.fd,this._autoCloseFd=n.autoClose!==!1),this.once(`end`,()=>this._release())}_construct(e){if(this._ownFd!==null){this.pending=!1,e(),this.emit(`open`,this._ownFd),this.emit(`ready`);return}this._gioFile.read_async(r.PRIORITY_DEFAULT,this._cancellable,(t,n)=>{if(this.destroyed){e();return}try{this._inputStream=this._gioFile.read_finish(n),this.pending=!1,this.emit(`open`,0),this.emit(`ready`),this._start>0&&this._inputStream.can_seek()&&this._inputStream.seek(this._start,r.SeekType.SET,null),e()}catch(t){this._cancellable.is_cancelled()||e(t)}})}_read(e){if(this._lastSize=e,this._reading){this._readAgain=!0;return}this._doRead(e)}_doRead(e){if(this._ownFd!==null){if(this._reading||this.destroyed)return;this._reading=!0,r.timeout_add(r.PRIORITY_DEFAULT,0,()=>(this._reading=!1,this.destroyed||this._readThroughFd(e),r.SOURCE_REMOVE));return}let t=e;if(this._end!==1/0){let n=this._end-this._pos+1;if(n<=0){this.push(null);return}t=Math.min(e,n)}let n=this._inputStream;!n||this.destroyed||(this._reading=!0,n.read_bytes_async(t,r.PRIORITY_DEFAULT,this._cancellable,(e,t)=>{this._reading=!1;try{let e=n.read_bytes_finish(t).get_data();if(!e||e.length===0){this._readAgain=!1,this.push(null);return}this.bytesRead+=e.length,this._pos+=e.length,this.push(a.from(e)),this._readAgain&&!this._reading&&(this._readAgain=!1,this._doRead(this._lastSize))}catch(e){this._readAgain=!1,this._cancellable.is_cancelled()||this.destroy(e)}}))}_readThroughFd(e){try{let t=e;if(this._end!==1/0){let n=this._end-this._pos+1;if(n<=0){this._readAgain=!1,this.push(null);return}t=Math.min(e,n)}let r=n.getInstance(this._ownFd,`read`),i=a.alloc(t),o=r._readSync(i,0,t,this._positional?this._pos:null);if(o===0){this._readAgain=!1,this.push(null);return}this.bytesRead+=o,this._pos+=o,this.push(i.subarray(0,o))}catch(e){this._readAgain=!1,this.destroy(e)}}_release(){this._inputStream&&=(this._inputStream.close_async(r.PRIORITY_DEFAULT,null,()=>{}),null),this._releaseFd()}_releaseFd(){if(this._ownFd===null||!this._autoCloseFd)return;let e=this._ownFd;this._ownFd=null,this.fd=null;try{t(e)}catch{}}_destroy(e,t){this._cancellable.cancel(),this._release(),t(e)}};function createReadStream(e,t){return new ReadStream(e,t)}export{ReadStream,createReadStream};
package/lib/esm/stats.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";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};
1
+ import"./_virtual/_rolldown/runtime.js";import{Dirent as e}from"./dirent.js";import{answered as t,fsError as n}from"./fd-io.js";import r from"@girs/gio-2.0";import{basename as i}from"node:path";const a=`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,t,n){let o,s;e instanceof r.FileInfo?(o=e,s=t.toString(),n||=i(s)):(s=e.toString(),typeof t==`string`&&(n=t),n||=i(s),o=r.File.new_for_path(s).query_info(a,r.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)),super(s,n,o.get_file_type(),o),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,t,n){let o,s;e instanceof r.FileInfo?(o=e,s=t.toString(),n||=i(s)):(s=e.toString(),typeof t==`string`&&(n=t),n||=i(s),o=r.File.new_for_path(s).query_info(a,r.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)),super(s,n,o.get_file_type(),o),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}};function statsFrom(e,r,i,a){if(!t(e))throw n(`EACCES`,i,r);return a?new BigIntStats(e,r):new Stats(e,r)}export{BigIntStats,a as STAT_ATTRIBUTES,Stats,statsFrom};
package/lib/esm/sync.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";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{isStdFd as p,readStdFdAll as m}from"./std-fd.js";import h from"@girs/glib-2.0";import g from"@girs/gio-2.0";import{join as _}from"node:path";import{Buffer as v}from"node:buffer";import{existsSync as y}from"@gjsify/utils";function statSync(e,t){let n=r(e);try{let e=g.File.new_for_path(n).query_info(c,g.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=g.File.new_for_path(n).query_info(c,g.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=g.File.new_for_path(n).enumerate_children(`standard::name,standard::type`,g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null),a=[];try{let e=i.next_file(null);for(;e!==null;)a.push({name:e.get_name(),type:e.get_file_type()}),e=i.next_file(null)}finally{try{i.close(null)}catch{}}let s=[];for(let e of a){let r=_(n,e.name);if(t?.withFileTypes?s.push(new o(r,e.name,e.type)):s.push(e.name),t?.recursive&&e.type===g.FileType.DIRECTORY){let n=readdirSync(r,t);for(let t of n)typeof t==`string`?s.push(_(e.name,t)):s.push(t)}}return s}function realpathSync(e){let t=r(e);return resolveEveryComponent(g.File.new_for_path(t),{left:40},t)}function resolveEveryComponent(e,t,n){let r=e.get_parent();return expandSymlinks(r===null?e:g.File.new_for_path(resolveEveryComponent(r,t,n)).get_child(e.get_basename()),t,n)}function expandSymlinks(e,t,n){let r=e;for(;;){let e=r.query_info(`standard::is-symlink,standard::symlink-target`,g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);if(!e.get_is_symlink())return r.get_path();if(--t.left<0)throw Error(`ELOOP: too many levels of symbolic links, realpath '${n}'`);let i=e.get_symlink_target(),a=r.get_parent(),o=h.path_is_absolute(i)?g.File.new_for_path(i):(a??r).resolve_relative_path(i);r=g.File.new_for_path(resolveEveryComponent(o,t,n))}}realpathSync.native=realpathSync;function symlinkSync(e,t,n){let i=r(t),a=r(e);g.File.new_for_path(i).make_symbolic_link(a,null)}function readFileSync(e,i={encoding:null,flag:`r`}){if(typeof e==`number`&&p(e))return t(n(i,`buffer`),m(e));let a=r(typeof e==`number`?u.getInstance(e).options.path:e),o=g.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);let a=g.File.new_for_path(e);try{a.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}}function mkdirSyncRecursive(e){let t=g.File.new_for_path(e);try{return t.make_directory(null),e}catch(t){let n=t;if(n.code===g.IOErrorEnum.EXISTS)return;if(n.code===g.IOErrorEnum.NOT_FOUND){let n=_(e,`..`),r=g.File.new_for_path(n).get_path();if(r===e)throw d(t,`mkdir`,e);let i=mkdirSyncRecursive(r),a=g.File.new_for_path(e);try{a.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}return i??e}throw d(t,`mkdir`,e)}}function rmdirSync(e,t){let n=r(e),i=g.File.new_for_path(n);try{if(i.query_info(`standard::type`,g.FileQueryInfoFlags.NONE,null).get_file_type()!==g.FileType.DIRECTORY)throw d(Object.assign(Error(),{code:4}),`rmdir`,n);if(i.enumerate_children(`standard::name`,g.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=g.File.new_for_path(t);try{n.delete(null)}catch(e){throw d(e,`unlink`,t)}}function writeFileSync(e,t){h.file_set_contents(r(e),t)}function renameSync(e,t){let n=r(e),i=r(t),a=g.File.new_for_path(n),o=g.File.new_for_path(i);try{a.move(o,g.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=g.File.new_for_path(i),s=g.File.new_for_path(a),c=g.FileCopyFlags.NONE;n&&!(n&1)?c=g.FileCopyFlags.OVERWRITE:n||(c=g.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=g.File.new_for_path(n);try{let e=i.query_info(`access::*`,g.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=g.File.new_for_path(i),o;o=typeof t==`string`?new TextEncoder().encode(t):t;try{let e=a.append_to(g.FileCreateFlags.NONE,null);o.length>0&&e.write_bytes(new h.Bytes(o),null),e.close(null)}catch(e){throw d(e,`appendfile`,i)}}function readlinkSync(e,t){let n=r(e),i=g.File.new_for_path(n);try{let e=i.query_info(`standard::symlink-target`,g.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`?v.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(g.File.new_for_path(n).query_file_type(g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)===g.FileType.UNKNOWN)throw Object.assign(Error(`ENOENT: no such file or directory, link '${n}' -> '${i}'`),{code:`ENOENT`,errno:-2,syscall:`link`,path:n,dest:i});if(g.File.new_for_path(i).query_file_type(g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)!==g.FileType.UNKNOWN)throw Object.assign(Error(`EEXIST: file already exists, link '${n}' -> '${i}'`),{code:`EEXIST`,errno:-17,syscall:`link`,path:n,dest:i});let a=``;try{let[,,e,t]=h.spawn_sync(null,[`ln`,`--`,n,i],null,h.SpawnFlags.SEARCH_PATH,null);if(a=e?new TextDecoder().decode(e).trim():``,!h.spawn_check_wait_status(t))throw Error(`ln exited non-zero (${t})`);return}catch(e){throw a===``&&e instanceof Error&&(a=e.message),Object.assign(Error(`EPERM: operation not permitted, link '${n}' -> '${i}'`+(a?` (${a})`:``)),{code:`EPERM`,errno:-1,syscall:`link`,path:n,dest:i})}}function truncateSync(e,t){let n=r(e),i=g.File.new_for_path(n);try{let e=i.replace(null,!1,g.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 h.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;try{g.File.new_for_path(n).set_attribute_uint32(`unix::mode`,i,g.FileQueryInfoFlags.NONE,null)}catch(e){throw d(e,`chmod`,n)}}function chownSync(e,t,n){let i=r(e);try{let e=g.File.new_for_path(i),r=new g.FileInfo;t!==-1&&r.set_attribute_uint32(`unix::uid`,t),n!==-1&&r.set_attribute_uint32(`unix::gid`,n),e.set_attributes_from_info(r,g.FileQueryInfoFlags.NONE,null)}catch(e){throw d(e,`chown`,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=g.File.new_for_path(n),a=t?.recursive||!1,o=t?.force||!1,s;try{s=i.query_file_type(g.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){if(o&&f(t))return;throw d(t,`rm`,e)}if(s===g.FileType.SYMBOLIC_LINK){try{i.delete(null)}catch(t){if(o&&f(t))return;throw d(t,`rm`,e)}return}if(s===g.FileType.DIRECTORY){let r=readdirSync(e);if(!a&&r.length)throw d(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)rmSync(_(n,e),t)}try{i.delete(null)}catch(t){if(o&&f(t))return;throw d(t,`rm`,e)}}export{accessSync,appendFileSync,chmodSync,chownSync,copyFileSync,y as existsSync,linkSync,lstatSync,mkdirSync,mkdtempSync,openSync,readFileSync,readdirSync,readlinkSync,realpathSync,renameSync,rmSync,rmdirSync,statSync,symlinkSync,truncateSync,unlinkSync,watch,writeFileSync};
1
+ import"./_virtual/_rolldown/runtime.js";import{decode as e,encodeUint8Array as t,getEncodingFromOptions as n}from"./encoding.js";import{normalizePath as r,randomName as i}from"./utils.js";import{FSWatcher as a}from"./fs-watcher.js";import{isStdFd as o,readStdFdAll as s,writeStdFdSync as c}from"./std-fd.js";import{normalizeMode as l}from"./posix-flags.js";import{Dirent as u}from"./dirent.js";import{createNodeError as d,isNotFoundError as f}from"./errors.js";import{classifyMkdirFailure as p,fsError as m}from"./fd-io.js";import{STAT_ATTRIBUTES as h,statsFrom as g}from"./stats.js";import{FileHandle as _}from"./file-handle.js";import v from"@girs/glib-2.0";import y from"@girs/gio-2.0";import{join as b}from"node:path";import{Buffer as x}from"node:buffer";import{existsSync as S}from"@gjsify/utils";function statSync(e,t){let n=r(e);try{return g(y.File.new_for_path(n).query_info(h,y.FileQueryInfoFlags.NONE,null),n,`stat`,t?.bigint)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`stat`,n)}}function lstatSync(e,t){let n=r(e);try{return g(y.File.new_for_path(n).query_info(h,y.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null),n,`lstat`,t?.bigint)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`lstat`,n)}}function readdirSync(e,t){let n=r(e),i=y.File.new_for_path(n).enumerate_children(`standard::name,standard::type`,y.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null),a=[];try{let e=i.next_file(null);for(;e!==null;)a.push({name:e.get_name(),type:e.get_file_type()}),e=i.next_file(null)}finally{try{i.close(null)}catch{}}let o=[];for(let e of a){let r=b(n,e.name);if(t?.withFileTypes?o.push(new u(r,e.name,e.type)):o.push(e.name),t?.recursive&&e.type===y.FileType.DIRECTORY){let n=readdirSync(r,t);for(let t of n)typeof t==`string`?o.push(b(e.name,t)):o.push(t)}}return o}function realpathSync(e){let t=r(e);return resolveEveryComponent(y.File.new_for_path(t),{left:40},t)}function resolveEveryComponent(e,t,n){let r=e.get_parent();return expandSymlinks(r===null?e:y.File.new_for_path(resolveEveryComponent(r,t,n)).get_child(e.get_basename()),t,n)}function expandSymlinks(e,t,n){let r=e;for(;;){let e=r.query_info(`standard::is-symlink,standard::symlink-target`,y.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);if(!e.get_is_symlink())return r.get_path();if(--t.left<0)throw Error(`ELOOP: too many levels of symbolic links, realpath '${n}'`);let i=e.get_symlink_target(),a=r.get_parent(),o=v.path_is_absolute(i)?y.File.new_for_path(i):(a??r).resolve_relative_path(i);r=y.File.new_for_path(resolveEveryComponent(o,t,n))}}realpathSync.native=realpathSync;function symlinkSync(e,t,n){let i=r(t),a=r(e);y.File.new_for_path(i).make_symbolic_link(a,null)}function readFileSync(e,i={encoding:null,flag:`r`}){if(e instanceof _&&(e=e.fd),typeof e==`number`&&o(e))return t(n(i,`buffer`),s(e));if(typeof e==`number`)return t(n(i,`buffer`),_.getInstance(e,`read`)._readToEndSync());let a=r(e),c=y.File.new_for_path(a);try{let[e,r]=c.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;t!=null&&(typeof t==`object`?(t.recursive&&(n=t.recursive),t.mode!==void 0&&(i=t.mode)):i=t),e=r(e);let a=l(i,511);if(n)return mkdirSyncRecursive(e,a);mkdirWithMode(e,a)}function mkdirWithMode(e,t){if(v.mkdir(e,t)!==0)throw p(e)}function mkdirSyncRecursive(e,t){if(v.mkdir(e,t)===0)return e;let n=p(e);if(n.code===`EEXIST`){if(v.file_test(e,v.FileTest.IS_DIR))return;throw n}if(n.code!==`ENOENT`)throw n;let r=b(e,`..`),i=y.File.new_for_path(r).get_path();if(i===e)throw n;let a=mkdirSyncRecursive(i,t);return mkdirWithMode(e,t),a??e}function rmdirSync(e,t){let n=r(e),i=y.File.new_for_path(n);try{if(i.query_info(`standard::type`,y.FileQueryInfoFlags.NONE,null).get_file_type()!==y.FileType.DIRECTORY)throw d(Object.assign(Error(),{code:4}),`rmdir`,n);if(i.enumerate_children(`standard::name`,y.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=y.File.new_for_path(t);try{n.delete(null)}catch(e){throw d(e,`unlink`,t)}}function writeWholeFile(e,t,i,a){let s=n(i,`utf8`),l=typeof i==`object`&&i?i:{},u=typeof t==`string`?x.from(t,s||`utf8`):t;if(typeof e==`number`||e instanceof _){if(typeof e==`number`&&o(e)){c(e,u);return}_.getInstance(e,`write`)._writeSync(u,null);return}let d=new _({path:r(e),flags:l.flag??a,mode:l.mode??438});try{d._writeSync(u,null)}finally{d._closeSync()}}function writeFileSync(e,t,n){writeWholeFile(e,t,n??null,`w`)}function renameSync(e,t){let n=r(e),i=r(t),a=y.File.new_for_path(n),o=y.File.new_for_path(i);try{a.move(o,y.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=y.File.new_for_path(i),s=y.File.new_for_path(a),c=y.FileCopyFlags.NONE;n&&!(n&1)?c=y.FileCopyFlags.OVERWRITE:n||(c=y.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=y.File.new_for_path(n);try{let e=i.query_info(`access::*`,y.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){writeWholeFile(e,t,n??null,`a`)}function readlinkSync(e,t){let n=r(e),i=y.File.new_for_path(n);try{let e=i.query_info(`standard::symlink-target`,y.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`?x.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(y.File.new_for_path(n).query_file_type(y.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)===y.FileType.UNKNOWN)throw Object.assign(Error(`ENOENT: no such file or directory, link '${n}' -> '${i}'`),{code:`ENOENT`,errno:-2,syscall:`link`,path:n,dest:i});if(y.File.new_for_path(i).query_file_type(y.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)!==y.FileType.UNKNOWN)throw Object.assign(Error(`EEXIST: file already exists, link '${n}' -> '${i}'`),{code:`EEXIST`,errno:-17,syscall:`link`,path:n,dest:i});let a=``;try{let[,,e,t]=v.spawn_sync(null,[`ln`,`--`,n,i],null,v.SpawnFlags.SEARCH_PATH,null);if(a=e?new TextDecoder().decode(e).trim():``,!v.spawn_check_wait_status(t))throw Error(`ln exited non-zero (${t})`);return}catch(e){throw a===``&&e instanceof Error&&(a=e.message),Object.assign(Error(`EPERM: operation not permitted, link '${n}' -> '${i}'`+(a?` (${a})`:``)),{code:`EPERM`,errno:-1,syscall:`link`,path:n,dest:i})}}function truncateSync(e,t){let n=r(e),i=y.File.new_for_path(n);try{let e=i.open_readwrite(null);try{e.get_output_stream().truncate(Math.max(0,t??0),null)}finally{e.close(null)}}catch(e){throw d(e,`truncate`,n)}}function chmodSync(e,t){let n=r(e),i=l(t);try{y.File.new_for_path(n).set_attribute_uint32(`unix::mode`,i,y.FileQueryInfoFlags.NONE,null)}catch(e){throw d(e,`chmod`,n)}}function chownSync(e,t,n){let i=r(e);try{let e=y.File.new_for_path(i),r=new y.FileInfo;t!==-1&&r.set_attribute_uint32(`unix::uid`,t),n!==-1&&r.set_attribute_uint32(`unix::gid`,n),e.set_attributes_from_info(r,y.FileQueryInfoFlags.NONE,null)}catch(e){throw d(e,`chown`,i)}}function watch(e,t,n){return new a(r(e),t,n)}function openSync(e,t,n){return new _({path:e,flags:t,mode:n})}function mkdtempSync(t,r){let i=n(r);return e(mkdtempAt(t),i)}function mkdtempAt(e){for(let t=0;t<64;t++){let t=e+i();if(v.mkdir(t,448)===0)return t;let n=p(t);if(n.code!==`EEXIST`)throw n.syscall=`mkdtemp`,n}throw m(`EEXIST`,`mkdtemp`,e+`XXXXXX`)}function rmSync(e,t){let n=r(e),i=y.File.new_for_path(n),a=t?.recursive||!1,o=t?.force||!1,s;try{s=i.query_file_type(y.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){if(o&&f(t))return;throw d(t,`rm`,e)}if(s===y.FileType.SYMBOLIC_LINK){try{i.delete(null)}catch(t){if(o&&f(t))return;throw d(t,`rm`,e)}return}if(s===y.FileType.DIRECTORY){let r=readdirSync(e);if(!a&&r.length)throw d(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)rmSync(b(n,e),t)}try{i.delete(null)}catch(t){if(o&&f(t))return;throw d(t,`rm`,e)}}export{accessSync,appendFileSync,chmodSync,chownSync,copyFileSync,S as existsSync,linkSync,lstatSync,mkdirSync,mkdtempAt,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"./_virtual/_rolldown/runtime.js";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};
1
+ import"./_virtual/_rolldown/runtime.js";import{URL as e,fileURLToPath as t}from"node:url";function normalizePath(n){return n instanceof URL||n instanceof e?t(n):typeof n==`string`?n:n.toString()}function randomName(){return[...[,,,,,,]].map(()=>`0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ`[Math.floor(Math.random()*62)]).join(``)}export{normalizePath,randomName};
package/lib/esm/utimes.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";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(t,r,i){let a=e(t),o=n.File.new_for_path(a),s=new n.FileInfo;r!==-1&&s.set_attribute_uint32(`unix::uid`,r),i!==-1&&s.set_attribute_uint32(`unix::gid`,i),o.set_attributes_from_info(s,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}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
+ import"./_virtual/_rolldown/runtime.js";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(t,r,i){let a=e(t),o=n.File.new_for_path(a),s=new n.FileInfo;r!==-1&&s.set_attribute_uint32(`unix::uid`,r),i!==-1&&s.set_attribute_uint32(`unix::gid`,i),o.set_attributes_from_info(s,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}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 lchmodUnsupported(){let e=Error(`The lchmod() method is not implemented`);return e.code=`ERR_METHOD_NOT_IMPLEMENTED`,e}const r=void 0,i=void 0;async function lchmodAsync(e,t){throw lchmodUnsupported()}export{i as lchmod,lchmodAsync,r as lchmodSync,lchown,lchownAsync,lchownSync,lutimes,lutimesAsync,lutimesSync,utimes,utimesAsync,utimesSync};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";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};
1
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{normalizeMode as t}from"./posix-flags.js";import{close as n,open as r,write as i}from"./callback.js";import{Writable as a}from"node:stream";const o=Symbol(`kIsPerformingIO`),s=Symbol(`kIoDone`);function toPathIfFileURL(t){return e(t)}var WriteStream=class extends a{close(e,t=null){let done=t=>{typeof e==`function`&&e(t)};if(this.fd===null||!this._autoClose)this.fd=null,done(t);else{let e=this._fdFromHandle;n(this.fd,n=>{let r=e&&n?.code===`EBADF`?null:n;done(r||t)}),this.fd=null}}bytesWritten=0;path;pending;fd=null;flags=`w`;mode=438;pos=void 0;_autoClose=!0;_fdFromHandle=!1;[o]=!1;constructor(e,n={}){super(n),this.path=toPathIfFileURL(e),n.flags!==void 0&&(this.flags=n.flags),n.mode!==void 0&&(this.mode=t(n.mode,438)),n.start!==void 0&&(this.pos=n.start),n.encoding&&this.setDefaultEncoding(n.encoding),typeof n.fd==`number`?(this.fd=n.fd,this._autoClose=n.autoClose??!0,this._fdFromHandle=n.fdFromHandle===!0):n.autoClose!==void 0&&(this._autoClose=n.autoClose),this.pending=this.fd===null}_construct(e){if(this.fd!==null){e(),this.emit(`open`,this.fd),this.emit(`ready`);return}r(this.path.toString(),this.flags,this.mode,(t,n)=>{if(t){e(t);return}this.fd=n,this.pending=!1,e(),this.emit(`open`,this.fd),this.emit(`ready`)})}_write(e,t,n){this[o]=!0,i(this.fd,e,0,e.length,this.pos??null,(e,t)=>{if(this[o]=!1,this.destroyed)return n(e),this.emit(s,e);if(e)return n(e);this.bytesWritten+=t,n()}),this.pos!==void 0&&(this.pos+=e.length)}_destroy(e,t){this[o]?this.once(s,n=>this.close(t,e||n)):this.close(t,e)}};function createWriteStream(e,t){return new WriteStream(e,t)}export{WriteStream,createWriteStream,toPathIfFileURL};
@@ -1,3 +1,92 @@
1
1
  export declare const CAN_SYMLINK: boolean;
2
2
  /** The `reason` string every symlink-gated `it.failing` shares. */
3
3
  export declare const NO_SYMLINK_REASON: string;
4
+ export declare const CAN_SETGID: boolean;
5
+ /** The `reason` string every setgid-gated `it.failing` shares. */
6
+ export declare const NO_SETGID_REASON: string;
7
+ export declare const CAN_PROC_FD: boolean;
8
+ export declare const CAN_FD_TRUNCATE_ANY_MODE: boolean;
9
+ /** The `reason` string the mode-independent-ftruncate rule carries. */
10
+ export declare const NO_FD_TRUNCATE_REASON: string;
11
+ /**
12
+ * The `reason` for the rules whose TEST counts descriptors through procfs.
13
+ *
14
+ * The one procfs gate that survived contact with darwin. The descriptor-IDENTITY
15
+ * rules turned out not to need it — the GJS leg passes them on a host with no
16
+ * `/proc/self/fd` at all — but these two fail on BOTH legs there, because the
17
+ * instrument they measure a leak with is `readdirSync('/proc/self/fd')` itself.
18
+ */
19
+ export declare const PROC_FD_COUNTING_REASON: string;
20
+ export declare const CAN_DENY_SEARCH: boolean;
21
+ /** The `reason` string every search-denial-gated `it.failing` shares. */
22
+ export declare const NO_DENY_SEARCH_REASON: string;
23
+ /** True on real GJS — the same signal `@gjsify/unit` gates its host hooks on. */
24
+ export declare const IS_GJS: boolean;
25
+ /**
26
+ * Can this filesystem store the nine POSIX permission bits and report them back?
27
+ *
28
+ * NTFS cannot. Node synthesizes a mode on Windows — 0o666 for a writable file,
29
+ * 0o444 for a read-only one, and nothing narrower — so every rule of the form
30
+ * "the mode I asked for is the mode on disk" compares 0o600 against 0o666 and
31
+ * fails for a reason that has nothing to do with the code under test.
32
+ */
33
+ export declare const CAN_EXPRESS_POSIX_MODE: boolean;
34
+ /** The `reason` string every mode-gated `it.failing` shares. */
35
+ export declare const NO_POSIX_MODE_REASON: string;
36
+ /**
37
+ * Does this host spell the POSIX errno for a refusal the way Linux does?
38
+ *
39
+ * win32 answers ENOENT where POSIX says ENOTDIR (a child of a regular file) and
40
+ * ENOENT or EINVAL where POSIX says ENAMETOOLONG, and reports EPERM for the
41
+ * EACCES and EINVAL cases. These are the reference implementation's own dialect,
42
+ * not a defect in the classifier the rules below guard.
43
+ */
44
+ export declare const HAS_POSIX_ERRNO: boolean;
45
+ /** The `reason` string every errno-dialect-gated `it.failing` shares. */
46
+ export declare const NO_POSIX_ERRNO_REASON: string;
47
+ /**
48
+ * Does an exclusive create refuse a symbolic link that dangles?
49
+ *
50
+ * `O_EXCL` on POSIX refuses ANY existing name, symlink included — which is what
51
+ * stops whoever planted the link from choosing where the caller's bytes land.
52
+ * win32 opens it instead. The rules this gates are security rules, which is
53
+ * exactly why they are keyed rather than probed: a probe would ask the code
54
+ * under test whether the hole is open, and take yes for an answer.
55
+ */
56
+ export declare const EXCL_REFUSES_SYMLINK: boolean;
57
+ /** The `reason` string the exclusive-create-over-symlink rules share. */
58
+ export declare const NO_EXCL_SYMLINK_REASON: string;
59
+ /**
60
+ * Does `open(2)` keep a setuid/setgid bit that was requested in the create mode,
61
+ * and `mkdir(2)` a sticky bit?
62
+ *
63
+ * Linux keeps both: `open` masks the requested mode with nothing but the umask,
64
+ * and `vfs_mkdir()` masks to `S_IRWXUGO | S_ISVTX`, so sticky survives. BSD —
65
+ * and therefore darwin — masks the create mode to `ACCESSPERMS`, dropping every
66
+ * special bit before the inode is written.
67
+ *
68
+ * Keyed on `linux` rather than probed for the reason above: the special bits ARE
69
+ * the mode surface, and a probe would let a gjsify regression describe itself as
70
+ * a host property.
71
+ */
72
+ export declare const CREATE_KEEPS_SPECIAL_BITS: boolean;
73
+ /** The `reason` string the special-bit rules share. */
74
+ export declare const NO_SPECIAL_BITS_REASON: string;
75
+ /**
76
+ * Does a positional write on an `O_APPEND` descriptor still append?
77
+ *
78
+ * POSIX requires it — XSH `pwrite`: "If the O_APPEND flag of the file status
79
+ * flags is set, the file offset shall be set to the end of the file prior to
80
+ * each write". Linux obeys, and so does libuv on win32 (measured: the rule
81
+ * passes there). darwin is the outlier — BSD's pwrite writes AT the offset — so
82
+ * `writeSync(fd, buf, 0, n, 0)` on an append fd destroys the head of the log.
83
+ *
84
+ * `@gjsify/fs` implements the POSIX rule on every platform (it never passes a
85
+ * position for an append descriptor at all — see `_writeCore`), so on a
86
+ * non-Linux host the two legs genuinely disagree, and it is the REFERENCE that
87
+ * diverges from the standard. The marker therefore scopes to the Node leg; the
88
+ * GJS leg runs the rule and must pass.
89
+ */
90
+ export declare const PWRITE_OBEYS_APPEND: boolean;
91
+ /** The `reason` string the positional-append rule carries. */
92
+ export declare const NO_PWRITE_APPEND_REASON: string;
@@ -30,11 +30,31 @@ export declare class Dirent implements OriginalDirent {
30
30
  private _isSocket;
31
31
  /** This is not part of node.fs and is used internal by gjsify */
32
32
  protected _file: Gio.File;
33
- /** This is not part of node.fs and is used internal by gjsify */
34
- constructor(path: string, filename?: string, fileType?: Gio.FileType);
33
+ /**
34
+ * This is not part of node.fs and is used internal by gjsify
35
+ *
36
+ * `info` is the lookup `fileType` came from, where the caller has one.
37
+ * Passing it is what makes `fstatSync` answer about the FILE and not about
38
+ * the procfs link that names its descriptor — see {@link _classifySpecialFile}.
39
+ */
40
+ constructor(path: string, filename?: string, fileType?: Gio.FileType, info?: Gio.FileInfo);
35
41
  /**
36
42
  * Classify a SPECIAL file type using the unix::mode attribute from Gio.FileInfo.
37
43
  * Falls back to marking nothing if the mode attribute is unavailable.
44
+ *
45
+ * TWO lookups decide one question here, and they have to agree. The type
46
+ * above said SPECIAL after FOLLOWING the name; re-asking with
47
+ * `NOFOLLOW_SYMLINKS` asks about a different object. That is not academic:
48
+ * `fstatSync(fd)` stats `/proc/self/fd/<n>`, which IS a symlink, so the
49
+ * followed lookup correctly said SPECIAL and the NOFOLLOW re-query saw
50
+ * `S_IFLNK`, matched none of the four cases below, and left EVERY predicate
51
+ * false — `isFIFO()`, `isFile()` and `isCharacterDevice()` all `false` for a
52
+ * descriptor on a FIFO or on `/dev/null`, so a caller classifying it got
53
+ * "none of the above".
54
+ *
55
+ * So the caller's own `GFileInfo` is used when there is one (`statSync` and
56
+ * `lstatSync` already query `unix::*`, so it costs no syscall), and the
57
+ * fallback follows, matching the `query_file_type` two lines above it.
38
58
  */
39
59
  private _classifySpecialFile;
40
60
  /**
@@ -3,5 +3,16 @@ import { isNotFoundError } from '@gjsify/utils/core';
3
3
  export { isNotFoundError };
4
4
  /**
5
5
  * Create a Node.js-style ErrnoException from a Gio error, with fs-specific path/dest fields.
6
+ *
7
+ * An error that ALREADY carries a Node code passes through untouched. The
8
+ * generic mapper reads `err.code` as a NUMERIC `Gio.IOErrorEnum` and looks it
9
+ * up in a table, so a string code misses and falls through to the `|| 'EIO'`
10
+ * default — which means every `try { … } catch (e) { throw createNodeError(e,
11
+ * …) }` in this package silently DOWNGRADED the precise codes `fd-io.ts`
12
+ * reconstructs (EACCES, EEXIST, ENOTDIR, ELOOP, ENAMETOOLONG, EBADF, ESPIPE) to
13
+ * a generic I/O error, and stamped its own syscall and path over them. Since
14
+ * this redesign the precise ones are the common case inside those blocks, so
15
+ * the guard belongs here rather than at each call site: the alternative is
16
+ * remembering to hoist every throw out of every try, once per site, forever.
6
17
  */
7
18
  export declare function createNodeError(err: unknown, syscall: string, path: PathLike, dest?: PathLike): NodeJS.ErrnoException;