@gjsify/fs 0.25.1 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/esm/callback.js +1 -1
- package/lib/esm/fs-watcher.js +1 -1
- package/lib/esm/sync.js +1 -1
- package/lib/esm/utimes.js +1 -1
- package/lib/types/file-handle.d.ts +1 -1
- package/package.json +8 -8
package/lib/esm/callback.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{BigIntStats as t,STAT_ATTRIBUTES as n,Stats as r}from"./stats.js";import{FileHandle as i}from"./file-handle.js";import{createNodeError as a}from"./errors.js";import{accessSync as o,appendFileSync as s,chmodSync as c,chownSync as l,copyFileSync as u,
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{BigIntStats as t,STAT_ATTRIBUTES as n,Stats as r}from"./stats.js";import{FileHandle as i}from"./file-handle.js";import{createNodeError as a}from"./errors.js";import{accessSync as o,appendFileSync as s,chmodSync as c,chownSync as l,copyFileSync as u,linkSync as d,mkdirSync as f,readFileSync as p,readdirSync as m,readlinkSync as h,realpathSync as g,renameSync as _,rmdirSync as v,truncateSync as y,writeFileSync as b}from"./sync.js";import{open as x,rm as S}from"./promises.js";import C from"@girs/glib-2.0";import w from"@girs/gio-2.0";import{Buffer as T}from"node:buffer";function parseOptsCb(e,t){return typeof e==`function`?{options:{},callback:e}:{options:e??{},callback:t}}function statImpl(i,o,s,c,l){let u=e(i),d=w.File.new_for_path(u);d.query_info_async(n,o,C.PRIORITY_DEFAULT,null,(e,n)=>{try{let e=d.query_info_finish(n);l(null,c?.bigint?new t(e,u):new r(e,u))}catch(e){l(a(e,s,u))}})}function stat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,w.FileQueryInfoFlags.NONE,`stat`,r,i)}function lstat(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);statImpl(e,w.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,`lstat`,r,i)}function readdir(e,t,n){let{options:r,callback:i}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{i(null,m(e,r))}catch(t){i(a(t,`readdir`,e))}})}function realpath(e,t,n){let{callback:r}=parseOptsCb(t,n);Promise.resolve().then(()=>{try{r(null,g(e))}catch(e){r(e)}})}function symlink(t,n,r,i){let o=typeof r==`function`?r:i;if(typeof o!=`function`)throw TypeError(`Callback must be a function. Received `+typeof o);let s=e(n),c=e(t),l=w.File.new_for_path(s);l.make_symbolic_link_async(c,C.PRIORITY_DEFAULT,null,(e,t)=>{try{l.make_symbolic_link_finish(t),o(null)}catch(e){o(a(e,`symlink`,c,s))}})}function open(e,...t){let n,r,i;switch(t.length){case 1:i=t[0];break;case 2:n=t[0],i=t[1];break;case 3:n=t[0],r=t[1],i=t[2];break;default:break}x(e,n,r).then(e=>{i(null,e.fd)}).catch(e=>{i(e,-1)})}function write(e,t,...n){let r=i.getInstance(e);if(typeof t==`string`){let e=n.pop(),i=n[0],a=n[1];r.write(t,i,a).then(t=>{e(null,t.bytesWritten,t.buffer)}).catch(t=>{e(t,0,``)});return}let a=n[n.length-1],o=n[0],s=n[1],c=n[2];r.write(t,o,s,c).then(e=>{a(null,e.bytesWritten,e.buffer)}).catch(e=>{a(e,0,T.from([]))})}function read(e,...t){let n=i.getInstance(e),r=t[t.length-1],a,o,s,c;if(!(t.length<=1))if(typeof t[0]==`object`&&!ArrayBuffer.isView(t[0])){let e=t[0];a=e.buffer,o=e.offset,s=e.length,c=e.position}else a=t[0],o=t[1],s=t[2],c=t[3];n.read(a,o,s,c).then(e=>{r(null,e.bytesRead,e.buffer)}).catch(e=>{r(e,0,T.from([]))})}function close(e,t){i.getInstance(e).close().then(()=>{t(null)}).catch(e=>t(e))}function rm(e,...t){let n={},r=t[t.length-1];t.length>=2&&(n=t[0]),S(e,n).then(()=>{r(null)}).catch(e=>{r(e)})}function rename(e,t,n){Promise.resolve().then(()=>{try{_(e,t),n(null)}catch(e){n(e)}})}function copyFile(e,t,n,r){let i=typeof n==`function`?0:n,a=typeof n==`function`?n:r;Promise.resolve().then(()=>{try{u(e,t,i),a(null)}catch(e){a(e)}})}function access(e,t,n){let r=typeof t==`function`?void 0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{o(e,r),i(null)}catch(e){i(e)}})}function appendFile(e,t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n;Promise.resolve().then(()=>{try{s(e,t,a),i(null)}catch(e){i(e)}})}function readlink(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{r(null,h(e,i))}catch(e){r(e,``)}})}function truncate(e,t,n){let r=typeof t==`function`?0:t,i=typeof t==`function`?t:n;Promise.resolve().then(()=>{try{y(e,r),i(null)}catch(e){i(e)}})}function chmod(e,t,n){Promise.resolve().then(()=>{try{c(e,t),n(null)}catch(e){n(e)}})}function chown(e,t,n,r){Promise.resolve().then(()=>{try{l(e,t,n),r(null)}catch(e){r(e)}})}function mkdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{f(e,i),r(null)}catch(e){r(e)}})}function rmdir(e,t,n){let r=typeof t==`function`?t:n,i=typeof t==`function`?void 0:t;Promise.resolve().then(()=>{try{v(e,i),r(null)}catch(e){r(e)}})}function readFile(t,n,r){let i=typeof n==`function`?n:r,a=typeof n==`function`?void 0:n,o=e(t);Promise.resolve().then(()=>{try{let e=typeof a==`string`?{encoding:a,flag:`r`}:{encoding:a?.encoding??null,flag:a?.flag??`r`};i(null,p(o,e))}catch(e){i(e,null)}})}function writeFile(t,n,r,i){let a=typeof r==`function`?r:i,o=e(t);Promise.resolve().then(()=>{try{b(o,n),a(null)}catch(e){a(e)}})}function link(e,t,n){Promise.resolve().then(()=>{try{d(e,t),n(null)}catch(e){n(e)}})}function unlink(t,n){let r=e(t);Promise.resolve().then(()=>{C.unlink(r),n(null)})}export{access,appendFile,chmod,chown,close,copyFile,link,lstat,mkdir,open,read,readFile,readdir,readlink,realpath,rename,rm,rmdir,stat,symlink,truncate,unlink,write,writeFile};
|
package/lib/esm/fs-watcher.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";import{EventEmitter as r}from"node:events";const i=new WeakMap;var FSWatcher=class extends r{constructor(r,a,o){super(),(!a||typeof a!=`object`)&&(a={persistent:!0});let s=a.persistent!==!1,c=n.Cancellable.new(),l=e(r),u=n.File.new_for_path(l).monitor(n.FileMonitorFlags.NONE,c);u.connect(`changed`,changed.bind(this));let d=null;s&&(d=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),i.set(this,{persistent:s,cancellable:c,sourceId:d,watcher:u}),o&&this.on(`change`,o)}close(){let e=i.get(this);e.cancellable.is_cancelled()||(e.cancellable.cancel(),e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null))}ref(){let e=i.get(this);return!e.persistent&&!e.cancellable.is_cancelled()&&(e.persistent=!0,e.sourceId=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),this}unref(){let e=i.get(this);return e.persistent&&(e.persistent=!1,e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null)),this}};function changed(e,t,r,i){switch(i){case n.FileMonitorEvent.CHANGES_DONE_HINT:this.emit(`change`,`change`,t.get_basename());break;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:this.emit(`change`,`rename`,t.get_basename());break}}function gioEventToNodeType(e){switch(e){case n.FileMonitorEvent.CHANGES_DONE_HINT:return`change`;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:return`rename`;default:return null}}async function*watchAsync(t,r){let i=r?.signal;if(i?.aborted)return;let a=e(t),o=n.File.new_for_path(a),s=n.Cancellable.new(),c;try{c=o.monitor(n.FileMonitorFlags.NONE,s)}catch{return}let l=[],u=[],d=!1;function enqueue(e){d||(u.length>0?u.shift().resolve({value:e,done:!1}):l.push(e))}function terminate(){if(!d)for(d=!0,s.is_cancelled()||s.cancel();u.length>0;)u.shift().resolve({value:void 0,done:!0})}let f=c.connect(`changed`,(e,t,n,r)=>{let i=gioEventToNodeType(r);i!==null&&enqueue({eventType:i,filename:t?.get_basename()??null})}),abortHandler=()=>terminate();i?.addEventListener(`abort`,abortHandler);try{for(;!d;){if(l.length>0){yield l.shift();continue}let e=await new Promise(e=>{u.push({resolve:e})});if(e.done)break;yield e.value}}finally{i?.removeEventListener(`abort`,abortHandler)
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";import{EventEmitter as r}from"node:events";const i=new WeakMap;var FSWatcher=class extends r{constructor(r,a,o){super(),(!a||typeof a!=`object`)&&(a={persistent:!0});let s=a.persistent!==!1,c=n.Cancellable.new(),l=e(r),u=n.File.new_for_path(l).monitor(n.FileMonitorFlags.NONE,c);u.connect(`changed`,changed.bind(this));let d=null;s&&(d=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),i.set(this,{persistent:s,cancellable:c,sourceId:d,watcher:u}),o&&this.on(`change`,o)}close(){let e=i.get(this);e.cancellable.is_cancelled()||(e.cancellable.cancel(),e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null))}ref(){let e=i.get(this);return!e.persistent&&!e.cancellable.is_cancelled()&&(e.persistent=!0,e.sourceId=t.timeout_add(t.PRIORITY_LOW,2147483647,()=>t.SOURCE_CONTINUE)),this}unref(){let e=i.get(this);return e.persistent&&(e.persistent=!1,e.sourceId!==null&&(t.source_remove(e.sourceId),e.sourceId=null)),this}};function changed(e,t,r,i){switch(i){case n.FileMonitorEvent.CHANGES_DONE_HINT:this.emit(`change`,`change`,t.get_basename());break;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:this.emit(`change`,`rename`,t.get_basename());break}}function gioEventToNodeType(e){switch(e){case n.FileMonitorEvent.CHANGES_DONE_HINT:return`change`;case n.FileMonitorEvent.DELETED:case n.FileMonitorEvent.CREATED:case n.FileMonitorEvent.RENAMED:case n.FileMonitorEvent.MOVED_IN:case n.FileMonitorEvent.MOVED_OUT:return`rename`;default:return null}}async function*watchAsync(t,r){let i=r?.signal;if(i?.aborted)return;let a=e(t),o=n.File.new_for_path(a),s=n.Cancellable.new(),c;try{c=o.monitor(n.FileMonitorFlags.NONE,s)}catch{return}let l=[],u=[],d=!1;function enqueue(e){d||(u.length>0?u.shift().resolve({value:e,done:!1}):l.push(e))}function terminate(){if(!d)for(d=!0,s.is_cancelled()||s.cancel();u.length>0;)u.shift().resolve({value:void 0,done:!0})}let f=c.connect(`changed`,(e,t,n,r)=>{let i=gioEventToNodeType(r);i!==null&&enqueue({eventType:i,filename:t?.get_basename()??null})}),abortHandler=()=>terminate();i?.addEventListener(`abort`,abortHandler);try{for(;!d;){if(l.length>0){yield l.shift();continue}let e=await new Promise(e=>{u.push({resolve:e})});if(e.done)break;yield e.value}}finally{i?.removeEventListener(`abort`,abortHandler),c.disconnect(f),s.is_cancelled()||s.cancel()}}export{FSWatcher,FSWatcher as default,watchAsync};
|
package/lib/esm/sync.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{decode as e,encodeUint8Array as t,getEncodingFromOptions as n}from"./encoding.js";import{normalizePath as r,tempDirPath as i}from"./utils.js";import{FSWatcher as a}from"./fs-watcher.js";import{Dirent as o}from"./dirent.js";import{BigIntStats as s,STAT_ATTRIBUTES as c,Stats as l}from"./stats.js";import{FileHandle as u}from"./file-handle.js";import{createNodeError as d,isNotFoundError as f}from"./errors.js";import p from"@girs/glib-2.0";import m from"@girs/gio-2.0";import{join as h}from"node:path";import{Buffer as g}from"node:buffer";import{existsSync as _}from"@gjsify/utils";function statSync(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NONE,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`stat`,n)}}function lstatSync(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`lstat`,n)}}function readdirSync(e,t){let n=r(e),i=m.File.new_for_path(n).enumerate_children(`standard::name,standard::type`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null),a=[];try{let e=i.next_file(null);for(;e!==null;)a.push({name:e.get_name(),type:e.get_file_type()}),e=i.next_file(null)}finally{try{i.close(null)}catch{}}let s=[];for(let e of a){let r=h(n,e.name);if(t?.withFileTypes?s.push(new o(r,e.name,e.type)):s.push(e.name),t?.recursive&&e.type===m.FileType.DIRECTORY){let n=readdirSync(r,t);for(let t of n)typeof t==`string`?s.push(h(e.name,t)):s.push(t)}}return s}function realpathSync(e){let t=r(e),n=m.File.new_for_path(t),i=0;for(;;){let e=n.query_info(`standard::is-symlink,standard::symlink-target`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);if(!e.get_is_symlink())return n.get_path();let r=e.get_symlink_target(),a=n.get_parent();if(n=a?a.resolve_relative_path(r):m.File.new_for_path(r),++i>40)throw Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`)}}realpathSync.native=realpathSync;function symlinkSync(e,t,n){let i=r(t),a=r(e);m.File.new_for_path(i).make_symbolic_link(a,null)}function readFileSync(e,i={encoding:null,flag:`r`}){let a=r(e),o=m.File.new_for_path(a);try{let[e,r]=o.load_contents(null);if(!e)throw d(Error(`failed to read file`),`read`,a);return t(n(i,`buffer`),r)}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`read`,a)}}function mkdirSync(e,t){let n=!1,i=511;if(typeof t==`object`?(t?.recursive&&(n=t.recursive),t?.mode&&(i=t.mode)):i=t||511,e=r(e),typeof i==`string`)throw TypeError(`mode as string is currently not supported!`);if(n)return mkdirSyncRecursive(e);let a=m.File.new_for_path(e);try{a.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}}function mkdirSyncRecursive(e){let t=m.File.new_for_path(e);try{return t.make_directory(null),e}catch(t){let n=t;if(n.code===m.IOErrorEnum.EXISTS)return;if(n.code===m.IOErrorEnum.NOT_FOUND){let n=h(e,`..`),r=m.File.new_for_path(n).get_path();if(r===e)throw d(t,`mkdir`,e);let i=mkdirSyncRecursive(r),a=m.File.new_for_path(e);try{a.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}return i??e}throw d(t,`mkdir`,e)}}function rmdirSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{if(i.query_info(`standard::type`,m.FileQueryInfoFlags.NONE,null).get_file_type()!==m.FileType.DIRECTORY)throw d(Object.assign(Error(),{code:4}),`rmdir`,n);if(i.enumerate_children(`standard::name`,m.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=m.File.new_for_path(t);try{n.delete(null)}catch(e){throw d(e,`unlink`,t)}}function writeFileSync(e,t){p.file_set_contents(r(e),t)}function renameSync(e,t){let n=r(e),i=r(t),a=m.File.new_for_path(n),o=m.File.new_for_path(i);try{a.move(o,m.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=m.File.new_for_path(i),s=m.File.new_for_path(a),c=m.FileCopyFlags.NONE;n&&!(n&1)?c=m.FileCopyFlags.OVERWRITE:n||(c=m.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=m.File.new_for_path(n);try{let e=i.query_info(`access::*`,m.FileQueryInfoFlags.NONE,null);if(t!==void 0&&t!==0){let r={code:14,message:`permission denied, access '${n}'`};if(t&4&&!e.get_attribute_boolean(`access::can-read`)||t&2&&!e.get_attribute_boolean(`access::can-write`)||t&1&&!e.get_attribute_boolean(`access::can-execute`))throw d(r,`access`,n)}}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`access`,n)}}function appendFileSync(e,t,n){let i=r(e),a=m.File.new_for_path(i),o;o=typeof t==`string`?new TextEncoder().encode(t):t;try{let e=a.append_to(m.FileCreateFlags.NONE,null);o.length>0&&e.write_bytes(new p.Bytes(o),null),e.close(null)}catch(e){throw d(e,`appendfile`,i)}}function readlinkSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{let e=i.query_info(`standard::symlink-target`,m.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`?g.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(
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{decode as e,encodeUint8Array as t,getEncodingFromOptions as n}from"./encoding.js";import{normalizePath as r,tempDirPath as i}from"./utils.js";import{FSWatcher as a}from"./fs-watcher.js";import{Dirent as o}from"./dirent.js";import{BigIntStats as s,STAT_ATTRIBUTES as c,Stats as l}from"./stats.js";import{FileHandle as u}from"./file-handle.js";import{createNodeError as d,isNotFoundError as f}from"./errors.js";import p from"@girs/glib-2.0";import m from"@girs/gio-2.0";import{join as h}from"node:path";import{Buffer as g}from"node:buffer";import{existsSync as _}from"@gjsify/utils";function statSync(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NONE,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`stat`,n)}}function lstatSync(e,t){let n=r(e);try{let e=m.File.new_for_path(n).query_info(c,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);return t?.bigint?new s(e,n):new l(e,n)}catch(e){if(t?.throwIfNoEntry===!1&&f(e))return;throw d(e,`lstat`,n)}}function readdirSync(e,t){let n=r(e),i=m.File.new_for_path(n).enumerate_children(`standard::name,standard::type`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null),a=[];try{let e=i.next_file(null);for(;e!==null;)a.push({name:e.get_name(),type:e.get_file_type()}),e=i.next_file(null)}finally{try{i.close(null)}catch{}}let s=[];for(let e of a){let r=h(n,e.name);if(t?.withFileTypes?s.push(new o(r,e.name,e.type)):s.push(e.name),t?.recursive&&e.type===m.FileType.DIRECTORY){let n=readdirSync(r,t);for(let t of n)typeof t==`string`?s.push(h(e.name,t)):s.push(t)}}return s}function realpathSync(e){let t=r(e),n=m.File.new_for_path(t),i=0;for(;;){let e=n.query_info(`standard::is-symlink,standard::symlink-target`,m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null);if(!e.get_is_symlink())return n.get_path();let r=e.get_symlink_target(),a=n.get_parent();if(n=a?a.resolve_relative_path(r):m.File.new_for_path(r),++i>40)throw Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`)}}realpathSync.native=realpathSync;function symlinkSync(e,t,n){let i=r(t),a=r(e);m.File.new_for_path(i).make_symbolic_link(a,null)}function readFileSync(e,i={encoding:null,flag:`r`}){let a=r(e),o=m.File.new_for_path(a);try{let[e,r]=o.load_contents(null);if(!e)throw d(Error(`failed to read file`),`read`,a);return t(n(i,`buffer`),r)}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`read`,a)}}function mkdirSync(e,t){let n=!1,i=511;if(typeof t==`object`?(t?.recursive&&(n=t.recursive),t?.mode&&(i=t.mode)):i=t||511,e=r(e),typeof i==`string`)throw TypeError(`mode as string is currently not supported!`);if(n)return mkdirSyncRecursive(e);let a=m.File.new_for_path(e);try{a.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}}function mkdirSyncRecursive(e){let t=m.File.new_for_path(e);try{return t.make_directory(null),e}catch(t){let n=t;if(n.code===m.IOErrorEnum.EXISTS)return;if(n.code===m.IOErrorEnum.NOT_FOUND){let n=h(e,`..`),r=m.File.new_for_path(n).get_path();if(r===e)throw d(t,`mkdir`,e);let i=mkdirSyncRecursive(r),a=m.File.new_for_path(e);try{a.make_directory(null)}catch(t){throw d(t,`mkdir`,e)}return i??e}throw d(t,`mkdir`,e)}}function rmdirSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{if(i.query_info(`standard::type`,m.FileQueryInfoFlags.NONE,null).get_file_type()!==m.FileType.DIRECTORY)throw d(Object.assign(Error(),{code:4}),`rmdir`,n);if(i.enumerate_children(`standard::name`,m.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=m.File.new_for_path(t);try{n.delete(null)}catch(e){throw d(e,`unlink`,t)}}function writeFileSync(e,t){p.file_set_contents(r(e),t)}function renameSync(e,t){let n=r(e),i=r(t),a=m.File.new_for_path(n),o=m.File.new_for_path(i);try{a.move(o,m.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=m.File.new_for_path(i),s=m.File.new_for_path(a),c=m.FileCopyFlags.NONE;n&&!(n&1)?c=m.FileCopyFlags.OVERWRITE:n||(c=m.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=m.File.new_for_path(n);try{let e=i.query_info(`access::*`,m.FileQueryInfoFlags.NONE,null);if(t!==void 0&&t!==0){let r={code:14,message:`permission denied, access '${n}'`};if(t&4&&!e.get_attribute_boolean(`access::can-read`)||t&2&&!e.get_attribute_boolean(`access::can-write`)||t&1&&!e.get_attribute_boolean(`access::can-execute`))throw d(r,`access`,n)}}catch(e){throw e.code&&typeof e.code==`string`?e:d(e,`access`,n)}}function appendFileSync(e,t,n){let i=r(e),a=m.File.new_for_path(i),o;o=typeof t==`string`?new TextEncoder().encode(t):t;try{let e=a.append_to(m.FileCreateFlags.NONE,null);o.length>0&&e.write_bytes(new p.Bytes(o),null),e.close(null)}catch(e){throw d(e,`appendfile`,i)}}function readlinkSync(e,t){let n=r(e),i=m.File.new_for_path(n);try{let e=i.query_info(`standard::symlink-target`,m.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`?g.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(m.File.new_for_path(n).query_file_type(m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)===m.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(m.File.new_for_path(i).query_file_type(m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)!==m.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]=p.spawn_sync(null,[`ln`,`--`,n,i],null,p.SpawnFlags.SEARCH_PATH,null);if(a=e?new TextDecoder().decode(e).trim():``,!p.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=m.File.new_for_path(n);try{let e=i.replace(null,!1,m.FileCreateFlags.NONE,null);if(t&&t>0){let[,n]=i.load_contents(null),r=n.slice(0,t);r.length>0&&e.write_bytes(new p.Bytes(r),null)}e.close(null)}catch(e){throw d(e,`truncate`,n)}}function chmodSync(e,t){let n=r(e),i=typeof t==`string`?parseInt(t,8):t;try{m.File.new_for_path(n).set_attribute_uint32(`unix::mode`,i,m.FileQueryInfoFlags.NONE,null)}catch(e){throw d(e,`chmod`,n)}}function chownSync(e,t,n){let i=r(e);try{let e=m.File.new_for_path(i),r=new m.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,m.FileQueryInfoFlags.NONE,null)}catch(e){throw d(e,`chown`,i)}}function watch(e,t,n){return new a(r(e),t,n)}function openSync(e,t,n){return new u({path:e,flags:t,mode:n})}function mkdtempSync(t,r){let a=n(r),o=i(t);return mkdirSync(o,{recursive:!1,mode:511}),e(o,a)}function rmSync(e,t){let n=r(e),i=m.File.new_for_path(n),a=t?.recursive||!1,o=t?.force||!1,s;try{s=i.query_file_type(m.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}catch(t){if(o&&f(t))return;throw d(t,`rm`,e)}if(s===m.FileType.SYMBOLIC_LINK){try{i.delete(null)}catch(t){if(o&&f(t))return;throw d(t,`rm`,e)}return}if(s===m.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(h(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,_ as existsSync,linkSync,lstatSync,mkdirSync,mkdtempSync,openSync,readFileSync,readdirSync,readlinkSync,realpathSync,renameSync,rmSync,rmdirSync,statSync,symlinkSync,truncateSync,unlinkSync,watch,writeFileSync};
|
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(
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";function toGLibDateTime(e){let n=e instanceof Date?e.getTime():typeof e==`bigint`?Number(e):typeof e==`string`?Date.parse(e):e*1e3;return t.DateTime.new_from_unix_utc(Math.floor(n/1e3))}function setTimestamps(e,t,r,i){let a=n.File.new_for_path(e),o=new n.FileInfo;o.set_modification_date_time(toGLibDateTime(r)),o.set_access_date_time(toGLibDateTime(t)),a.set_attributes_from_info(o,i,null)}function utimesSync(t,r,i){setTimestamps(e(t),r,i,n.FileQueryInfoFlags.NONE)}function utimes(e,t,n,r){Promise.resolve().then(()=>utimesSync(e,t,n)).then(()=>r(null),r)}async function utimesAsync(e,t,n){utimesSync(e,t,n)}function lutimesSync(t,r,i){setTimestamps(e(t),r,i,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS)}function lutimes(e,t,n,r){Promise.resolve().then(()=>lutimesSync(e,t,n)).then(()=>r(null),r)}async function lutimesAsync(e,t,n){lutimesSync(e,t,n)}function lchownSync(t,r,i){let a=e(t),o=n.File.new_for_path(a),s=new n.FileInfo;r!==-1&&s.set_attribute_uint32(`unix::uid`,r),i!==-1&&s.set_attribute_uint32(`unix::gid`,i),o.set_attributes_from_info(s,n.FileQueryInfoFlags.NOFOLLOW_SYMLINKS,null)}function lchown(e,t,n,r){Promise.resolve().then(()=>lchownSync(e,t,n)).then(()=>r(null),r)}async function lchownAsync(e,t,n){lchownSync(e,t,n)}function lchmodSync(e,t){}function lchmod(e,t,n){n(null)}async function lchmodAsync(e,t){}export{lchmod,lchmodAsync,lchmodSync,lchown,lchownAsync,lchownSync,lutimes,lutimesAsync,lutimesSync,utimes,utimesAsync,utimesSync};
|
|
@@ -406,7 +406,7 @@ export declare class FileHandle implements IFileHandle {
|
|
|
406
406
|
* helpers ({@link https://nodejs.org/api/stream_iter.html}). The
|
|
407
407
|
* stub keeps the @types/node FileHandle interface satisfied so
|
|
408
408
|
* downstream typecheck passes; calling at runtime throws a clear
|
|
409
|
-
* "not yet" error. Tracked in
|
|
409
|
+
* "not yet" error. Tracked in status/open-todos.md → "Node 25
|
|
410
410
|
* stream/iter integration".
|
|
411
411
|
*/
|
|
412
412
|
pull(..._args: any[]): any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/fs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"description": "Node.js fs module for Gjs",
|
|
5
5
|
"module": "lib/esm/index.js",
|
|
6
6
|
"types": "lib/types/index.d.ts",
|
|
@@ -66,19 +66,19 @@
|
|
|
66
66
|
"fs"
|
|
67
67
|
],
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@gjsify/cli": "^0.
|
|
70
|
-
"@gjsify/unit": "^0.
|
|
69
|
+
"@gjsify/cli": "^0.26.1",
|
|
70
|
+
"@gjsify/unit": "^0.26.1",
|
|
71
71
|
"@types/node": "^25.9.2",
|
|
72
72
|
"typescript": "^6.0.3"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
75
|
"@girs/gio-2.0": "^4.1.0",
|
|
76
76
|
"@girs/glib-2.0": "^4.1.0",
|
|
77
|
-
"@gjsify/buffer": "^0.
|
|
78
|
-
"@gjsify/events": "^0.
|
|
79
|
-
"@gjsify/stream": "^0.
|
|
80
|
-
"@gjsify/url": "^0.
|
|
81
|
-
"@gjsify/utils": "^0.
|
|
77
|
+
"@gjsify/buffer": "^0.26.1",
|
|
78
|
+
"@gjsify/events": "^0.26.1",
|
|
79
|
+
"@gjsify/stream": "^0.26.1",
|
|
80
|
+
"@gjsify/url": "^0.26.1",
|
|
81
|
+
"@gjsify/utils": "^0.26.1"
|
|
82
82
|
},
|
|
83
83
|
"gjsify": {
|
|
84
84
|
"runtimes": {
|