@gjsify/fs 0.4.30 → 0.4.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/esm/fd-ops.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{FileHandle as t}from"./file-handle.js";import{chmodSync as n,chownSync as r,readFileSync as i,statSync as a,truncateSync as o}from"./sync.js";import{utimesSync as s}from"./utimes.js";function getFH(e){return e instanceof t?t.getInstance(e.fd):t.getInstance(e)}function fstatSync(t,n){return a(e(getFH(t).options.path),n)}function fstat(e,t,n){typeof t==`function`&&(n=t,t={}),Promise.resolve().then(()=>fstatSync(e,t)).then(e=>n(null,e),n)}async function fstatAsync(e,t){return t?.bigint,fstatSync(e,t)}function ftruncateSync(t,n=0){o(e(getFH(t).options.path),n)}function ftruncate(e,t,n){typeof t==`function`&&(n=t,t=0),Promise.resolve().then(()=>ftruncateSync(e,t)).then(()=>n(null),n)}async function ftruncateAsync(e,t=0){ftruncateSync(e,t)}function fdatasyncSync(e){getFH(e)._flushSync()}function fdatasync(e,t){Promise.resolve().then(()=>fdatasyncSync(e)).then(()=>t(null),t)}async function fdatasyncAsync(e){fdatasyncSync(e)}function fsyncSync(e){getFH(e)._flushSync()}function fsync(e,t){Promise.resolve().then(()=>fsyncSync(e)).then(()=>t(null),t)}async function fsyncAsync(e){fsyncSync(e)}function fchmodSync(t,r){n(e(getFH(t).options.path),r)}function fchmod(e,t,n){Promise.resolve().then(()=>fchmodSync(e,t)).then(()=>n(null),n)}async function fchmodAsync(e,t){fchmodSync(e,t)}function fchownSync(t,n,i){r(e(getFH(t).options.path),n,i)}function fchown(e,t,n,r){Promise.resolve().then(()=>fchownSync(e,t,n)).then(()=>r(null),r)}async function fchownAsync(e,t,n){fchownSync(e,t,n)}function futimesSync(t,n,r){s(e(getFH(t).options.path),n,r)}function futimes(e,t,n,r){Promise.resolve().then(()=>futimesSync(e,t,n)).then(()=>r(null),r)}async function futimesAsync(e,t,n){futimesSync(e,t,n)}function closeSync(e){getFH(e)._closeSync()}function readSync(e,t,n,r,i){let a=0;return typeof n==`object`&&n?(a=n.offset??0,r=n.length??t.byteLength,i=n.position??null):(a=n??0,r??=t.byteLength-a),getFH(e)._readSync(t,a,r,i??null)}function writeSync(e,t,n,r,i){let a;if(typeof t==`string`)a=new TextEncoder().encode(t),typeof n==`number`&&(i=n);else{let e=typeof n==`number`?n:0,i=typeof r==`number`?r:t.byteLength-e;a=new Uint8Array(t.buffer,t.byteOffset+e,i)}return getFH(e)._writeSync(a,i??null)}function readvSync(e,t,n){let r=0;for(let i of t){let t=readSync(e,i,0,i.byteLength,n==null?null:n+r);if(r+=t,t<i.byteLength)break}return r}function readv(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesRead:readvSync(e,t,n),buffers:t})).then(e=>r(null,e.bytesRead,e.buffers),r)}async function readvAsync(e,t,n){return{bytesRead:readvSync(e,t,n),buffers:t}}function writevSync(e,t,n){let r=0;for(let i of t){let t=writeSync(e,i,0,i.byteLength,n==null?null:n+r);r+=t}return r}function writev(e,t,n,r){typeof n==`function`&&(r=n,n=null),Promise.resolve().then(()=>({bytesWritten:writevSync(e,t,n),buffers:t})).then(e=>r(null,e.bytesWritten,e.buffers),r)}async function writevAsync(e,t,n){return{bytesWritten:writevSync(e,t,n),buffers:t}}function exists(t,n){try{a(e(t)),n(!0)}catch{n(!1)}}async function openAsBlob(t,n){let r=i(e(t));return new Blob([r],{type:n?.type??``})}export{closeSync,exists,fchmod,fchmodAsync,fchmodSync,fchown,fchownAsync,fchownSync,fdatasync,fdatasyncAsync,fdatasyncSync,fstat,fstatAsync,fstatSync,fsync,fsyncAsync,fsyncSync,ftruncate,ftruncateAsync,ftruncateSync,futimes,futimesAsync,futimesSync,openAsBlob,readSync,readv,readvAsync,readvSync,writeSync,writev,writevAsync,writevSync};
1
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import{FileHandle as t}from"./file-handle.js";import{chmodSync as n,chownSync as r,readFileSync as i,statSync as a,truncateSync as o}from"./sync.js";import{utimesSync as s}from"./utimes.js";function getFH(e){return e instanceof t?t.getInstance(e.fd):t.getInstance(e)}function fstatSync(t,n){return a(e(getFH(t).options.path),n)}function fstat(e,t,n){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(t,n=0){o(e(getFH(t).options.path),n)}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)._flushSync()}function fdatasync(e,t){Promise.resolve().then(()=>fdatasyncSync(e)).then(()=>t(null),t)}async function fdatasyncAsync(e){fdatasyncSync(e)}function fsyncSync(e){getFH(e)._flushSync()}function fsync(e,t){Promise.resolve().then(()=>fsyncSync(e)).then(()=>t(null),t)}async function fsyncAsync(e){fsyncSync(e)}function fchmodSync(t,r){n(e(getFH(t).options.path),r)}function fchmod(e,t,n){Promise.resolve().then(()=>fchmodSync(e,t)).then(()=>n(null),n)}async function fchmodAsync(e,t){fchmodSync(e,t)}function fchownSync(t,n,i){r(e(getFH(t).options.path),n,i)}function fchown(e,t,n,r){Promise.resolve().then(()=>fchownSync(e,t,n)).then(()=>r(null),r)}async function fchownAsync(e,t,n){fchownSync(e,t,n)}function futimesSync(t,n,r){s(e(getFH(t).options.path),n,r)}function futimes(e,t,n,r){Promise.resolve().then(()=>futimesSync(e,t,n)).then(()=>r(null),r)}async function futimesAsync(e,t,n){futimesSync(e,t,n)}function closeSync(e){getFH(e)._closeSync()}function readSync(e,t,n,r,i){let a=0;return typeof n==`object`&&n?(a=n.offset??0,r=n.length??t.byteLength,i=n.position??null):(a=n??0,r??=t.byteLength-a),getFH(e)._readSync(t,a,r,i??null)}function writeSync(e,t,n,r,i){let a;if(typeof t==`string`)a=new TextEncoder().encode(t),typeof n==`number`&&(i=n);else{let e=typeof n==`number`?n:0,i=typeof r==`number`?r:t.byteLength-e;a=new Uint8Array(t.buffer,t.byteOffset+e,i)}return getFH(e)._writeSync(a,i??null)}function readvSync(e,t,n){let r=0;for(let i of t){let t=readSync(e,i,0,i.byteLength,n==null?null:n+r);if(r+=t,t<i.byteLength)break}return r}function readv(e,t,n,r){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{a(e(t)),n(!0)}catch{n(!1)}}async function openAsBlob(t,n){let r=i(e(t));return new Blob([r],{type:n?.type??``})}export{closeSync,exists,fchmod,fchmodAsync,fchmodSync,fchown,fchownAsync,fchownSync,fdatasync,fdatasyncAsync,fdatasyncSync,fstat,fstatAsync,fstatSync,fsync,fsyncAsync,fsyncSync,ftruncate,ftruncateAsync,ftruncateSync,futimes,futimesAsync,futimesSync,openAsBlob,readSync,readv,readvAsync,readvSync,writeSync,writev,writevAsync,writevSync};
@@ -1 +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(`rename`,`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);try{c.disconnect(f)}catch{}s.is_cancelled()||s.cancel()}}export{FSWatcher,FSWatcher as default,watchAsync};
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);try{c.disconnect(f)}catch{}s.is_cancelled()||s.cancel()}}export{FSWatcher,FSWatcher as default,watchAsync};
package/lib/esm/statfs.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";const r=[`filesystem::size`,`filesystem::free`].join(`,`),i=4096;function buildStatFs(e){let t=Number(e.get_attribute_uint64(`filesystem::size`)??0),n=Number(e.get_attribute_uint64(`filesystem::free`)??0),r=Math.floor(t/i),a=Math.floor(n/i);return{type:0,bsize:i,blocks:r,bfree:a,bavail:a,files:0,ffree:0}}function buildBigIntStatFs(e){let t=BigInt(e.get_attribute_uint64(`filesystem::size`)??0),n=BigInt(e.get_attribute_uint64(`filesystem::free`)??0),r=BigInt(i),a=t/r,o=n/r;return{type:0n,bsize:r,blocks:a,bfree:o,bavail:o,files:0n,ffree:0n}}function statfsSync(t,i){let a=n.File.new_for_path(e(t)).query_filesystem_info(r,null);return i?.bigint===!0?buildBigIntStatFs(a):buildStatFs(a)}function queryFsInfoAsync(i,a){return new Promise((o,s)=>{let c=n.File.new_for_path(e(i));c.query_filesystem_info_async(r,t.PRIORITY_DEFAULT,null,(e,t)=>{try{let e=c.query_filesystem_info_finish(t);o(a?buildBigIntStatFs(e):buildStatFs(e))}catch(e){s(e)}})})}function statfs(e,t,n){typeof t==`function`&&(n=t,t={}),queryFsInfoAsync(e,t?.bigint===!0).then(e=>n(null,e),e=>n(e,null))}async function statfsAsync(e,t){return queryFsInfoAsync(e,t?.bigint===!0)}export{statfs,statfsAsync,statfsSync};
1
+ import"./_virtual/_rolldown/runtime.js";import{normalizePath as e}from"./utils.js";import t from"@girs/glib-2.0";import n from"@girs/gio-2.0";const r=[`filesystem::size`,`filesystem::free`].join(`,`),i=4096;function buildStatFs(e){let t=Number(e.get_attribute_uint64(`filesystem::size`)??0),n=Number(e.get_attribute_uint64(`filesystem::free`)??0),r=Math.floor(t/i),a=Math.floor(n/i);return{type:0,bsize:i,blocks:r,bfree:a,bavail:a,files:0,ffree:0}}function buildBigIntStatFs(e){let t=BigInt(e.get_attribute_uint64(`filesystem::size`)??0),n=BigInt(e.get_attribute_uint64(`filesystem::free`)??0),r=BigInt(i),a=t/r,o=n/r;return{type:0n,bsize:r,blocks:a,bfree:o,bavail:o,files:0n,ffree:0n}}function statfsSync(t,i){let a=n.File.new_for_path(e(t)).query_filesystem_info(r,null);return i?.bigint===!0?buildBigIntStatFs(a):buildStatFs(a)}function queryFsInfoAsync(i,a){return new Promise((o,s)=>{let c=n.File.new_for_path(e(i));c.query_filesystem_info_async(r,t.PRIORITY_DEFAULT,null,(e,t)=>{try{let e=c.query_filesystem_info_finish(t);o(a?buildBigIntStatFs(e):buildStatFs(e))}catch(e){s(e)}})})}function statfs(e,t,n){let r=typeof t==`function`?t:n;queryFsInfoAsync(e,(typeof t==`function`?{}:t)?.bigint===!0).then(e=>r(null,e),e=>r(e,null))}async function statfsAsync(e,t){return queryFsInfoAsync(e,t?.bigint===!0)}export{statfs,statfsAsync,statfsSync};
@@ -4,4 +4,4 @@ export { isNotFoundError };
4
4
  /**
5
5
  * Create a Node.js-style ErrnoException from a Gio error, with fs-specific path/dest fields.
6
6
  */
7
- export declare function createNodeError(err: any, syscall: string, path: PathLike, dest?: PathLike): NodeJS.ErrnoException;
7
+ export declare function createNodeError(err: unknown, syscall: string, path: PathLike, dest?: PathLike): NodeJS.ErrnoException;
@@ -16,7 +16,10 @@ export declare function readdirSync(path: PathLike, options?: {
16
16
  }): string[] | Dirent[];
17
17
  export declare function realpathSync(path: PathLike): string;
18
18
  export declare function symlinkSync(target: PathLike, path: PathLike, _type?: 'file' | 'dir' | 'junction'): void;
19
- export declare function readFileSync(path: PathLike, options?: any): string | Buffer<ArrayBuffer>;
19
+ export declare function readFileSync(path: PathLike, options?: {
20
+ encoding?: string | null;
21
+ flag?: string;
22
+ } | string | null): string | Buffer<ArrayBuffer>;
20
23
  /**
21
24
  * Synchronously creates a directory. Returns `undefined`, or if `recursive` is`true`, the first directory path created.
22
25
  * This is the synchronous version of {@link mkdir}.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/fs",
3
- "version": "0.4.30",
3
+ "version": "0.4.31",
4
4
  "description": "Node.js fs module for Gjs",
5
5
  "module": "lib/esm/index.js",
6
6
  "types": "lib/types/index.d.ts",
@@ -37,18 +37,18 @@
37
37
  "fs"
38
38
  ],
39
39
  "devDependencies": {
40
- "@gjsify/cli": "^0.4.30",
41
- "@gjsify/unit": "^0.4.30",
40
+ "@gjsify/cli": "^0.4.31",
41
+ "@gjsify/unit": "^0.4.31",
42
42
  "@types/node": "^25.9.1",
43
43
  "typescript": "^6.0.3"
44
44
  },
45
45
  "dependencies": {
46
46
  "@girs/gio-2.0": "2.88.0-4.0.1",
47
47
  "@girs/glib-2.0": "2.88.0-4.0.1",
48
- "@gjsify/buffer": "^0.4.30",
49
- "@gjsify/events": "^0.4.30",
50
- "@gjsify/stream": "^0.4.30",
51
- "@gjsify/url": "^0.4.30",
52
- "@gjsify/utils": "^0.4.30"
48
+ "@gjsify/buffer": "^0.4.31",
49
+ "@gjsify/events": "^0.4.31",
50
+ "@gjsify/stream": "^0.4.31",
51
+ "@gjsify/url": "^0.4.31",
52
+ "@gjsify/utils": "^0.4.31"
53
53
  }
54
54
  }