@gjsify/fs 0.53.0 → 0.55.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.
@@ -1 +1 @@
1
- import{__exportAll as e}from"../_virtual/_rolldown/runtime.js";import{__defaultVolume as t,absolutise as n}from"./volume.js";import{appendFileSync as r,writeFileSync as i}from"./sync.js";var a=e({FSWatcher:()=>FSWatcher,ReadStream:()=>ReadStream,StatWatcher:()=>StatWatcher,WriteStream:()=>WriteStream,createReadStream:()=>createReadStream,createWriteStream:()=>createWriteStream,unwatchFile:()=>unwatchFile,watch:()=>watch,watchFile:()=>watchFile}),EventBus=class{listeners=new Map;on(e,t){let n=this.listeners.get(e)??[];return n.push(t),this.listeners.set(e,n),this}once(e,t){let wrapper=(...n)=>{this.off(e,wrapper),t(...n)};return this.on(e,wrapper)}off(e,t){let n=this.listeners.get(e);if(!n)return this;let r=n.indexOf(t);return r>=0&&n.splice(r,1),this}emit(e,...t){let n=this.listeners.get(e);if(!n||n.length===0)return!1;for(let e of n.slice())e(...t);return!0}removeAllListeners(e){return e?this.listeners.delete(e):this.listeners.clear(),this}},ReadStream=class extends EventBus{path;destroyed=!1;buffer;position;end;chunkSize;encoding;constructor(e,r={}){super(),this.path=n(e);try{this.buffer=t.readFileSync(this.path)}catch(e){this.buffer=new Uint8Array,queueMicrotask(()=>this.emit(`error`,e));return}this.position=r.start??0,this.end=Math.min(r.end??this.buffer.byteLength-1,this.buffer.byteLength-1),this.chunkSize=r.highWaterMark??65536,this.encoding=r.encoding,queueMicrotask(()=>this._pump())}_pump(){if(!this.destroyed){for(;this.position<=this.end;){let e=Math.min(this.position+this.chunkSize,this.end+1),t=this.buffer.subarray(this.position,e);this.position=e,this.encoding?this.emit(`data`,new TextDecoder(this.encoding).decode(t)):this.emit(`data`,t)}this.emit(`end`),this.emit(`close`)}}pipe(e){return this.on(`data`,t=>{e.write(t)}),this.on(`end`,()=>{e.end?.()}),e}destroy(e){this.destroyed=!0,e&&this.emit(`error`,e),this.emit(`close`)}async*[Symbol.asyncIterator](){let e=[],t=!1,n=null;for(this.on(`data`,t=>{e.push(t),n?.()}),this.on(`end`,()=>{t=!0,n?.()});!t||e.length>0;){if(e.length===0){await new Promise(e=>{n=e}),n=null;continue}let t=e.shift();t!==void 0&&(yield t)}}get bytesRead(){return this.position}};function createReadStream(e,t){return new ReadStream(e,t)}var WriteStream=class extends EventBus{path;destroyed=!1;parts=[];ended=!1;flags;mode;encoding;bytesWritten=0;constructor(e,t={}){super(),this.path=n(e),this.flags=t.flags??`w`,this.mode=t.mode??438,this.encoding=t.encoding,queueMicrotask(()=>this.emit(`open`,-1))}write(e,t,n){if(this.destroyed||this.ended)return!1;let r=typeof t==`function`?t:n,i=typeof e==`string`?new TextEncoder().encode(e):e;return this.parts.push(i),this.bytesWritten+=i.byteLength,queueMicrotask(()=>r?.(null)),!0}end(e,t){this.ended||(e&&this.write(e),this.ended=!0,queueMicrotask(()=>{try{let e=new Uint8Array(this.parts.reduce((e,t)=>e+t.byteLength,0)),n=0;for(let t of this.parts)e.set(t,n),n+=t.byteLength;this.flags===`a`||this.flags===`a+`?r(this.path,e):i(this.path,e,{mode:this.mode}),this.emit(`finish`),this.emit(`close`),t?.()}catch(e){this.emit(`error`,e)}}))}destroy(e){this.destroyed=!0,e&&this.emit(`error`,e),this.emit(`close`)}};function createWriteStream(e,t){return new WriteStream(e,t)}var FSWatcher=class extends EventBus{path;closed=!1;constructor(e){super(),this.path=n(e)}close(){this.closed||(this.closed=!0,this.emit(`close`))}ref(){return this}unref(){return this}};function watch(e,t,n){return new FSWatcher(e)}var StatWatcher=class extends EventBus{close(){this.emit(`close`)}ref(){return this}unref(){return this}};function watchFile(e){return new StatWatcher}function unwatchFile(e){}export{FSWatcher,ReadStream,StatWatcher,WriteStream,createReadStream,createWriteStream,a as stream_exports,unwatchFile,watch,watchFile};
1
+ import{__exportAll as e}from"../_virtual/_rolldown/runtime.js";import{__defaultVolume as t,absolutise as n}from"./volume.js";import{appendFileSync as r,writeFileSync as i}from"./sync.js";var a=e({FSWatcher:()=>FSWatcher,ReadStream:()=>ReadStream,StatWatcher:()=>StatWatcher,WriteStream:()=>WriteStream,createReadStream:()=>createReadStream,createWriteStream:()=>createWriteStream,unwatchFile:()=>unwatchFile,watch:()=>watch,watchFile:()=>watchFile}),EventBus=class{listeners=new Map;on(e,t){let n=this.listeners.get(e)??[];return n.push(t),this.listeners.set(e,n),this}once(e,t){let wrapper=(...n)=>{this.off(e,wrapper),t(...n)};return this.on(e,wrapper)}off(e,t){let n=this.listeners.get(e);if(!n)return this;let r=n.indexOf(t);return r>=0&&n.splice(r,1),this}emit(e,...t){let n=this.listeners.get(e);if(!n||n.length===0)return!1;for(let e of n.slice())e(...t);return!0}removeAllListeners(e){return e?this.listeners.delete(e):this.listeners.clear(),this}addListener(e,t){return this.on(e,t)}removeListener(e,t){return this.off(e,t)}},ReadStream=class extends EventBus{path;destroyed=!1;buffer;position;end;chunkSize;encoding;constructor(e,r={}){super(),this.path=n(e);try{this.buffer=t.readFileSync(this.path)}catch(e){this.buffer=new Uint8Array,queueMicrotask(()=>this.emit(`error`,e));return}this.position=r.start??0,this.end=Math.min(r.end??this.buffer.byteLength-1,this.buffer.byteLength-1),this.chunkSize=r.highWaterMark??65536,this.encoding=r.encoding,queueMicrotask(()=>this._pump())}_pump(){if(!this.destroyed){for(;this.position<=this.end;){let e=Math.min(this.position+this.chunkSize,this.end+1),t=this.buffer.subarray(this.position,e);this.position=e,this.encoding?this.emit(`data`,new TextDecoder(this.encoding).decode(t)):this.emit(`data`,t)}this.emit(`end`),this.emit(`close`)}}pipe(e){return this.on(`data`,t=>{e.write(t)}),this.on(`end`,()=>{e.end?.()}),e}destroy(e){this.destroyed=!0,e&&this.emit(`error`,e),this.emit(`close`)}async*[Symbol.asyncIterator](){let e=[],t=!1,n=null;for(this.on(`data`,t=>{e.push(t),n?.()}),this.on(`end`,()=>{t=!0,n?.()});!t||e.length>0;){if(e.length===0){await new Promise(e=>{n=e}),n=null;continue}let t=e.shift();t!==void 0&&(yield t)}}get bytesRead(){return this.position}};function createReadStream(e,t){return new ReadStream(e,t)}var WriteStream=class extends EventBus{path;destroyed=!1;parts=[];ended=!1;flags;mode;encoding;bytesWritten=0;constructor(e,t={}){super(),this.path=n(e),this.flags=t.flags??`w`,this.mode=t.mode??438,this.encoding=t.encoding,queueMicrotask(()=>this.emit(`open`,-1))}write(e,t,n){if(this.destroyed||this.ended)return!1;let r=typeof t==`function`?t:n,i=typeof e==`string`?new TextEncoder().encode(e):e;return this.parts.push(i),this.bytesWritten+=i.byteLength,queueMicrotask(()=>r?.(null)),!0}end(e,t){this.ended||(e&&this.write(e),this.ended=!0,queueMicrotask(()=>{try{let e=new Uint8Array(this.parts.reduce((e,t)=>e+t.byteLength,0)),n=0;for(let t of this.parts)e.set(t,n),n+=t.byteLength;this.flags===`a`||this.flags===`a+`?r(this.path,e):i(this.path,e,{mode:this.mode}),this.emit(`finish`),this.emit(`close`),t?.()}catch(e){this.emit(`error`,e)}}))}destroy(e){this.destroyed=!0,e&&this.emit(`error`,e),this.emit(`close`)}};function createWriteStream(e,t){return new WriteStream(e,t)}var FSWatcher=class extends EventBus{path;closed=!1;constructor(e){super(),this.path=n(e)}close(){this.closed||(this.closed=!0,this.emit(`close`))}ref(){return this}unref(){return this}};function watch(e,t,n){return new FSWatcher(e)}var StatWatcher=class extends EventBus{close(){this.emit(`close`)}ref(){return this}unref(){return this}};function watchFile(e){return new StatWatcher}function unwatchFile(e){}export{FSWatcher,ReadStream,StatWatcher,WriteStream,createReadStream,createWriteStream,a as stream_exports,unwatchFile,watch,watchFile};
@@ -17,6 +17,8 @@ declare class EventBus {
17
17
  off(event: string, fn: (...args: unknown[]) => void): this;
18
18
  emit(event: string, ...args: unknown[]): boolean;
19
19
  removeAllListeners(event?: string): this;
20
+ addListener(event: string, fn: (...args: unknown[]) => void): this;
21
+ removeListener(event: string, fn: (...args: unknown[]) => void): this;
20
22
  }
