@gjsify/fs 0.4.21 → 0.4.22

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/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{chmodSync as n,chownSync as r,readFileSync as i,statSync as a,truncateSync as o}from"./sync.js";import{utimesSync as s}from"./utimes.js";function getFH(e){return e instanceof t?t.getInstance(e.fd):t.getInstance(e)}function fstatSync(t,n){return a(e(getFH(t).options.path),n)}function fstat(e,t,n){typeof t==`function`&&(n=t,t={}),Promise.resolve().then(()=>fstatSync(e,t)).then(e=>n(null,e),n)}async function fstatAsync(e,t){return fstatSync(e,t)}function ftruncateSync(t,n=0){o(e(getFH(t).options.path),n)}function ftruncate(e,t,n){typeof t==`function`&&(n=t,t=0),Promise.resolve().then(()=>ftruncateSync(e,t)).then(()=>n(null),n)}async function ftruncateAsync(e,t=0){ftruncateSync(e,t)}function fdatasyncSync(e){getFH(e)._flushSync()}function fdatasync(e,t){Promise.resolve().then(()=>fdatasyncSync(e)).then(()=>t(null),t)}async function fdatasyncAsync(e){fdatasyncSync(e)}function fsyncSync(e){getFH(e)._flushSync()}function fsync(e,t){Promise.resolve().then(()=>fsyncSync(e)).then(()=>t(null),t)}async function fsyncAsync(e){fsyncSync(e)}function fchmodSync(t,r){n(e(getFH(t).options.path),r)}function fchmod(e,t,n){Promise.resolve().then(()=>fchmodSync(e,t)).then(()=>n(null),n)}async function fchmodAsync(e,t){fchmodSync(e,t)}function fchownSync(t,n,i){r(e(getFH(t).options.path),n,i)}function fchown(e,t,n,r){Promise.resolve().then(()=>fchownSync(e,t,n)).then(()=>r(null),r)}async function fchownAsync(e,t,n){fchownSync(e,t,n)}function futimesSync(t,n,r){s(e(getFH(t).options.path),n,r)}function futimes(e,t,n,r){Promise.resolve().then(()=>futimesSync(e,t,n)).then(()=>r(null),r)}async function futimesAsync(e,t,n){futimesSync(e,t,n)}function closeSync(e){getFH(e)._closeSync()}function readSync(e,t,n,r,i){let a=0;return typeof n==`object`&&n?(a=n.offset??0,r=n.length??t.byteLength,i=n.position??null):(a=n??0,r??=t.byteLength-a),getFH(e)._readSync(t,a,r,i??null)}function writeSync(e,t,n,r,i){let a;if(typeof t==`string`)a=new TextEncoder().encode(t),typeof n==`number`&&(i=n);else{let e=typeof n==`number`?n:0,i=typeof r==`number`?r:t.byteLength-e;a=new Uint8Array(t.buffer,t.byteOffset+e,i)}return getFH(e)._writeSync(a,i??null)}function readvSync(e,t,n){let r=0;for(let i of t){let t=readSync(e,i,0,i.byteLength,n==null?null:n+r);if(r+=t,t<i.byteLength)break}return r}function readv(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesRead:readvSync(e,t,n),buffers:t})).then(e=>r(null,e.bytesRead,e.buffers),r)}async function readvAsync(e,t,n){return{bytesRead:readvSync(e,t,n),buffers:t}}function writevSync(e,t,n){let r=0;for(let i of t){let t=writeSync(e,i,0,i.byteLength,n==null?null:n+r);r+=t}return r}function writev(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesWritten:writevSync(e,t,n),buffers:t})).then(e=>r(null,e.bytesWritten,e.buffers),r)}async function writevAsync(e,t,n){return{bytesWritten:writevSync(e,t,n),buffers:t}}function exists(t,n){try{a(e(t)),n(!0)}catch{n(!1)}}async function openAsBlob(t,n){let r=i(e(t));return new Blob([r],{type:n?.type??``})}export{closeSync,exists,fchmod,fchmodAsync,fchmodSync,fchown,fchownAsync,fchownSync,fdatasync,fdatasyncAsync,fdatasyncSync,fstat,fstatAsync,fstatSync,fsync,fsyncAsync,fsyncSync,ftruncate,ftruncateAsync,ftruncateSync,futimes,futimesAsync,futimesSync,openAsBlob,readSync,readv,readvAsync,readvSync,writeSync,writev,writevAsync,writevSync};
1
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{FileHandle as t}from"./file-handle.js";import{chmodSync as n,chownSync as r,readFileSync as i,statSync as a,truncateSync as o}from"./sync.js";import{utimesSync as s}from"./utimes.js";function getFH(e){return e instanceof t?t.getInstance(e.fd):t.getInstance(e)}function fstatSync(t,n){return a(e(getFH(t).options.path),n)}function fstat(e,t,n){typeof t==`function`&&(n=t,t={}),Promise.resolve().then(()=>fstatSync(e,t)).then(e=>n(null,e),n)}async function fstatAsync(e,t){return t?.bigint,fstatSync(e,t)}function ftruncateSync(t,n=0){o(e(getFH(t).options.path),n)}function ftruncate(e,t,n){typeof t==`function`&&(n=t,t=0),Promise.resolve().then(()=>ftruncateSync(e,t)).then(()=>n(null),n)}async function ftruncateAsync(e,t=0){ftruncateSync(e,t)}function fdatasyncSync(e){getFH(e)._flushSync()}function fdatasync(e,t){Promise.resolve().then(()=>fdatasyncSync(e)).then(()=>t(null),t)}async function fdatasyncAsync(e){fdatasyncSync(e)}function fsyncSync(e){getFH(e)._flushSync()}function fsync(e,t){Promise.resolve().then(()=>fsyncSync(e)).then(()=>t(null),t)}async function fsyncAsync(e){fsyncSync(e)}function fchmodSync(t,r){n(e(getFH(t).options.path),r)}function fchmod(e,t,n){Promise.resolve().then(()=>fchmodSync(e,t)).then(()=>n(null),n)}async function fchmodAsync(e,t){fchmodSync(e,t)}function fchownSync(t,n,i){r(e(getFH(t).options.path),n,i)}function fchown(e,t,n,r){Promise.resolve().then(()=>fchownSync(e,t,n)).then(()=>r(null),r)}async function fchownAsync(e,t,n){fchownSync(e,t,n)}function futimesSync(t,n,r){s(e(getFH(t).options.path),n,r)}function futimes(e,t,n,r){Promise.resolve().then(()=>futimesSync(e,t,n)).then(()=>r(null),r)}async function futimesAsync(e,t,n){futimesSync(e,t,n)}function closeSync(e){getFH(e)._closeSync()}function readSync(e,t,n,r,i){let a=0;return typeof n==`object`&&n?(a=n.offset??0,r=n.length??t.byteLength,i=n.position??null):(a=n??0,r??=t.byteLength-a),getFH(e)._readSync(t,a,r,i??null)}function writeSync(e,t,n,r,i){let a;if(typeof t==`string`)a=new TextEncoder().encode(t),typeof n==`number`&&(i=n);else{let e=typeof n==`number`?n:0,i=typeof r==`number`?r:t.byteLength-e;a=new Uint8Array(t.buffer,t.byteOffset+e,i)}return getFH(e)._writeSync(a,i??null)}function readvSync(e,t,n){let r=0;for(let i of t){let t=readSync(e,i,0,i.byteLength,n==null?null:n+r);if(r+=t,t<i.byteLength)break}return r}function readv(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesRead:readvSync(e,t,n),buffers:t})).then(e=>r(null,e.bytesRead,e.buffers),r)}async function readvAsync(e,t,n){return{bytesRead:readvSync(e,t,n),buffers:t}}function writevSync(e,t,n){let r=0;for(let i of t){let t=writeSync(e,i,0,i.byteLength,n==null?null:n+r);r+=t}return r}function writev(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesWritten:writevSync(e,t,n),buffers:t})).then(e=>r(null,e.bytesWritten,e.buffers),r)}async function writevAsync(e,t,n){return{bytesWritten:writevSync(e,t,n),buffers:t}}function exists(t,n){try{a(e(t)),n(!0)}catch{n(!1)}}async function openAsBlob(t,n){let r=i(e(t));return new Blob([r],{type:n?.type??``})}export{closeSync,exists,fchmod,fchmodAsync,fchmodSync,fchown,fchownAsync,fchownSync,fdatasync,fdatasyncAsync,fdatasyncSync,fstat,fstatAsync,fstatSync,fsync,fsyncAsync,fsyncSync,ftruncate,ftruncateAsync,ftruncateSync,futimes,futimesAsync,futimesSync,openAsBlob,readSync,readv,readvAsync,readvSync,writeSync,writev,writevAsync,writevSync};
@@ -0,0 +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 +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{chmodSync as c,chownSync as l}from"./sync.js";import u from"@girs/glib-2.0";import d from"@girs/gio-2.0";import{Buffer as f}from"node:buffer";import{createGLibFileError as p}from"@gjsify/utils";import{createInterface as m}from"node:readline";function resolveIOMode(e){if(e==null)return`r`;if(typeof e==`number`){let t=(e&2)!=0,n=(e&1)!=0,r=(e&1024)!=0,i=(e&512)!=0;return t?i?`w+`:`r+`:n?r?`a`:`w`:`r`}switch(e){case`ax`:case`wx`:return`w`;case`ax+`:case`wx+`:return`w+`;case`as`:case`rs+`:return`r+`;case`as+`:return`a+`;default:return e}}function openIOChannel(e,t,n){try{return u.IOChannel.new_file(e,t)}catch(r){if(n&&t===`r+`&&r?.code===u.FileError.NOENT)return u.file_set_contents(e,new Uint8Array),u.IOChannel.new_file(e,t);throw r}}function mapOpenError(e,t){return p(e,`open`,{path:t})}var h=class FileHandle{options;_file;_ioStream=null;_readStream=null;_gFile;_ioMode;_ioLock=Promise.resolve();static instances={};constructor(e){this.options=e,this.options.flags||=`r`,this.options.mode||=438;let t=n(e.path),r=typeof e.flags==`number`&&(e.flags&64)!=0,i=resolveIOMode(e.flags);try{this._file=openIOChannel(t,i,r)}catch(e){throw mapOpenError(e,t)}return this._file.set_encoding(null),this.fd=this._file.unix_get_fd(),this._gFile=d.File.new_for_path(t),this._ioMode=i,FileHandle.instances[this.fd]=this,FileHandle.getInstance(this.fd)}_getReadStream(){return this._ioStream?{input:this._ioStream.get_input_stream(),seekable:this._ioStream}:this._ioMode===`r`?(this._readStream||=this._gFile.read(null),{input:this._readStream,seekable:this._readStream}):(this._ioStream=this._gFile.open_readwrite(null),{input:this._ioStream.get_input_stream(),seekable:this._ioStream})}_getWriteStream(){if(this._ioStream)return this._ioStream;if(this._ioMode===`r`)throw Error(`FileHandle opened read-only; cannot write`);return this._ioStream=this._gFile.open_readwrite(null),this._ioStream}_serialize(e){let t=this._ioLock.catch(()=>{}).then(e);return this._ioLock=t,t}fd;static getInstance(e){if(!FileHandle.instances[e])throw Error(`No instance found for fd!`);return FileHandle.instances[e]}async appendFile(e,n){let r=t(n);typeof e==`string`&&(e=f.from(e)),r&&this._file.set_encoding(r);let[i,a]=this._file.write_chars(e,e.length);if(i===u.IOStatus.ERROR)throw Error(`Error on append to file!`)}async chown(e,t){l(n(this.options.path),e,t)}async chmod(e){c(n(this.options.path),e)}createReadStream(e){return new r(this.options.path,e)}createWriteStream(e){return new i(this.options.path,e)}async datasync(){this._file.flush()}async sync(){this._file.flush()}async read(...e){let t,n,r,i;if(typeof e[0]==`object`&&!(e[0]instanceof Uint8Array)&&!(e[0]instanceof f)){let a=e[0];t=a.buffer,n=a.offset,r=a.length,i=a.position}else t=e[0],n=e[1],r=e[2],i=e[3];let a=t,o=n??0,s=r??a?.byteLength??65536,c=i??0;return this._serialize(async()=>{let{input:e,seekable:n}=this._getReadStream();n.seek(BigInt(c),u.SeekType.SET,null);let r=e.read_bytes(s,null).get_data(),i=r?.length??0;return a&&r&&i>0&&a.set(r,o),{bytesRead:i,buffer:t}})}readableWebStream(){let e=globalThis.ReadableStream;if(typeof e!=`function`)throw Error(`readableWebStream() requires a global ReadableStream. Import "node:stream/web" or "@gjsify/streams" before calling this method.`);return new e}async readFile(n){let r=t(n,`buffer`);r&&this._file.set_encoding(r);let[i,a]=this._file.read_to_end();if(i===u.IOStatus.ERROR)throw Error(`Error on read from file!`);return e(r,a)}readLines(e){return m({input:this.createReadStream(e),crlfDelay:1/0})}async stat(e){let t=await new Promise((e,t)=>{this._gFile.query_info_async(o,d.FileQueryInfoFlags.NONE,u.PRIORITY_DEFAULT,null,(n,r)=>{try{e(this._gFile.query_info_finish(r))}catch(e){t(e)}})}),r=n(this.options.path);return e?.bigint?new a(t,r):new s(t,r)}async truncate(e=0){let t=Math.max(0,e);this._file.flush(),this._getWriteStream().get_output_stream().truncate(t,null)}async utimes(e,t){let{utimesSync:r}=await import(`./utimes.js`);r(n(this.options.path),e,t)}async writeFile(e,n){let r=t(n),i;i=typeof e==`string`?f.from(e,r||`utf8`):e,this._file.seek_position(0,u.SeekType.SET);let[a]=this._file.write_chars(i,i.length);if(a===u.IOStatus.ERROR)throw Error(`Error writing to file!`);this._file.flush()}async write(e,...n){let r=null,i=null,a=null,o=null;typeof e==`string`?(r=n[0],i=n[1]):(a=n[0],o=n[1],r=n[2]),i=t(i,typeof e==`string`?`utf8`:null);let s;s=typeof e==`string`?new TextEncoder().encode(e):e;let c=a??0,l=o??s.byteLength-c,d=s.slice(c,c+l),f=r??0;return{bytesWritten:await this._serialize(async()=>{let e=this._getWriteStream();e.seek(BigInt(f),u.SeekType.SET,null);let t=e.get_output_stream(),n=await new Promise((e,n)=>{t.write_bytes_async(new u.Bytes(d),u.PRIORITY_DEFAULT,null,(r,i)=>{try{e(t.write_bytes_finish(i))}catch(e){n(e)}})});return await new Promise((e,n)=>{t.flush_async(u.PRIORITY_DEFAULT,null,(r,i)=>{try{t.flush_finish(i),e()}catch(e){n(e)}})}),n}),buffer:e}}async writev(e,t){let n=0;for(let r of e){let e=f.from(r.buffer,r.byteOffset,r.byteLength),i=await this.write(e,0,e.byteLength,t==null?null:t+n);n+=i.bytesWritten}return{bytesWritten:n,buffers:e}}async readv(e,t){let n=0;for(let r of e){let e=await this.read({buffer:f.from(r.buffer,r.byteOffset,r.byteLength),position:t==null?null:t+n});if(n+=e.bytesRead,e.bytesRead<r.byteLength)break}return{bytesRead:n,buffers:e}}_flushSync(){this._file.flush()}_closeSync(){try{this._ioStream?.close(null)}catch{}try{this._readStream?.close(null)}catch{}this._ioStream=null,this._readStream=null;try{this._file.shutdown(!0)}catch{}delete FileHandle.instances[this.fd]}_readSync(e,t,n,r){let i=this._gFile.read(null);try{r!==null&&r>=0&&i.seek(r,u.SeekType.SET,null);let a=i.read_bytes(n,null).get_data();return new Uint8Array(e.buffer,e.byteOffset+t).set(a.subarray(0,a.length)),a.length}finally{i.close(null)}}_writeSync(e,t){let n=this._gFile.open_readwrite(null);try{return t!==null&&t>=0&&n.seek(t,u.SeekType.SET,null),n.get_output_stream().write_bytes(u.Bytes.new(e),null)}finally{n.close(null)}}async close(){try{this._ioStream?.close(null)}catch{}try{this._readStream?.close(null)}catch{}this._ioStream=null,this._readStream=null;try{this._file.shutdown(!0)}catch{}}async[Symbol.asyncDispose](){await this.close()}};export{h as FileHandle};
1
+ 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;_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{}delete FileHandle.instances[this.fd]}_readSync(e,t,n,r){let i=this._gFile.read(null);try{r!==null&&r>=0&&i.seek(r,m.SeekType.SET,null);let a=i.read_bytes(n,null).get_data();return new Uint8Array(e.buffer,e.byteOffset+t).set(a.subarray(0,a.length)),a.length}finally{i.close(null)}}_writeSync(e,t){let n=this._gFile.open_readwrite(null);try{return t!==null&&t>=0&&n.seek(t,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};
@@ -0,0 +1,25 @@
1
+ import GLib from '@girs/glib-2.0';
2
+ import type { OpenFlags } from './types/index.js';
3
+ /** fopen(3)-style IOChannel mode. */
4
+ export type IOMode = 'r' | 'r+' | 'w' | 'w+' | 'a' | 'a+';
5
+ /**
6
+ * Convert open flags (Node.js string or POSIX numeric) to a GLib.IOChannel mode.
7
+ * IOChannel.new_file() takes fopen(3) modes: 'r', 'r+', 'w', 'w+', 'a', 'a+'.
8
+ */
9
+ export declare function resolveIOMode(flags: OpenFlags | number | undefined): IOMode;
10
+ /** Whether the open flags include `O_CREAT` (create-if-missing semantics). */
11
+ export declare function shouldCreate(flags: OpenFlags | number | undefined): boolean;
12
+ /**
13
+ * Open the file with the given IOChannel mode. When the flags request
14
+ * create-if-missing + read/write without truncation (numeric O_CREAT | O_RDWR,
15
+ * which maps to IOChannel 'r+' — a mode that requires the file to exist), we
16
+ * catch the ENOENT and create an empty file, then retry. This avoids a TOCTOU
17
+ * existence check and keeps the common "file exists" path to a single syscall.
18
+ */
19
+ export declare function openIOChannel(path: string, mode: IOMode, creat: boolean): GLib.IOChannel;
20
+ /**
21
+ * Wrap a `GLib.IOChannel.new_file()` failure as a Node `ErrnoException`.
22
+ * GLib's IOChannel throws GLib.FileError (not Gio.IOErrorEnum) on this path,
23
+ * so we route through `createGLibFileError` to get the right errno + code.
24
+ */
25
+ export declare function mapOpenError(err: unknown, path: string): NodeJS.ErrnoException;
@@ -394,4 +394,24 @@ export declare class FileHandle implements IFileHandle {
394
394
  */
395
395
  close(): Promise<void>;
396
396
  [Symbol.asyncDispose](): Promise<void>;
397
+ /**
398
+ * `node:stream/iter` pull-mode reader. Added in Node 25.9 — wires the
399
+ * file handle into the new stream-iter pipeline so callers can do
400
+ * `await pipeTo(fh.pull({ autoClose: true }), w)` instead of the
401
+ * older `createReadStream()` pattern.
402
+ *
403
+ * Not implemented yet — `@gjsify/stream` doesn't ship the iter
404
+ * helpers ({@link https://nodejs.org/api/stream_iter.html}). The
405
+ * stub keeps the @types/node FileHandle interface satisfied so
406
+ * downstream typecheck passes; calling at runtime throws a clear
407
+ * "not yet" error. Tracked in STATUS.md "Open TODOs → Node 25
408
+ * stream/iter integration".
409
+ */
410
+ pull(..._args: any[]): any;
411
+ /**
412
+ * `node:stream/iter` writer. Counterpart to {@link pull} — added in
413
+ * Node 25.9 alongside the new pipeline shape. Same not-implemented
414
+ * stub for the same reason. See {@link pull} for context.
415
+ */
416
+ writer(_options?: any): any;
397
417
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/fs",
3
- "version": "0.4.21",
3
+ "version": "0.4.22",
4
4
  "description": "Node.js fs module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -37,18 +37,18 @@
37
37
  "fs"
38
38
  ],
39
39
  "devDependencies": {
40
- "@gjsify/cli": "^0.4.21",
41
- "@gjsify/unit": "^0.4.21",
42
- "@types/node": "^25.6.2",
40
+ "@gjsify/cli": "^0.4.22",
41
+ "@gjsify/unit": "^0.4.22",
42
+ "@types/node": "^25.9.1",
43
43
  "typescript": "^6.0.3"
44
44
  },
45
45
  "dependencies": {
46
- "@girs/gio-2.0": "2.88.0-4.0.0-rc.15",
47
- "@girs/glib-2.0": "2.88.0-4.0.0-rc.15",
48
- "@gjsify/buffer": "^0.4.21",
49
- "@gjsify/events": "^0.4.21",
50
- "@gjsify/stream": "^0.4.21",
51
- "@gjsify/url": "^0.4.21",
52
- "@gjsify/utils": "^0.4.21"
46
+ "@girs/gio-2.0": "2.88.0-4.0.1",
47
+ "@girs/glib-2.0": "2.88.0-4.0.1",
48
+ "@gjsify/buffer": "^0.4.22",
49
+ "@gjsify/events": "^0.4.22",
50
+ "@gjsify/stream": "^0.4.22",
51
+ "@gjsify/url": "^0.4.22",
52
+ "@gjsify/utils": "^0.4.22"
53
53
  }
54
54
  }