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