@gjsify/fs 0.22.0 → 0.24.1
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.
- package/lib/esm/callback.js +1 -1
- package/lib/esm/dir.js +1 -1
- package/lib/esm/errors.js +1 -1
- package/lib/esm/file-handle-open.js +1 -1
- package/lib/esm/file-handle.js +1 -1
- package/lib/types/errors.d.ts +1 -1
- package/package.json +8 -8
package/lib/esm/callback.js
CHANGED
|
@@ -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,mkdirSync as d,readFileSync as f,readdirSync as p,readlinkSync as m,realpathSync as h,renameSync as g,rmdirSync as _,truncateSync as v,writeFileSync as y}from"./sync.js";import{open as b,rm as x}from"./promises.js";import S from"@girs/glib-2.0";import C from"@girs/gio-2.0";import{Buffer as w}from"node:buffer";function parseOptsCb(e,t){return typeof e==`function`?{options:{},callback:e}:{options:e??{},callback:t}}function statImpl(i,o,s,c,l){let u=e(i),d=C.File.new_for_path(u);d.query_info_async(n,o,S.PRIORITY_DEFAULT,null,(e,n)=>{try{let e=d.query_info_finish(n);l(null,c?.bigint?new t(e,u):new r(e,u))}catch(e){l(a(e,s,u))}})}function stat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,C.FileQueryInfoFlags.NONE,`stat`,r,i)}function lstat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,C.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,r,i)}function readdir(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{i(null,p(e,r))}catch(t){i(a(t,`readdir`,e))}})}function realpath(e,t,n){let{callback:r}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{r(null,h(e))}catch(e){r(e)}})}function symlink(t,n,r,i){let o=typeof r==`function`?r:i;if(typeof o!=`function`)throw TypeError(`Callback must be a function. Received `+typeof o);let s=e(n),c=e(t),l=C.File.new_for_path(s);l.make_symbolic_link_async(c,S.PRIORITY_DEFAULT,null,(e,t)=>{try{l.make_symbolic_link_finish(t),o(null)}catch(e){o(a(e,`symlink`,c,s))}})}function open(e,...t){let n,r,i;switch(t.length){case 1:i=t[0];break;case 2:n=t[0],i=t[1];break;case 3:n=t[0],r=t[1],i=t[2];break;default:break}b(e,n,r).then(e=>{i(null,e.fd)}).catch(e=>{i(e,-1)})}function write(e,t,...n){let r=i.getInstance(e);if(typeof t==`string`){let e=n.pop(),i=n[0],a=n[1];r.write(t,i,a).then(t=>{e(null,t.bytesWritten,t.buffer)}).catch(t=>{e(t,0,``)});return}let a=n[n.length-1],o=n[0],s=n[1],c=n[2];r.write(t,o,s,c).then(e=>{a(null,e.bytesWritten,e.buffer)}).catch(e=>{a(e,0,w.from([]))})}function read(e,...t){let n=i.getInstance(e),r=t[t.length-1],a,o,s,c;if(!(t.length<=1))if(typeof t[0]==`object`&&!ArrayBuffer.isView(t[0])){let e=t[0];a=e.buffer,o=e.offset,s=e.length,c=e.position}else a=t[0],o=t[1],s=t[2],c=t[3];n.read(a,o,s,c).then(e=>{r(null,e.bytesRead,e.buffer)}).catch(e=>{r(e,0,w.from([]))})}function close(e,t){i.getInstance(e).close().then(()=>{t(null)}).catch(e=>t(e))}function rm(e,...t){let n={},r=t[t.length-1];t.length>=2&&(n=t[0]),x(e,n).then(()=>{r(null)}).catch(e=>{r(e)})}function rename(e,t,n){Promise.resolve().then(()=>{try{g(e,t),n(null)}catch(e){n(e)}})}function copyFile(e,t,n,r){let i=typeof n==`function`?0:n,a=typeof n==`function`?n:r;Promise.resolve().then(()=>{try{u(e,t,i),a(null)}catch(e){a(e)}})}function access(e,t,n){let r=typeof t==`function`?void 0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{o(e,r),i(null)}catch(e){i(e)}})}function appendFile(e,t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n;Promise.resolve().then(()=>{try{s(e,t,a),i(null)}catch(e){i(e)}})}function readlink(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{r(null,m(e,i))}catch(e){r(e,``)}})}function truncate(e,t,n){let r=typeof t==`function`?0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{v(e,r),i(null)}catch(e){i(e)}})}function chmod(e,t,n){Promise.resolve().then(()=>{try{c(e,t),n(null)}catch(e){n(e)}})}function chown(e,t,n,r){Promise.resolve().then(()=>{try{l(e,t,n),r(null)}catch(e){r(e)}})}function mkdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{d(e,i),r(null)}catch(e){r(e)}})}function rmdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{_(e,i),r(null)}catch(e){r(e)}})}function readFile(t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n,o=e(t);Promise.resolve().then(()=>{try{
|
|
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,mkdirSync as d,readFileSync as f,readdirSync as p,readlinkSync as m,realpathSync as h,renameSync as g,rmdirSync as _,truncateSync as v,writeFileSync as y}from"./sync.js";import{open as b,rm as x}from"./promises.js";import S from"@girs/glib-2.0";import C from"@girs/gio-2.0";import{Buffer as w}from"node:buffer";function parseOptsCb(e,t){return typeof e==`function`?{options:{},callback:e}:{options:e??{},callback:t}}function statImpl(i,o,s,c,l){let u=e(i),d=C.File.new_for_path(u);d.query_info_async(n,o,S.PRIORITY_DEFAULT,null,(e,n)=>{try{let e=d.query_info_finish(n);l(null,c?.bigint?new t(e,u):new r(e,u))}catch(e){l(a(e,s,u))}})}function stat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,C.FileQueryInfoFlags.NONE,`stat`,r,i)}function lstat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,C.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,r,i)}function readdir(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{i(null,p(e,r))}catch(t){i(a(t,`readdir`,e))}})}function realpath(e,t,n){let{callback:r}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{r(null,h(e))}catch(e){r(e)}})}function symlink(t,n,r,i){let o=typeof r==`function`?r:i;if(typeof o!=`function`)throw TypeError(`Callback must be a function. Received `+typeof o);let s=e(n),c=e(t),l=C.File.new_for_path(s);l.make_symbolic_link_async(c,S.PRIORITY_DEFAULT,null,(e,t)=>{try{l.make_symbolic_link_finish(t),o(null)}catch(e){o(a(e,`symlink`,c,s))}})}function open(e,...t){let n,r,i;switch(t.length){case 1:i=t[0];break;case 2:n=t[0],i=t[1];break;case 3:n=t[0],r=t[1],i=t[2];break;default:break}b(e,n,r).then(e=>{i(null,e.fd)}).catch(e=>{i(e,-1)})}function write(e,t,...n){let r=i.getInstance(e);if(typeof t==`string`){let e=n.pop(),i=n[0],a=n[1];r.write(t,i,a).then(t=>{e(null,t.bytesWritten,t.buffer)}).catch(t=>{e(t,0,``)});return}let a=n[n.length-1],o=n[0],s=n[1],c=n[2];r.write(t,o,s,c).then(e=>{a(null,e.bytesWritten,e.buffer)}).catch(e=>{a(e,0,w.from([]))})}function read(e,...t){let n=i.getInstance(e),r=t[t.length-1],a,o,s,c;if(!(t.length<=1))if(typeof t[0]==`object`&&!ArrayBuffer.isView(t[0])){let e=t[0];a=e.buffer,o=e.offset,s=e.length,c=e.position}else a=t[0],o=t[1],s=t[2],c=t[3];n.read(a,o,s,c).then(e=>{r(null,e.bytesRead,e.buffer)}).catch(e=>{r(e,0,w.from([]))})}function close(e,t){i.getInstance(e).close().then(()=>{t(null)}).catch(e=>t(e))}function rm(e,...t){let n={},r=t[t.length-1];t.length>=2&&(n=t[0]),x(e,n).then(()=>{r(null)}).catch(e=>{r(e)})}function rename(e,t,n){Promise.resolve().then(()=>{try{g(e,t),n(null)}catch(e){n(e)}})}function copyFile(e,t,n,r){let i=typeof n==`function`?0:n,a=typeof n==`function`?n:r;Promise.resolve().then(()=>{try{u(e,t,i),a(null)}catch(e){a(e)}})}function access(e,t,n){let r=typeof t==`function`?void 0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{o(e,r),i(null)}catch(e){i(e)}})}function appendFile(e,t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n;Promise.resolve().then(()=>{try{s(e,t,a),i(null)}catch(e){i(e)}})}function readlink(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{r(null,m(e,i))}catch(e){r(e,``)}})}function truncate(e,t,n){let r=typeof t==`function`?0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{v(e,r),i(null)}catch(e){i(e)}})}function chmod(e,t,n){Promise.resolve().then(()=>{try{c(e,t),n(null)}catch(e){n(e)}})}function chown(e,t,n,r){Promise.resolve().then(()=>{try{l(e,t,n),r(null)}catch(e){r(e)}})}function mkdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{d(e,i),r(null)}catch(e){r(e)}})}function rmdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{_(e,i),r(null)}catch(e){r(e)}})}function readFile(t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n,o=e(t);Promise.resolve().then(()=>{try{let e=typeof a==`string`?{encoding:a,flag:`r`}:{encoding:a?.encoding??null,flag:a?.flag??`r`};i(null,f(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{y(o,n),a(null)}catch(e){a(e)}})}function link(t,n,r){let i=e(t),a=e(n);Promise.resolve().then(()=>{try{if(!S.spawn_command_line_sync(`ln ${i} ${a}`)[0])throw Object.assign(Error(`EPERM: operation not permitted, link '${i}' -> '${a}'`),{code:`EPERM`,errno:-1,syscall:`link`,path:i,dest:a});r(null)}catch(e){r(e)}})}function unlink(t,n){let r=e(t);Promise.resolve().then(()=>{try{S.unlink(r),n(null)}catch(e){n(e)}})}export{access,appendFile,chmod,chown,close,copyFile,link,lstat,mkdir,open,read,readFile,readdir,readlink,realpath,rename,rm,rmdir,stat,symlink,truncate,unlink,write,writeFile};
|
package/lib/esm/dir.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{Dirent as t}from"./dirent.js";import{createNodeError as n}from"./errors.js";import r from"@girs/glib-2.0";import i from"@girs/gio-2.0";const a=`standard::name,standard::type,standard::is-symlink,standard::size,standard::symlink-target,unix::uid,unix::gid,unix::mode,time::modified,time::access,time::created`;var Dir=class{path;_enumerator;_closed=!1;constructor(e,t){this.path=e,this._enumerator=t}_assertOpen(){if(this._closed){let e=Error(`Directory handle was closed`);throw e.code=`ERR_DIR_CLOSED`,e}}readSync(){this._assertOpen();try{let e=this._enumerator.next_file(null);if(e===null)return null;let n=e.get_name(),r=e.get_file_type();return new t(this.path.endsWith(`/`)?this.path+n:this.path+`/`+n,n,r)}catch(e){throw n(e,`readdir`,this.path)}}read(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this._assertOpen();let t=this.readSync();Promise.resolve().then(()=>e(null,t))}catch(t){Promise.resolve().then(()=>e(t,null))}return}return new Promise((e,t)=>{try{this._assertOpen(),e(this.readSync())}catch(e){t(e)}})}closeSync(){this._assertOpen(),this._closed=!0;try{this._enumerator.close(null)}catch{}this._enumerator=null}close(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this.closeSync(),Promise.resolve().then(()=>e(null))}catch(t){Promise.resolve().then(()=>e(t))}return}return new Promise((e,t)=>{try{this.closeSync(),e()}catch(e){t(e)}})}async*[Symbol.asyncIterator](){try{for(;;){let e=await this.read();if(e===null)break;yield e}}finally{this._closed||await this.close()}}};function _openDir(e){let t=i.File.new_for_path(e),r;try{r=t.enumerate_children(a,i.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){throw n(t,`opendir`,e)}return new Dir(e,r)}function opendirSync(t){return _openDir(e(t))}function opendir(e,t,n){let r;if(r=typeof t==`function`?t:n,typeof r!=`function`)throw TypeError(`The "callback" argument must be of type function`);Promise.resolve().then(()=>{try{let t=opendirSync(e);r(null,t)}catch(e){r(e,null)}})}async function opendirAsync(t,o){return new Promise((o,s)=>{let c=e(t),l=i.File.new_for_path(c);l.enumerate_children_async(a,i.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,r.PRIORITY_DEFAULT,null,(e,t)=>{try{o(new Dir(c,
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{Dirent as t}from"./dirent.js";import{createNodeError as n}from"./errors.js";import r from"@girs/glib-2.0";import i from"@girs/gio-2.0";const a=`standard::name,standard::type,standard::is-symlink,standard::size,standard::symlink-target,unix::uid,unix::gid,unix::mode,time::modified,time::access,time::created`;var Dir=class{path;_enumerator;_closed=!1;constructor(e,t){this.path=e,this._enumerator=t}_assertOpen(){if(this._closed){let e=Error(`Directory handle was closed`);throw e.code=`ERR_DIR_CLOSED`,e}}readSync(){this._assertOpen();try{let e=this._enumerator.next_file(null);if(e===null)return null;let n=e.get_name(),r=e.get_file_type();return new t(this.path.endsWith(`/`)?this.path+n:this.path+`/`+n,n,r)}catch(e){throw n(e,`readdir`,this.path)}}read(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this._assertOpen();let t=this.readSync();Promise.resolve().then(()=>e(null,t))}catch(t){Promise.resolve().then(()=>e(t,null))}return}return new Promise((e,t)=>{try{this._assertOpen(),e(this.readSync())}catch(e){t(e)}})}closeSync(){this._assertOpen(),this._closed=!0;try{this._enumerator.close(null)}catch{}this._enumerator=null}close(e){if(e!==void 0){if(typeof e!=`function`)throw TypeError(`The "callback" argument must be of type function`);try{this.closeSync(),Promise.resolve().then(()=>e(null))}catch(t){Promise.resolve().then(()=>e(t))}return}return new Promise((e,t)=>{try{this.closeSync(),e()}catch(e){t(e)}})}async*[Symbol.asyncIterator](){try{for(;;){let e=await this.read();if(e===null)break;yield e}}finally{this._closed||await this.close()}}};function _openDir(e){let t=i.File.new_for_path(e),r;try{r=t.enumerate_children(a,i.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){throw n(t,`opendir`,e)}return new Dir(e,r)}function opendirSync(t){return _openDir(e(t))}function opendir(e,t,n){let r;if(r=typeof t==`function`?t:n,typeof r!=`function`)throw TypeError(`The "callback" argument must be of type function`);Promise.resolve().then(()=>{try{let t=opendirSync(e);r(null,t)}catch(e){r(e,null)}})}async function opendirAsync(t,o){return new Promise((o,s)=>{let c=e(t),l=i.File.new_for_path(c);l.enumerate_children_async(a,i.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,r.PRIORITY_DEFAULT,null,(e,t)=>{try{let e=l.enumerate_children_finish(t);o(new Dir(c,e))}catch(e){s(n(e,`opendir`,c))}})})}export{Dir,opendir,opendirAsync,opendirSync};
|
package/lib/esm/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{createNodeError as e,isNotFoundError as t}from"@gjsify/utils";function createNodeError(t,n,r,i){return e(t,n,{path:r.toString(),dest:i?.toString()})}export{createNodeError,t as isNotFoundError};
|
|
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 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";import{createGLibFileError as t}from"@gjsify/utils";function resolveIOMode(e){if(e==null)return`r`;if(typeof e==`number`){let t=(e&2)!=0,n=(e&1)!=0,r=(e&1024)!=0,i=(e&512)!=0;return t?i?`w+`:`r+`:n?r?`a`:`w`:`r`}switch(e){case`ax`:case`wx`:return`w`;case`ax+`:case`wx+`:return`w+`;case`as`:case`rs+`:return`r+`;case`as+`:return`a+`;default:return e}}function shouldCreate(e){return typeof e==`number`?(e&64)!=0:typeof e==`string`?e===`w`||e===`w+`||e===`wx`||e===`wx+`||e===`a`||e===`a+`||e===`ax`||e===`ax+`||e===`as`||e===`as+`:!1}function openIOChannel(t,n,r){try{return e.IOChannel.new_file(t,n)}catch(i){if(r&&n===`r+`&&i?.code===e.FileError.NOENT)return e.file_set_contents(t,new Uint8Array),e.IOChannel.new_file(t,n);throw i}}function mapOpenError(e,n){return t(e,`open`,{path:n})}export{mapOpenError,openIOChannel,resolveIOMode,shouldCreate};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import e from"@girs/glib-2.0";import{createGLibFileError as t}from"@gjsify/utils/core";function resolveIOMode(e){if(e==null)return`r`;if(typeof e==`number`){let t=(e&2)!=0,n=(e&1)!=0,r=(e&1024)!=0,i=(e&512)!=0;return t?i?`w+`:`r+`:n?r?`a`:`w`:`r`}switch(e){case`ax`:case`wx`:return`w`;case`ax+`:case`wx+`:return`w+`;case`as`:case`rs+`:return`r+`;case`as+`:return`a+`;default:return e}}function shouldCreate(e){return typeof e==`number`?(e&64)!=0:typeof e==`string`?e===`w`||e===`w+`||e===`wx`||e===`wx+`||e===`a`||e===`a+`||e===`ax`||e===`ax+`||e===`as`||e===`as+`:!1}function openIOChannel(t,n,r){try{return e.IOChannel.new_file(t,n)}catch(i){if(r&&n===`r+`&&i?.code===e.FileError.NOENT)return e.file_set_contents(t,new Uint8Array),e.IOChannel.new_file(t,n);throw i}}function mapOpenError(e,n){return t(e,`open`,{path:n})}export{mapOpenError,openIOChannel,resolveIOMode,shouldCreate};
|
package/lib/esm/file-handle.js
CHANGED
|
@@ -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{_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{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};
|
package/lib/types/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PathLike } from 'node:fs';
|
|
2
|
-
import { isNotFoundError } from '@gjsify/utils';
|
|
2
|
+
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.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/fs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1",
|
|
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,19 +66,19 @@
|
|
|
66
66
|
"fs"
|
|
67
67
|
],
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@gjsify/cli": "^0.
|
|
70
|
-
"@gjsify/unit": "^0.
|
|
69
|
+
"@gjsify/cli": "^0.24.1",
|
|
70
|
+
"@gjsify/unit": "^0.24.1",
|
|
71
71
|
"@types/node": "^25.9.2",
|
|
72
72
|
"typescript": "^6.0.3"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@girs/gio-2.0": "^4.1.0",
|
|
76
76
|
"@girs/glib-2.0": "^4.1.0",
|
|
77
|
-
"@gjsify/buffer": "^0.
|
|
78
|
-
"@gjsify/events": "^0.
|
|
79
|
-
"@gjsify/stream": "^0.
|
|
80
|
-
"@gjsify/url": "^0.
|
|
81
|
-
"@gjsify/utils": "^0.
|
|
77
|
+
"@gjsify/buffer": "^0.24.1",
|
|
78
|
+
"@gjsify/events": "^0.24.1",
|
|
79
|
+
"@gjsify/stream": "^0.24.1",
|
|
80
|
+
"@gjsify/url": "^0.24.1",
|
|
81
|
+
"@gjsify/utils": "^0.24.1"
|
|
82
82
|
},
|
|
83
83
|
"gjsify": {
|
|
84
84
|
"runtimes": {
|