21
23
  export declare class ReadStream extends EventBus {
22
24
  readonly path: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gjsify/fs",
3
- "version": "0.53.0",
3
+ "version": "0.55.0",
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,9 +66,9 @@
66
66
  "fs"
67
67
  ],
68
68
  "devDependencies": {
69
- "@gjsify/cli": "^0.53.0",
70
- "@gjsify/unit": "^0.53.0",
71
- "@gjsify/web-streams": "^0.53.0",
69
+ "@gjsify/cli": "^0.55.0",
70
+ "@gjsify/unit": "^0.55.0",
71
+ "@gjsify/web-streams": "^0.55.0",
72
72
  "@types/node": "^25.9.2",
73
73
  "typescript": "^6.0.3"
74
74
  },
@@ -76,11 +76,11 @@
76
76
  "@girs/gio-2.0": "5.4.0",
77
77
  "@girs/giounix-2.0": "5.4.0",
78
78
  "@girs/glib-2.0": "5.4.0",
79
- "@gjsify/buffer": "^0.53.0",
80
- "@gjsify/events": "^0.53.0",
81
- "@gjsify/stream": "^0.53.0",
82
- "@gjsify/url": "^0.53.0",
83
- "@gjsify/utils": "^0.53.0"
79
+ "@gjsify/buffer": "^0.55.0",
80
+ "@gjsify/events": "^0.55.0",
81
+ "@gjsify/stream": "^0.55.0",
82
+ "@gjsify/url": "^0.55.0",
83
+ "@gjsify/utils": "^0.55.0"
84
84
  },
85
85
  "gjsify": {
86
86
  "runtimes": {