@gjsify/fs 0.64.12 → 0.64.13

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{createNodeError as t,requireCallback as n}from"./errors.js";import{STAT_ATTRIBUTES as r,statsFrom as i}from"./stats.js";import{FileHandle as a}from"./file-handle.js";import{accessSync as o,appendFileSync as s,chmodSync as c,chownSync as l,copyFileSync as u,linkSync as d,mkdirSync as f,mkdtempSync as p,readFileSync as m,readdirSync as h,readlinkSync as g,realpathSync as _,renameSync as v,rmdirSync as y,truncateSync as b,writeFileSync as x}from"./sync.js";import{open as S,rm as C}from"./promises.js";import w from"@girs/glib-2.0";import T from"@girs/gio-2.0";import{Buffer as E}from"node:buffer";function withHandle(e,t,n){try{return a.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:n(t)}}function statImpl(n,a,o,s,c){let l=e(n),u=T.File.new_for_path(l);u.query_info_async(r,a,w.PRIORITY_DEFAULT,null,(e,n)=>{try{c(null,i(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,T.FileQueryInfoFlags.NONE,`stat`,r,i)}function lstat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,T.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,h(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,_(e))}catch(e){r(e)}})}realpath.native=realpath;function symlink(r,i,a,o){let s=typeof a==`function`?a:n(o);if(typeof s!=`function`)throw TypeError(`Callback must be a function. Received `+typeof s);let c=e(i),l=e(r),u=T.File.new_for_path(c);u.make_symbolic_link_async(l,w.PRIORITY_DEFAULT,null,(e,n)=>{try{u.make_symbolic_link_finish(n),s(null)}catch(e){s(t(e,`symlink`,l,c))}})}function open(e,...t){let r,i,a;switch(t.length){case 1:a=t[0];break;case 2:r=t[0],a=t[1];break;case 3:r=t[0],i=t[1],a=t[2];break;default:break}let o=n(a);S(e,r,i).then(e=>{o(null,e.fd)}).catch(e=>{o(e,-1)})}function write(e,t,...r){n(r[r.length-1]);let i=withHandle(e,`write`,e=>{let n=r[r.length-1];typeof t==`string`?n(e,0,``):n(e,0,E.from([]))});if(!i)return;if(typeof t==`string`){let e=r.pop(),n=r[0],a=r[1];i.write(t,n,a).then(t=>{e(null,t.bytesWritten,t.buffer)}).catch(t=>{e(t,0,``)});return}let a=r[r.length-1],o=r[0],s=r[1],c=r[2];i.write(t,o,s,c).then(e=>{a(null,e.bytesWritten,e.buffer)}).catch(e=>{a(e,0,E.from([]))})}function read(e,...t){let r=n(t[t.length-1]),i=withHandle(e,`read`,e=>{typeof r==`function`&&r(e,0,E.from([]))});if(!i)return;let 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];i.read(a,o,s,c).then(e=>{r(null,e.bytesRead,e.buffer)}).catch(e=>{r(e,0,E.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]),C(e,n).then(()=>{r(null)}).catch(e=>{r(e)})}function rename(e,t,r){n(r),Promise.resolve().then(()=>{try{v(e,t),r(null)}catch(e){r(e)}})}function copyFile(e,t,r,i){let a=typeof r==`function`?0:r,o=typeof r==`function`?r:n(i);Promise.resolve().then(()=>{try{u(e,t,a),o(null)}catch(e){o(e)}})}function access(e,t,r){let i=typeof t==`function`?void 0:t,a=typeof t==`function`?t:n(r);Promise.resolve().then(()=>{try{o(e,i),a(null)}catch(e){a(e)}})}function appendFile(e,t,r,i){let a=typeof r==`function`?r:n(i),o=typeof r==`function`?void 0:r;Promise.resolve().then(()=>{try{s(e,t,o),a(null)}catch(e){a(e)}})}function readlink(e,t,r){let i=typeof t==`function`?t:n(r),a=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{i(null,g(e,a))}catch(e){i(e,``)}})}function truncate(e,t,r){let i=typeof t==`function`?0:t,a=typeof t==`function`?t:n(r);Promise.resolve().then(()=>{try{b(e,i),a(null)}catch(e){a(e)}})}function chmod(e,t,r){n(r),Promise.resolve().then(()=>{try{c(e,t),r(null)}catch(e){r(e)}})}function chown(e,t,r,i){n(i),Promise.resolve().then(()=>{try{l(e,t,r),i(null)}catch(e){i(e)}})}function mkdir(e,t,r){let i=typeof t==`function`?t:n(r),a=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{f(e,a),i(null)}catch(e){i(e)}})}function mkdtemp(e,t,r){let i=typeof t==`function`?t:n(r),a=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{let t;try{t=p(e,a)}catch(e){i(e,void 0);return}i(null,t)})}function rmdir(e,t,r){let i=typeof t==`function`?t:n(r),a=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{y(e,a),i(null)}catch(e){i(e)}})}function readFile(e,t,r){let i=typeof t==`function`?t:n(r),a=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{let t=typeof a==`string`?{encoding:a,flag:`r`}:{encoding:a?.encoding??null,flag:a?.flag??`r`};i(null,m(e,t))}catch(e){i(e,null)}})}function writeFile(e,t,r,i){let a=typeof r==`function`?r:n(i),o=typeof r==`function`?void 0:r;Promise.resolve().then(()=>{try{x(e,t,o),a(null)}catch(e){a(e)}})}function link(e,t,r){n(r),Promise.resolve().then(()=>{try{d(e,t),r(null)}catch(e){r(e)}})}function unlink(t,r){n(r);let i=e(t);Promise.resolve().then(()=>{w.unlink(i),r(null)})}export{access,appendFile,chmod,chown,close,copyFile,link,lstat,mkdir,mkdtemp,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,requireCallback as n}from"./errors.js";import{request as r}from"./request.js";import{STAT_ATTRIBUTES as i,statsFrom as a}from"./stats.js";import{FileHandle as o}from"./file-handle.js";import{accessSync as s,appendFileSync as c,chmodSync as l,chownSync as u,copyFileSync as d,linkSync as f,mkdirSync as p,mkdtempSync as m,readFileSync as h,readdirSync as g,readlinkSync as _,realpathSync as v,renameSync as y,rmdirSync as b,truncateSync as x,writeFileSync as S}from"./sync.js";import{open as C,rm as w}from"./promises.js";import T from"@girs/glib-2.0";import E from"@girs/gio-2.0";import{Buffer as D}from"node:buffer";function withHandle(e,t,n){try{return o.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:n(t)}}function statImpl(n,o,s,c,l){let u=e(n),d=E.File.new_for_path(u);d.query_info_async(i,o,T.PRIORITY_DEFAULT,null,r((e,n)=>{try{l(null,a(d.query_info_finish(n),u,s,c?.bigint))}catch(e){l(t(e,s,u))}}))}function stat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,E.FileQueryInfoFlags.NONE,`stat`,r,i)}function lstat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,E.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,g(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,v(e))}catch(e){r(e)}})}realpath.native=realpath;function symlink(i,a,o,s){let c=typeof o==`function`?o:n(s);if(typeof c!=`function`)throw TypeError(`Callback must be a function. Received `+typeof c);let l=e(a),u=e(i),d=E.File.new_for_path(l);d.make_symbolic_link_async(u,T.PRIORITY_DEFAULT,null,r((e,n)=>{try{d.make_symbolic_link_finish(n),c(null)}catch(e){c(t(e,`symlink`,u,l))}}))}function open(e,...t){let r,i,a;switch(t.length){case 1:a=t[0];break;case 2:r=t[0],a=t[1];break;case 3:r=t[0],i=t[1],a=t[2];break;default:break}let o=n(a);C(e,r,i).then(e=>{o(null,e.fd)}).catch(e=>{o(e,-1)})}function write(e,t,...r){n(r[r.length-1]);let i=withHandle(e,`write`,e=>{let n=r[r.length-1];typeof t==`string`?n(e,0,``):n(e,0,D.from([]))});if(!i)return;if(typeof t==`string`){let e=r.pop(),n=r[0],a=r[1];i.write(t,n,a).then(t=>{e(null,t.bytesWritten,t.buffer)}).catch(t=>{e(t,0,``)});return}let a=r[r.length-1],o=r[0],s=r[1],c=r[2];i.write(t,o,s,c).then(e=>{a(null,e.bytesWritten,e.buffer)}).catch(e=>{a(e,0,D.from([]))})}function read(e,...t){let r=n(t[t.length-1]),i=withHandle(e,`read`,e=>{typeof r==`function`&&r(e,0,D.from([]))});if(!i)return;let 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];i.read(a,o,s,c).then(e=>{r(null,e.bytesRead,e.buffer)}).catch(e=>{r(e,0,D.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]),w(e,n).then(()=>{r(null)}).catch(e=>{r(e)})}function rename(e,t,r){n(r),Promise.resolve().then(()=>{try{y(e,t),r(null)}catch(e){r(e)}})}function copyFile(e,t,r,i){let a=typeof r==`function`?0:r,o=typeof r==`function`?r:n(i);Promise.resolve().then(()=>{try{d(e,t,a),o(null)}catch(e){o(e)}})}function access(e,t,r){let i=typeof t==`function`?void 0:t,a=typeof t==`function`?t:n(r);Promise.resolve().then(()=>{try{s(e,i),a(null)}catch(e){a(e)}})}function appendFile(e,t,r,i){let a=typeof r==`function`?r:n(i),o=typeof r==`function`?void 0:r;Promise.resolve().then(()=>{try{c(e,t,o),a(null)}catch(e){a(e)}})}function readlink(e,t,r){let i=typeof t==`function`?t:n(r),a=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{i(null,_(e,a))}catch(e){i(e,``)}})}function truncate(e,t,r){let i=typeof t==`function`?0:t,a=typeof t==`function`?t:n(r);Promise.resolve().then(()=>{try{x(e,i),a(null)}catch(e){a(e)}})}function chmod(e,t,r){n(r),Promise.resolve().then(()=>{try{l(e,t),r(null)}catch(e){r(e)}})}function chown(e,t,r,i){n(i),Promise.resolve().then(()=>{try{u(e,t,r),i(null)}catch(e){i(e)}})}function mkdir(e,t,r){let i=typeof t==`function`?t:n(r),a=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{p(e,a),i(null)}catch(e){i(e)}})}function mkdtemp(e,t,r){let i=typeof t==`function`?t:n(r),a=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{let t;try{t=m(e,a)}catch(e){i(e,void 0);return}i(null,t)})}function rmdir(e,t,r){let i=typeof t==`function`?t:n(r),a=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{b(e,a),i(null)}catch(e){i(e)}})}function readFile(e,t,r){let i=typeof t==`function`?t:n(r),a=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{let t=typeof a==`string`?{encoding:a,flag:`r`}:{encoding:a?.encoding??null,flag:a?.flag??`r`};i(null,h(e,t))}catch(e){i(e,null)}})}function writeFile(e,t,r,i){let a=typeof r==`function`?r:n(i),o=typeof r==`function`?void 0:r;Promise.resolve().then(()=>{try{S(e,t,o),a(null)}catch(e){a(e)}})}function link(e,t,r){n(r),Promise.resolve().then(()=>{try{f(e,t),r(null)}catch(e){r(e)}})}function unlink(t,r){n(r);let i=e(t);Promise.resolve().then(()=>{T.unlink(i),r(null)})}export{access,appendFile,chmod,chown,close,copyFile,link,lstat,mkdir,mkdtemp,open,read,readFile,readdir,readlink,realpath,rename,rm,rmdir,stat,symlink,truncate,unlink,write,writeFile};
package/lib/esm/dir.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{createNodeError as t,requireCallback as n}from"./errors.js";import{Dirent as r}from"./dirent.js";import i from"@girs/glib-2.0";import a from"@girs/gio-2.0";import{join as o}from"node:path";const s=`standard::name,standard::type,standard::is-symlink,standard::size,standard::symlink-target,unix::uid,unix::gid,unix::mode,time::modified,time::access,time::created`;var Dir=class{path;_enumerator;_closed=!1;constructor(e,t){this.path=e,this._enumerator=t}_assertOpen(){if(this._closed){let e=Error(`Directory handle was closed`);throw e.code=`ERR_DIR_CLOSED`,e}}readSync(){this._assertOpen();try{let e=this._enumerator.next_file(null);if(e===null)return null;let t=e.get_name(),n=e.get_file_type();return new r(o(this.path,t),t,n,void 0,this.path)}catch(e){throw t(e,`readdir`,this.path)}}read(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this._assertOpen();let t=this.readSync();Promise.resolve().then(()=>e(null,t))}catch(t){Promise.resolve().then(()=>e(t,null))}return}return new Promise((e,t)=>{try{this._assertOpen(),e(this.readSync())}catch(e){t(e)}})}closeSync(){this._assertOpen(),this._closed=!0;try{this._enumerator.close(null)}catch{}this._enumerator=null}close(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this.closeSync(),Promise.resolve().then(()=>e(null))}catch(t){Promise.resolve().then(()=>e(t))}return}return new Promise((e,t)=>{try{this.closeSync(),e()}catch(e){t(e)}})}async*[Symbol.asyncIterator](){try{for(;;){let e=await this.read();if(e===null)break;yield e}}finally{this._closed||await this.close()}}};function _openDir(e){let n=a.File.new_for_path(e),r;try{r=n.enumerate_children(s,a.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(n){throw t(n,`opendir`,e)}return new Dir(e,r)}function opendirSync(t){return _openDir(e(t))}function opendir(e,t,r){let i;if(i=typeof t==`function`?t:n(r,`callback`),typeof i!=`function`)throw TypeError(`The "callback" argument must be of type function`);Promise.resolve().then(()=>{try{let t=opendirSync(e);i(null,t)}catch(e){i(e,null)}})}async function opendirAsync(n,r){return new Promise((r,o)=>{let c=e(n),l=a.File.new_for_path(c);l.enumerate_children_async(s,a.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,i.PRIORITY_DEFAULT,null,(e,n)=>{try{let e=l.enumerate_children_finish(n);r(new Dir(c,e))}catch(e){o(t(e,`opendir`,c))}})})}export{Dir,opendir,opendirAsync,opendirSync};
1
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{createNodeError as t,requireCallback as n}from"./errors.js";import{request as r}from"./request.js";import{Dirent as i}from"./dirent.js";import a from"@girs/glib-2.0";import o from"@girs/gio-2.0";import{join as s}from"node:path";const c=`standard::name,standard::type,standard::is-symlink,standard::size,standard::symlink-target,unix::uid,unix::gid,unix::mode,time::modified,time::access,time::created`;var Dir=class{path;_enumerator;_closed=!1;constructor(e,t){this.path=e,this._enumerator=t}_assertOpen(){if(this._closed){let e=Error(`Directory handle was closed`);throw e.code=`ERR_DIR_CLOSED`,e}}readSync(){this._assertOpen();try{let e=this._enumerator.next_file(null);if(e===null)return null;let t=e.get_name(),n=e.get_file_type();return new i(s(this.path,t),t,n,void 0,this.path)}catch(e){throw t(e,`readdir`,this.path)}}read(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this._assertOpen();let t=this.readSync();Promise.resolve().then(()=>e(null,t))}catch(t){Promise.resolve().then(()=>e(t,null))}return}return new Promise((e,t)=>{try{this._assertOpen(),e(this.readSync())}catch(e){t(e)}})}closeSync(){this._assertOpen(),this._closed=!0;try{this._enumerator.close(null)}catch{}this._enumerator=null}close(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this.closeSync(),Promise.resolve().then(()=>e(null))}catch(t){Promise.resolve().then(()=>e(t))}return}return new Promise((e,t)=>{try{this.closeSync(),e()}catch(e){t(e)}})}async*[Symbol.asyncIterator](){try{for(;;){let e=await this.read();if(e===null)break;yield e}}finally{this._closed||await this.close()}}};function _openDir(e){let n=o.File.new_for_path(e),r;try{r=n.enumerate_children(c,o.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(n){throw t(n,`opendir`,e)}return new Dir(e,r)}function opendirSync(t){return _openDir(e(t))}function opendir(e,t,r){let i;if(i=typeof t==`function`?t:n(r,`callback`),typeof i!=`function`)throw TypeError(`The "callback" argument must be of type function`);Promise.resolve().then(()=>{try{let t=opendirSync(e);i(null,t)}catch(e){i(e,null)}})}async function opendirAsync(n,i){return new Promise((i,s)=>{let l=e(n),u=o.File.new_for_path(l);u.enumerate_children_async(c,o.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,a.PRIORITY_DEFAULT,null,r((e,n)=>{try{let e=u.enumerate_children_finish(n);i(new Dir(l,e))}catch(e){s(t(e,`opendir`,l))}}))})}export{Dir,opendir,opendirAsync,opendirSync};
@@ -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{invalidState as r}from"./errors.js";import{ReadStream as i}from"./read-stream.js";import{normalizeMode as a,parseOpenFlags as o}from"./posix-flags.js";import{WriteStream as s}from"./write-stream.js";import{closeFd as c,fdPath as l,fsError as u,fsyncFd as d,isSeekableFd as f,openFd as p,readFd as m,releaseFd as h,seekFd as g,sizeOfFd as _,tellFd as v,truncateFd as y,writeFd as b}from"./fd-io.js";import{STAT_ATTRIBUTES as x,statsFrom as S}from"./stats.js";import{chmodSync as C,chownSync as w}from"./sync.js";import T from"@girs/glib-2.0";import E from"@girs/gio-2.0";import{Buffer as D}from"node:buffer";import{createInterface as O}from"node:readline";var k=class FileHandle{options;_gFile;_pathStr;_spec;_pos=0;_closed=!1;_webStreamLocked=!1;static instances={};constructor(e){this.options=e,this.options.flags??=`r`;let t=n(e.path);this._spec=o(this.options.flags),this.options.mode??=438;let r=a(this.options.mode,438);return this.fd=p(t,this._spec,r),this._pathStr=t,this._gFile=E.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 u(`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=f(this.fd,this._pathStr);if(i&&!a)throw u(`ESPIPE`,`read`,this._pathStr);let o=i?r:this._pos;a&&g(this.fd,o);let s=m(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 u(`EBADF`,`write`,this._pathStr);if(this._spec.append){let t=b(this.fd,e);return this._pos=v(this.fd)??_(this.fd,this._pathStr),t}let n=t!=null&&t>=0,r=f(this.fd,this._pathStr);if(n&&!r)throw u(`ESPIPE`,`write`,this._pathStr);let i=n?t:this._pos;r&&g(this.fd,i);let a=b(this.fd,e);return!n&&r&&(this._pos=i+a),a}_assertOpen(e){if(this._closed)throw u(`EBADF`,e,this._pathStr)}_truncateCore(e){if(this._assertOpen(`ftruncate`),!this._spec.writable)throw u(`EINVAL`,`ftruncate`,this._pathStr);y(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 l(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 u(`EBADF`,t);return r}async appendFile(e,t){await this.writeFile(e,t)}async chown(e,t){this._assertOpen(`fchown`),w(n(this.options.path),e,t)}async chmod(e){this._assertOpen(`fchmod`),C(this._fdTarget(),e)}createReadStream(e){return new i(this.options.path,{...e,fd:this.fd})}createWriteStream(e){return new s(this.options.path,{...e,fd:this.fd,fdFromHandle:!0})}async datasync(){this._assertOpen(`fdatasync`),d(this.fd)}async sync(){this._assertOpen(`fsync`),d(this.fd)}async read(...e){let t,n,r,i;if(typeof e[0]==`object`&&!(e[0]instanceof Uint8Array)&&!(e[0]instanceof D)){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(){if(this._closed)throw r(`The FileHandle is closed`);if(this._webStreamLocked)throw r(`The FileHandle is locked`);let e=globalThis.ReadableStream;if(typeof e!=`function`)throw Error(`readableWebStream() requires a global ReadableStream. Import "node:stream/web" or "@gjsify/web-streams/register" before calling this method.`);return this._webStreamLocked=!0,new e({type:`bytes`,pull:e=>{if(this._closed){e.close(),e.byobRequest?.respond(0);return}let t=e.byobRequest?.view,n=t?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(64*1024),r;try{r=this._readCore(n,0,n.length,null)}catch(t){e.error(t);return}if(r===0){e.close(),e.byobRequest?.respond(0);return}if(e.byobRequest){e.byobRequest.respond(r);return}e.enqueue(n.subarray(0,r))}})}async readFile(n){return e(t(n,`buffer`),this._readToEnd())}readLines(e){return O({input:this.createReadStream(e),crlfDelay:1/0})}async stat(e){this._assertOpen(`fstat`);let t=E.File.new_for_path(this._fdTarget());return S(await new Promise((e,n)=>{t.query_info_async(x,E.FileQueryInfoFlags.NONE,T.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`?D.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=D.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:D.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(){d(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,h(this.fd),c(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{k 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{invalidState as r}from"./errors.js";import{request as i}from"./request.js";import{ReadStream as a}from"./read-stream.js";import{normalizeMode as o,parseOpenFlags as s}from"./posix-flags.js";import{WriteStream as c}from"./write-stream.js";import{closeFd as l,fdPath as u,fsError as d,fsyncFd as f,isSeekableFd as p,openFd as m,readFd as h,releaseFd as g,seekFd as _,sizeOfFd as v,tellFd as y,truncateFd as b,writeFd as x}from"./fd-io.js";import{STAT_ATTRIBUTES as S,statsFrom as C}from"./stats.js";import{chmodSync as w,chownSync as T}from"./sync.js";import E from"@girs/glib-2.0";import D from"@girs/gio-2.0";import{Buffer as O}from"node:buffer";import{createInterface as k}from"node:readline";var A=class FileHandle{options;_gFile;_pathStr;_spec;_pos=0;_closed=!1;_webStreamLocked=!1;static instances={};constructor(e){this.options=e,this.options.flags??=`r`;let t=n(e.path);this._spec=s(this.options.flags),this.options.mode??=438;let r=o(this.options.mode,438);return this.fd=m(t,this._spec,r),this._pathStr=t,this._gFile=D.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 d(`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=p(this.fd,this._pathStr);if(i&&!a)throw d(`ESPIPE`,`read`,this._pathStr);let o=i?r:this._pos;a&&_(this.fd,o);let s=h(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 d(`EBADF`,`write`,this._pathStr);if(this._spec.append){let t=x(this.fd,e);return this._pos=y(this.fd)??v(this.fd,this._pathStr),t}let n=t!=null&&t>=0,r=p(this.fd,this._pathStr);if(n&&!r)throw d(`ESPIPE`,`write`,this._pathStr);let i=n?t:this._pos;r&&_(this.fd,i);let a=x(this.fd,e);return!n&&r&&(this._pos=i+a),a}_assertOpen(e){if(this._closed)throw d(`EBADF`,e,this._pathStr)}_truncateCore(e){if(this._assertOpen(`ftruncate`),!this._spec.writable)throw d(`EINVAL`,`ftruncate`,this._pathStr);b(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 u(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 d(`EBADF`,t);return r}async appendFile(e,t){await this.writeFile(e,t)}async chown(e,t){this._assertOpen(`fchown`),T(n(this.options.path),e,t)}async chmod(e){this._assertOpen(`fchmod`),w(this._fdTarget(),e)}createReadStream(e){return new a(this.options.path,{...e,fd:this.fd})}createWriteStream(e){return new c(this.options.path,{...e,fd:this.fd,fdFromHandle:!0})}async datasync(){this._assertOpen(`fdatasync`),f(this.fd)}async sync(){this._assertOpen(`fsync`),f(this.fd)}async read(...e){let t,n,r,i;if(typeof e[0]==`object`&&!(e[0]instanceof Uint8Array)&&!(e[0]instanceof O)){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(){if(this._closed)throw r(`The FileHandle is closed`);if(this._webStreamLocked)throw r(`The FileHandle is locked`);let e=globalThis.ReadableStream;if(typeof e!=`function`)throw Error(`readableWebStream() requires a global ReadableStream. Import "node:stream/web" or "@gjsify/web-streams/register" before calling this method.`);return this._webStreamLocked=!0,new e({type:`bytes`,pull:e=>{if(this._closed){e.close(),e.byobRequest?.respond(0);return}let t=e.byobRequest?.view,n=t?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(64*1024),r;try{r=this._readCore(n,0,n.length,null)}catch(t){e.error(t);return}if(r===0){e.close(),e.byobRequest?.respond(0);return}if(e.byobRequest){e.byobRequest.respond(r);return}e.enqueue(n.subarray(0,r))}})}async readFile(n){return e(t(n,`buffer`),this._readToEnd())}readLines(e){return k({input:this.createReadStream(e),crlfDelay:1/0})}async stat(e){this._assertOpen(`fstat`);let t=D.File.new_for_path(this._fdTarget());return C(await new Promise((e,n)=>{t.query_info_async(S,D.FileQueryInfoFlags.NONE,E.PRIORITY_DEFAULT,null,i((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`?O.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=O.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:O.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(){f(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,g(this.fd),l(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{A as FileHandle};
@@ -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}from"./utils.js";import{createNodeError as a}from"./errors.js";import{watchAsync as o}from"./fs-watcher.js";import{lchmodAsync as s,lchownAsync as c,lutimesAsync as l,utimesAsync as u}from"./utimes.js";import{fchmodAsync as d,fchownAsync as f,fdatasyncAsync as p,fstatAsync as m,fsyncAsync as h,ftruncateAsync as g,futimesAsync as _,openAsBlob as v,readvAsync as y,writevAsync as b}from"./fd-ops.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{constants as H}from"./constants.js";import U from"@girs/glib-2.0";import W from"@girs/gio-2.0";import{join as G}from"node:path";var K=e({access:()=>access,appendFile:()=>appendFile,chmod:()=>chmod,chown:()=>chown,constants:()=>H,copyFile:()=>copyFile,cp:()=>R,default:()=>q,fchmod:()=>d,fchown:()=>f,fdatasync:()=>p,fstat:()=>m,fsync:()=>h,ftruncate:()=>g,futimes:()=>_,glob:()=>B,lchmod:()=>s,lchown:()=>c,link:()=>link,lstat:()=>lstat,lutimes:()=>l,mkdir:()=>mkdir,mkdtemp:()=>mkdtemp,open:()=>open,openAsBlob:()=>v,opendir:()=>z,readFile:()=>readFile,readdir:()=>readdir,readlink:()=>readlink,readv:()=>y,realpath:()=>realpath,rename:()=>rename,rm:()=>rm,rmdir:()=>rmdir,stat:()=>stat,statfs:()=>V,symlink:()=>symlink,truncate:()=>truncate,unlink:()=>unlink,utimes:()=>u,watch:()=>o,write:()=>write,writeFile:()=>writeFile,writev:()=>b});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 o=i(e),s=W.File.new_for_path(o),c,l;try{[c,l]=await new Promise((e,t)=>{s.load_contents_async(null,(n,r)=>{try{e(s.load_contents_finish(r))}catch(e){t(e)}})})}catch(e){throw a(e,`open`,o)}if(!c)throw a(Error(`failed to read file`),`open`,o);return n(r(t,`buffer`),l)}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=W.File.new_for_path(n);if((await new Promise((e,t)=>{r.query_info_async(`standard::type`,W.FileQueryInfoFlags.NONE,U.PRIORITY_DEFAULT,null,(i,o)=>{try{e(r.query_info_finish(o))}catch(e){t(a(e,`rmdir`,n))}})})).get_file_type()!==W.FileType.DIRECTORY)throw a(Object.assign(Error(),{code:4}),`rmdir`,n);if((await new Promise((e,t)=>{r.enumerate_children_async(`standard::name`,W.FileQueryInfoFlags.NONE,U.PRIORITY_DEFAULT,null,(i,o)=>{try{e(r.enumerate_children_finish(o))}catch(e){t(a(e,`rmdir`,n))}})})).next_file(null)!==null)throw a(Object.assign(Error(),{code:5}),`rmdir`,n);await new Promise((e,t)=>{r.delete_async(U.PRIORITY_DEFAULT,null,(i,o)=>{try{r.delete_finish(o),e()}catch(e){t(a(e,`rmdir`,n))}})})}async function unlink(e){let t=i(e),n=W.File.new_for_path(t);await new Promise((e,r)=>{n.delete_async(U.PRIORITY_DEFAULT,null,(i,o)=>{try{n.delete_finish(o),e()}catch(e){r(a(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 o=i(e);return new Promise((e,i)=>{let s=W.File.new_for_path(o);s.query_info_async(x,t,U.PRIORITY_DEFAULT,null,(t,c)=>{try{e(S(s.query_info_finish(c),o,n,r?.bigint))}catch(e){i(a(e,n,o))}})})}async function stat(e,t){return queryInfoAsync(e,W.FileQueryInfoFlags.NONE,`stat`,t)}async function lstat(e,t){return queryInfoAsync(e,W.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,t)}async function readdir(e,t){try{return M(e,t)}catch(t){throw a(t,`scandir`,e)}}async function realpath(e){return P(e)}async function symlink(e,t,n){let r=i(t),o=i(e);return new Promise((e,t)=>{let n=W.File.new_for_path(r);n.make_symbolic_link_async(o,U.PRIORITY_DEFAULT,null,(i,s)=>{try{n.make_symbolic_link_finish(s),e()}catch(e){t(a(e,`symlink`,o,r))}})})}async function rm(e,t){let n=i(e),r=W.File.new_for_path(n),o=t?.recursive||!1,s=t?.force||!1,c;try{c=r.query_file_type(W.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){if(s)return;throw a(t,`rm`,e)}if(c===W.FileType.SYMBOLIC_LINK){await new Promise((t,n)=>{r.delete_async(U.PRIORITY_DEFAULT,null,(i,o)=>{try{r.delete_finish(o),t()}catch(r){if(s){t();return}n(a(r,`rm`,e))}})});return}if(c===W.FileType.DIRECTORY){let r=await readdir(e,{withFileTypes:!0});if(!o&&r.length)throw a(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)typeof e!=`string`&&await rm(G(n,e.name),t)}await new Promise((t,n)=>{r.delete_async(U.PRIORITY_DEFAULT,null,(i,o)=>{try{r.delete_finish(o),t()}catch(r){if(s){t();return}n(a(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 q={readFile,mkdir,mkdtemp,realpath,readdir,writeFile,rmdir,unlink,open,write,rm,lstat,symlink,stat,rename,copyFile,access,appendFile,readlink,truncate,chmod,chown,link,cp:R,opendir:z,glob:B,watch:o,statfs:V,utimes:u,lutimes:l,lchown:c,lchmod:s,fstat:m,ftruncate:g,fdatasync:p,fsync:h,fchmod:d,fchown:f,futimes:_,readv:y,writev:b,openAsBlob:v,constants:H};export{access,appendFile,chmod,chown,H as constants,copyFile,R as cp,q as default,d as fchmod,f as fchown,p as fdatasync,m as fstat,h as fsync,g as ftruncate,_ as futimes,B as glob,s as lchmod,c as lchown,link,lstat,l as lutimes,mkdir,mkdtemp,open,v as openAsBlob,z as opendir,K as promises_exports,readFile,readdir,readlink,y as readv,realpath,rename,rm,rmdir,stat,V as statfs,symlink,truncate,unlink,u 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{createNodeError as a}from"./errors.js";import{watchAsync as o}from"./fs-watcher.js";import{lchmodAsync as s,lchownAsync as c,lutimesAsync as l,utimesAsync as u}from"./utimes.js";import{fchmodAsync as d,fchownAsync as f,fdatasyncAsync as p,fstatAsync as m,fsyncAsync as h,ftruncateAsync as g,futimesAsync as _,openAsBlob as v,readvAsync as y,writevAsync as b}from"./fd-ops.js";import{request as x}from"./request.js";import{STAT_ATTRIBUTES as S,statsFrom as C}from"./stats.js";import{FileHandle as w}from"./file-handle.js";import{accessSync as T,appendFileSync as E,chmodSync as D,chownSync as O,copyFileSync as k,linkSync as A,mkdirSync as j,mkdtempAt as M,readdirSync as N,readlinkSync as P,realpathSync as F,renameSync as I,truncateSync as L,writeFileSync as R}from"./sync.js";import{cpAsync as z}from"./cp.js";import{opendirAsync as B}from"./dir.js";import{globAsync as V}from"./glob.js";import{statfsAsync as H}from"./statfs.js";import{constants as U}from"./constants.js";import W from"@girs/glib-2.0";import G from"@girs/gio-2.0";import{join as K}from"node:path";var q=e({access:()=>access,appendFile:()=>appendFile,chmod:()=>chmod,chown:()=>chown,constants:()=>U,copyFile:()=>copyFile,cp:()=>z,default:()=>J,fchmod:()=>d,fchown:()=>f,fdatasync:()=>p,fstat:()=>m,fsync:()=>h,ftruncate:()=>g,futimes:()=>_,glob:()=>V,lchmod:()=>s,lchown:()=>c,link:()=>link,lstat:()=>lstat,lutimes:()=>l,mkdir:()=>mkdir,mkdtemp:()=>mkdtemp,open:()=>open,openAsBlob:()=>v,opendir:()=>B,readFile:()=>readFile,readdir:()=>readdir,readlink:()=>readlink,readv:()=>y,realpath:()=>realpath,rename:()=>rename,rm:()=>rm,rmdir:()=>rmdir,stat:()=>stat,statfs:()=>H,symlink:()=>symlink,truncate:()=>truncate,unlink:()=>unlink,utimes:()=>u,watch:()=>o,write:()=>write,writeFile:()=>writeFile,writev:()=>b});async function mkdir(e,t){return j(i(e),t)}async function readFile(e,t={encoding:null,flag:`r`}){if(e instanceof w||typeof e==`number`){let i=w.getInstance(e,`read`);return n(r(t,`buffer`),i._readToEndSync())}let o=i(e),s=G.File.new_for_path(o),c,l;try{[c,l]=await new Promise((e,t)=>{s.load_contents_async(null,x((n,r)=>{try{e(s.load_contents_finish(r))}catch(e){t(e)}}))})}catch(e){throw a(e,`open`,o)}if(!c)throw a(Error(`failed to read file`),`open`,o);return n(r(t,`buffer`),l)}async function mkdtemp(e,n){let i=r(n);return t(M(e),i)}async function writeFile(e,t,n){R(e,typeof t==`string`||t instanceof Uint8Array?t:String(t),n??null)}async function rmdir(e,t){let n=i(e),r=G.File.new_for_path(n);if((await new Promise((e,t)=>{r.query_info_async(`standard::type`,G.FileQueryInfoFlags.NONE,W.PRIORITY_DEFAULT,null,x((i,o)=>{try{e(r.query_info_finish(o))}catch(e){t(a(e,`rmdir`,n))}}))})).get_file_type()!==G.FileType.DIRECTORY)throw a(Object.assign(Error(),{code:4}),`rmdir`,n);if((await new Promise((e,t)=>{r.enumerate_children_async(`standard::name`,G.FileQueryInfoFlags.NONE,W.PRIORITY_DEFAULT,null,x((i,o)=>{try{e(r.enumerate_children_finish(o))}catch(e){t(a(e,`rmdir`,n))}}))})).next_file(null)!==null)throw a(Object.assign(Error(),{code:5}),`rmdir`,n);await new Promise((e,t)=>{r.delete_async(W.PRIORITY_DEFAULT,null,x((i,o)=>{try{r.delete_finish(o),e()}catch(e){t(a(e,`rmdir`,n))}}))})}async function unlink(e){let t=i(e),n=G.File.new_for_path(t);await new Promise((e,r)=>{n.delete_async(W.PRIORITY_DEFAULT,null,x((i,o)=>{try{n.delete_finish(o),e()}catch(e){r(a(e,`unlink`,t))}}))})}async function open(e,t,n){return new w({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 w.getInstance(e,`write`).write(t,n,r,i)).bytesWritten,buffer:t}}async function _writeStr(e,t,n,r){return{bytesWritten:(await w.getInstance(e,`write`).write(t,n,r)).bytesWritten,buffer:t}}function queryInfoAsync(e,t,n,r){let o=i(e);return new Promise((e,i)=>{let s=G.File.new_for_path(o);s.query_info_async(S,t,W.PRIORITY_DEFAULT,null,x((t,c)=>{try{e(C(s.query_info_finish(c),o,n,r?.bigint))}catch(e){i(a(e,n,o))}}))})}async function stat(e,t){return queryInfoAsync(e,G.FileQueryInfoFlags.NONE,`stat`,t)}async function lstat(e,t){return queryInfoAsync(e,G.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,t)}async function readdir(e,t){try{return N(e,t)}catch(t){throw a(t,`scandir`,e)}}async function realpath(e){return F(e)}async function symlink(e,t,n){let r=i(t),o=i(e);return new Promise((e,t)=>{let n=G.File.new_for_path(r);n.make_symbolic_link_async(o,W.PRIORITY_DEFAULT,null,x((i,s)=>{try{n.make_symbolic_link_finish(s),e()}catch(e){t(a(e,`symlink`,o,r))}}))})}async function rm(e,t){let n=i(e),r=G.File.new_for_path(n),o=t?.recursive||!1,s=t?.force||!1,c;try{c=r.query_file_type(G.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){if(s)return;throw a(t,`rm`,e)}if(c===G.FileType.SYMBOLIC_LINK){await new Promise((t,n)=>{r.delete_async(W.PRIORITY_DEFAULT,null,x((i,o)=>{try{r.delete_finish(o),t()}catch(r){if(s){t();return}n(a(r,`rm`,e))}}))});return}if(c===G.FileType.DIRECTORY){let r=await readdir(e,{withFileTypes:!0});if(!o&&r.length)throw a(Object.assign(Error(),{code:5}),`rm`,e);for(let e of r)typeof e!=`string`&&await rm(K(n,e.name),t)}await new Promise((t,n)=>{r.delete_async(W.PRIORITY_DEFAULT,null,x((i,o)=>{try{r.delete_finish(o),t()}catch(r){if(s){t();return}n(a(r,`rm`,e))}}))})}async function rename(e,t){I(e,t)}async function copyFile(e,t,n){k(e,t,n)}async function access(e,t){T(e,t)}async function appendFile(e,t,n){E(e,t,n)}async function readlink(e,t){return P(e,t)}async function truncate(e,t){L(e,t)}async function chmod(e,t){D(e,t)}async function chown(e,t,n){O(e,t,n)}async function link(e,t){A(e,t)}var J={readFile,mkdir,mkdtemp,realpath,readdir,writeFile,rmdir,unlink,open,write,rm,lstat,symlink,stat,rename,copyFile,access,appendFile,readlink,truncate,chmod,chown,link,cp:z,opendir:B,glob:V,watch:o,statfs:H,utimes:u,lutimes:l,lchown:c,lchmod:s,fstat:m,ftruncate:g,fdatasync:p,fsync:h,fchmod:d,fchown:f,futimes:_,readv:y,writev:b,openAsBlob:v,constants:U};export{access,appendFile,chmod,chown,U as constants,copyFile,z as cp,J as default,d as fchmod,f as fchown,p as fdatasync,m as fstat,h as fsync,g as ftruncate,_ as futimes,V as glob,s as lchmod,c as lchown,link,lstat,l as lutimes,mkdir,mkdtemp,open,v as openAsBlob,B as opendir,q as promises_exports,readFile,readdir,readlink,y as readv,realpath,rename,rm,rmdir,stat,H as statfs,symlink,truncate,unlink,u as utimes,o as watch,write,writeFile,b as writev};
@@ -1 +1 @@
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};
1
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{closeSync as t}from"./fd-ops.js";import{request as n}from"./request.js";import{FileHandle as r}from"./file-handle.js";import i from"@girs/glib-2.0";import a from"@girs/gio-2.0";import{Buffer as o}from"node:buffer";import{Readable as s}from"node:stream";var ReadStream=class extends s{bytesRead=0;path;pending=!0;fd=null;_ownFd=null;_autoCloseFd=!0;_positional=!1;_gioFile;_inputStream=null;_cancellable=new a.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=a.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(i.PRIORITY_DEFAULT,this._cancellable,n((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,i.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,i.timeout_add(i.PRIORITY_DEFAULT,0,()=>(this._reading=!1,this.destroyed||this._readThroughFd(e),i.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 r=this._inputStream;!r||this.destroyed||(this._reading=!0,r.read_bytes_async(t,i.PRIORITY_DEFAULT,this._cancellable,n((e,t)=>{this._reading=!1;try{let e=r.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(o.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 n=r.getInstance(this._ownFd,`read`),i=o.alloc(t),a=n._readSync(i,0,t,this._positional?this._pos:null);if(a===0){this._readAgain=!1,this.push(null);return}this.bytesRead+=a,this._pos+=a,this.push(i.subarray(0,a))}catch(e){this._readAgain=!1,this.destroy(e)}}_release(){this._inputStream&&=(this._inputStream.close_async(i.PRIORITY_DEFAULT,null,n(()=>{})),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};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{trackRequest as e,untrackRequest as t}from"@gjsify/utils/main-loop";function request(n){return e(),(...e)=>{try{n(...e)}finally{t()}}}export{request};
package/lib/esm/statfs.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{requireCallback as t}from"./errors.js";import n from"@girs/glib-2.0";import r from"@girs/gio-2.0";const i=[`filesystem::size`,`filesystem::free`].join(`,`),a=4096;function buildStatFs(e){let t=Number(e.get_attribute_uint64(`filesystem::size`)??0),n=Number(e.get_attribute_uint64(`filesystem::free`)??0),r=Math.floor(t/a),i=Math.floor(n/a);return{type:0,bsize:a,blocks:r,bfree:i,bavail:i,files:0,ffree:0}}function buildBigIntStatFs(e){let t=BigInt(e.get_attribute_uint64(`filesystem::size`)??0),n=BigInt(e.get_attribute_uint64(`filesystem::free`)??0),r=BigInt(a),i=t/r,o=n/r;return{type:0n,bsize:r,blocks:i,bfree:o,bavail:o,files:0n,ffree:0n}}function statfsSync(t,n){let a=r.File.new_for_path(e(t)).query_filesystem_info(i,null);return n?.bigint===!0?buildBigIntStatFs(a):buildStatFs(a)}function queryFsInfoAsync(t,a){return new Promise((o,s)=>{let c=r.File.new_for_path(e(t));c.query_filesystem_info_async(i,n.PRIORITY_DEFAULT,null,(e,t)=>{try{let e=c.query_filesystem_info_finish(t);o(a?buildBigIntStatFs(e):buildStatFs(e))}catch(e){s(e)}})})}function statfs(e,n,r){let i=typeof n==`function`?n:t(r);queryFsInfoAsync(e,(typeof n==`function`?{}:n)?.bigint===!0).then(e=>i(null,e),e=>i(e,null))}async function statfsAsync(e,t){return queryFsInfoAsync(e,t?.bigint===!0)}export{statfs,statfsAsync,statfsSync};
1
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{requireCallback as t}from"./errors.js";import{request as n}from"./request.js";import r from"@girs/glib-2.0";import i from"@girs/gio-2.0";const a=[`filesystem::size`,`filesystem::free`].join(`,`),o=4096;function buildStatFs(e){let t=Number(e.get_attribute_uint64(`filesystem::size`)??0),n=Number(e.get_attribute_uint64(`filesystem::free`)??0),r=Math.floor(t/o),i=Math.floor(n/o);return{type:0,bsize:o,blocks:r,bfree:i,bavail:i,files:0,ffree:0}}function buildBigIntStatFs(e){let t=BigInt(e.get_attribute_uint64(`filesystem::size`)??0),n=BigInt(e.get_attribute_uint64(`filesystem::free`)??0),r=BigInt(o),i=t/r,a=n/r;return{type:0n,bsize:r,blocks:i,bfree:a,bavail:a,files:0n,ffree:0n}}function statfsSync(t,n){let r=i.File.new_for_path(e(t)).query_filesystem_info(a,null);return n?.bigint===!0?buildBigIntStatFs(r):buildStatFs(r)}function queryFsInfoAsync(t,o){return new Promise((s,c)=>{let l=i.File.new_for_path(e(t));l.query_filesystem_info_async(a,r.PRIORITY_DEFAULT,null,n((e,t)=>{try{let e=l.query_filesystem_info_finish(t);s(o?buildBigIntStatFs(e):buildStatFs(e))}catch(e){c(e)}}))})}function statfs(e,n,r){let i=typeof n==`function`?n:t(r);queryFsInfoAsync(e,(typeof n==`function`?{}:n)?.bigint===!0).then(e=>i(null,e),e=>i(e,null))}async function statfsAsync(e,t){return queryFsInfoAsync(e,t?.bigint===!0)}export{statfs,statfsAsync,statfsSync};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Count one request now and wrap its Gio completion callback so the count
3
+ * drops after the callback has run. Pass the wrapped callback straight to the
4
+ * `*_async` call: every Gio async call completes exactly once.
5
+ */
6
+ export declare function request<A extends unknown[]>(callback: (...args: A) => void): (...args: A) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/fs",
3
- "version": "0.64.12",
3
+ "version": "0.64.13",
4
4
  "description": "Node.js fs module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -66,9 +66,9 @@
66
66
  "fs"
67
67
  ],
68
68
  "devDependencies": {
69
- "@gjsify/cli": "^0.64.12",
70
- "@gjsify/unit": "^0.64.12",
71
- "@gjsify/web-streams": "^0.64.12",
69
+ "@gjsify/cli": "^0.64.13",
70
+ "@gjsify/unit": "^0.64.13",
71
+ "@gjsify/web-streams": "^0.64.13",
72
72
  "@types/node": "^25.9.2",
73
73
  "typescript": "^6.0.3"
74
74
  },
@@ -76,11 +76,11 @@
76
76
  "@girs/gio-2.0": "5.4.0",
77
77
  "@girs/giounix-2.0": "5.4.0",
78
78
  "@girs/glib-2.0": "5.4.0",
79
- "@gjsify/buffer": "^0.64.12",
80
- "@gjsify/events": "^0.64.12",
81
- "@gjsify/stream": "^0.64.12",
82
- "@gjsify/url": "^0.64.12",
83
- "@gjsify/utils": "^0.64.12"
79
+ "@gjsify/buffer": "^0.64.13",
80
+ "@gjsify/events": "^0.64.13",
81
+ "@gjsify/stream": "^0.64.13",
82
+ "@gjsify/url": "^0.64.13",
83
+ "@gjsify/utils": "^0.64.13"
84
84
  },
85
85
  "gjsify": {
86
86
  "runtimes": {