@gjsify/stream 0.4.14 → 0.4.15
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/writable.js +1 -1
- package/lib/types/writable.d.ts +10 -0
- package/package.json +6 -6
package/lib/esm/writable.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{Stream_ as e}from"./stream-base.js";import{getDefaultHighWaterMark as t}from"./internal/state.js";import{nextTick as n}from"@gjsify/utils";var r=class Writable_ extends e{static[Symbol.hasInstance](e){let t=this;return t.prototype!==void 0&&Object.prototype.isPrototypeOf.call(t.prototype,e)?!0:t.prototype!==Writable_.prototype||e==null?!1:typeof e.writableHighWaterMark==`number`}writable=!0;writableHighWaterMark;writableLength=0;writableObjectMode;writableEnded=!1;writableFinished=!1;writableCorked=0;writableNeedDrain=!1;destroyed=!1;_err;_writableState={ended:!1,finished:!1,constructed:!0,writing:!1};_corkedBuffer=[];_writeBuffer=[];_pendingConstruct=[];_ending=!1;_endCallback;_pendingEnd=null;_writeImpl;_writev;_finalImpl;_destroyImpl;_constructImpl;_decodeStrings;_defaultEncoding=`utf8`;constructor(e){super(e),this.writableHighWaterMark=e?.highWaterMark??t(e?.objectMode??!1),this.writableObjectMode=e?.objectMode??!1,this._decodeStrings=e?.decodeStrings!==!1,e?.write&&(this._writeImpl=e.write),e?.writev&&(this._writev=e.writev),e?.final&&(this._finalImpl=e.final),e?.destroy&&(this._destroyImpl=e.destroy),e?.construct&&(this._constructImpl=e.construct),(this._constructImpl||this._construct!==Writable_.prototype._construct)&&(this._writableState.constructed=!1,n(()=>{this._construct(e=>{this._writableState.constructed=!0,e?this.destroy(e):this._maybeFlush()})}))}_construct(e){this._constructImpl?this._constructImpl.call(this,e):e()}_write(e,t,n){this._writeImpl?this._writeImpl.call(this,e,t,n):n()}_final(e){this._finalImpl?this._finalImpl.call(this,e):e()}_maybeFlush(){let e=this._pendingConstruct.splice(0);if(e.length>0){let[t,...n]=e;this._writeBuffer.push(...n),this._doWrite(t.chunk,t.encoding,t.callback)}if(this._pendingEnd){let{chunk:e,encoding:t,callback:n}=this._pendingEnd;this._pendingEnd=null,this._doEnd(e,t,n)}}_doWrite(e,t,r){this._writableState.writing=!0;let i=!0;this._write(e,t,t=>{if(this.writableLength-=this.writableObjectMode?1:chunkLen(e),i){n(()=>{if(t){r(t),this.emit(`error`,t);return}r(),this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`))}),t||this._drainWriteBuffer();return}n(t?()=>{r(t),this.emit(`error`,t),this._drainWriteBuffer()}:()=>{r(),this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`)),this._drainWriteBuffer()})}),i=!1}_drainWriteBuffer(){if(this._writeBuffer.length>0){let e=this._writeBuffer.shift();this._doWrite(e.chunk,e.encoding,e.callback)}else this._writableState.writing=!1,this._maybeFinish()}_maybeFinish(){!this._ending||this._writableState.finished||this._writableState.writing||this._writeBuffer.length>0||(this._ending=!1,this._final(e=>{this.writableFinished=!0,this._writableState.finished=!0,n(()=>{e&&this.emit(`error`,e),this.emit(`finish`),n(()=>this.emit(`close`)),this._endCallback&&this._endCallback()})}))}write(e,t,r){let i,a;if(typeof t==`function`?(i=t,a=this._defaultEncoding):(a=t??this._defaultEncoding,i=r??(()=>{})),this._decodeStrings&&!this.writableObjectMode&&typeof e==`string`){let t=globalThis.Buffer;t&&(e=t.from(e,a),a=`buffer`)}if(typeof e!=`string`&&!this.writableObjectMode){let t=globalThis.Buffer;(t&&t.isBuffer(e)||e instanceof Uint8Array)&&(a=`buffer`)}if(this.writableEnded){let e=Error(`write after end`);return n(()=>{i(e),this.emit(`error`,e)}),!1}if(this.writableLength+=this.writableObjectMode?1:chunkLen(e),this.writableCorked>0)return this._corkedBuffer.push({chunk:e,encoding:a,callback:i}),this.writableLength<this.writableHighWaterMark;if(!this._writableState.constructed)return this._pendingConstruct.push({chunk:e,encoding:a,callback:i}),this.writableLength<this.writableHighWaterMark;let o=this.writableLength<this.writableHighWaterMark;return o||(this.writableNeedDrain=!0),this._writableState.writing?this._writeBuffer.push({chunk:e,encoding:a,callback:i}):this._doWrite(e,a,i),o}_doEnd(e,t,n){e!=null&&this.write(e,t),this.writableEnded=!0,this._writableState.ended=!0,this._ending=!0,this._endCallback=n,this._maybeFinish()}end(e,t,r){return typeof e==`function`&&(r=e,e=void 0),typeof t==`function`&&(r=t,t=void 0),this.writableEnded?(r&&n(r),this):this._writableState.constructed?(this._doEnd(e,t,r),this):(this._pendingEnd={chunk:e,encoding:t,callback:r},this)}cork(){this.writableCorked++}uncork(){this.writableCorked>0&&(this.writableCorked--,this.writableCorked===0&&this._corkedBuffer.length>0&&this._flushCorkedBuffer())}_flushCorkedBuffer(){if(this._writev&&this._corkedBuffer.length>1){let e=this._corkedBuffer.splice(0),t=e.map(e=>({chunk:e.chunk,encoding:e.encoding}));this._writev.call(this,t,t=>{for(let t of e)this.writableLength-=this.writableObjectMode?1:chunkLen(t.chunk);if(t){for(let n of e)n.callback(t);this.emit(`error`,t)}else{for(let t of e)t.callback();this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`))}})}else{let e=this._corkedBuffer.splice(0);if(e.length>0){let[t,...n]=e;this._writeBuffer.push(...n),this._doWrite(t.chunk,t.encoding,t.callback)}}}setDefaultEncoding(e){return this._defaultEncoding=e,this}destroy(e){if(this.destroyed)return this;this.destroyed=!0,this.writable=!1,e&&(this._err=e);let cb=e=>{e&&n(()=>this.emit(`error`,e)),n(()=>this.emit(`close`))};return this.
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{Stream_ as e}from"./stream-base.js";import{getDefaultHighWaterMark as t}from"./internal/state.js";import{nextTick as n}from"@gjsify/utils";var r=class Writable_ extends e{static[Symbol.hasInstance](e){let t=this;return t.prototype!==void 0&&Object.prototype.isPrototypeOf.call(t.prototype,e)?!0:t.prototype!==Writable_.prototype||e==null?!1:typeof e.writableHighWaterMark==`number`}writable=!0;writableHighWaterMark;writableLength=0;writableObjectMode;writableEnded=!1;writableFinished=!1;writableCorked=0;writableNeedDrain=!1;destroyed=!1;_err;_writableState={ended:!1,finished:!1,constructed:!0,writing:!1};_corkedBuffer=[];_writeBuffer=[];_pendingConstruct=[];_ending=!1;_endCallback;_pendingEnd=null;_writeImpl;_writev;_finalImpl;_destroyImpl;_constructImpl;_decodeStrings;_defaultEncoding=`utf8`;constructor(e){super(e),this.writableHighWaterMark=e?.highWaterMark??t(e?.objectMode??!1),this.writableObjectMode=e?.objectMode??!1,this._decodeStrings=e?.decodeStrings!==!1,e?.write&&(this._writeImpl=e.write),e?.writev&&(this._writev=e.writev),e?.final&&(this._finalImpl=e.final),e?.destroy&&(this._destroyImpl=e.destroy),e?.construct&&(this._constructImpl=e.construct),(this._constructImpl||this._construct!==Writable_.prototype._construct)&&(this._writableState.constructed=!1,n(()=>{this._construct(e=>{this._writableState.constructed=!0,e?this.destroy(e):this._maybeFlush()})}))}_construct(e){this._constructImpl?this._constructImpl.call(this,e):e()}_write(e,t,n){this._writeImpl?this._writeImpl.call(this,e,t,n):n()}_final(e){this._finalImpl?this._finalImpl.call(this,e):e()}_destroy(e,t){this._destroyImpl?this._destroyImpl.call(this,e,t):t(e)}_maybeFlush(){let e=this._pendingConstruct.splice(0);if(e.length>0){let[t,...n]=e;this._writeBuffer.push(...n),this._doWrite(t.chunk,t.encoding,t.callback)}if(this._pendingEnd){let{chunk:e,encoding:t,callback:n}=this._pendingEnd;this._pendingEnd=null,this._doEnd(e,t,n)}}_doWrite(e,t,r){this._writableState.writing=!0;let i=!0;this._write(e,t,t=>{if(this.writableLength-=this.writableObjectMode?1:chunkLen(e),i){n(()=>{if(t){r(t),this.emit(`error`,t);return}r(),this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`))}),t||this._drainWriteBuffer();return}n(t?()=>{r(t),this.emit(`error`,t),this._drainWriteBuffer()}:()=>{r(),this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`)),this._drainWriteBuffer()})}),i=!1}_drainWriteBuffer(){if(this._writeBuffer.length>0){let e=this._writeBuffer.shift();this._doWrite(e.chunk,e.encoding,e.callback)}else this._writableState.writing=!1,this._maybeFinish()}_maybeFinish(){!this._ending||this._writableState.finished||this._writableState.writing||this._writeBuffer.length>0||(this._ending=!1,this._final(e=>{this.writableFinished=!0,this._writableState.finished=!0,n(()=>{e&&this.emit(`error`,e),this.emit(`finish`),n(()=>this.emit(`close`)),this._endCallback&&this._endCallback()})}))}write(e,t,r){let i,a;if(typeof t==`function`?(i=t,a=this._defaultEncoding):(a=t??this._defaultEncoding,i=r??(()=>{})),this._decodeStrings&&!this.writableObjectMode&&typeof e==`string`){let t=globalThis.Buffer;t&&(e=t.from(e,a),a=`buffer`)}if(typeof e!=`string`&&!this.writableObjectMode){let t=globalThis.Buffer;(t&&t.isBuffer(e)||e instanceof Uint8Array)&&(a=`buffer`)}if(this.writableEnded){let e=Error(`write after end`);return n(()=>{i(e),this.emit(`error`,e)}),!1}if(this.writableLength+=this.writableObjectMode?1:chunkLen(e),this.writableCorked>0)return this._corkedBuffer.push({chunk:e,encoding:a,callback:i}),this.writableLength<this.writableHighWaterMark;if(!this._writableState.constructed)return this._pendingConstruct.push({chunk:e,encoding:a,callback:i}),this.writableLength<this.writableHighWaterMark;let o=this.writableLength<this.writableHighWaterMark;return o||(this.writableNeedDrain=!0),this._writableState.writing?this._writeBuffer.push({chunk:e,encoding:a,callback:i}):this._doWrite(e,a,i),o}_doEnd(e,t,n){e!=null&&this.write(e,t),this.writableEnded=!0,this._writableState.ended=!0,this._ending=!0,this._endCallback=n,this._maybeFinish()}end(e,t,r){return typeof e==`function`&&(r=e,e=void 0),typeof t==`function`&&(r=t,t=void 0),this.writableEnded?(r&&n(r),this):this._writableState.constructed?(this._doEnd(e,t,r),this):(this._pendingEnd={chunk:e,encoding:t,callback:r},this)}cork(){this.writableCorked++}uncork(){this.writableCorked>0&&(this.writableCorked--,this.writableCorked===0&&this._corkedBuffer.length>0&&this._flushCorkedBuffer())}_flushCorkedBuffer(){if(this._writev&&this._corkedBuffer.length>1){let e=this._corkedBuffer.splice(0),t=e.map(e=>({chunk:e.chunk,encoding:e.encoding}));this._writev.call(this,t,t=>{for(let t of e)this.writableLength-=this.writableObjectMode?1:chunkLen(t.chunk);if(t){for(let n of e)n.callback(t);this.emit(`error`,t)}else{for(let t of e)t.callback();this.writableNeedDrain&&this.writableLength<=this.writableHighWaterMark&&(this.writableNeedDrain=!1,this.emit(`drain`))}})}else{let e=this._corkedBuffer.splice(0);if(e.length>0){let[t,...n]=e;this._writeBuffer.push(...n),this._doWrite(t.chunk,t.encoding,t.callback)}}}setDefaultEncoding(e){return this._defaultEncoding=e,this}destroy(e){if(this.destroyed)return this;this.destroyed=!0,this.writable=!1,e&&(this._err=e);let cb=e=>{e&&n(()=>this.emit(`error`,e)),n(()=>this.emit(`close`))};return this._destroy(e??null,cb),this}};function chunkLen(e){if(e==null)return 1;let t=e.length;return typeof t==`number`?t:1}export{r as Writable_};
|
package/lib/types/writable.d.ts
CHANGED
|
@@ -32,6 +32,16 @@ export declare class Writable_ extends Stream_ {
|
|
|
32
32
|
_construct(callback: ErrCallback): void;
|
|
33
33
|
_write(chunk: unknown, encoding: string, callback: ErrCallback): void;
|
|
34
34
|
_final(callback: ErrCallback): void;
|
|
35
|
+
/**
|
|
36
|
+
* Default `_destroy` impl — delegates to the constructor-opt `destroy`
|
|
37
|
+
* callback if one was provided. Subclasses can override this method
|
|
38
|
+
* (Node-spec convention: see lib/internal/streams/writable.js's
|
|
39
|
+
* `_destroy`), and the destroy() machinery will pick up the override
|
|
40
|
+
* automatically. Without this hook, packages like execa that wrap
|
|
41
|
+
* `subprocessStdin._destroy` to spy on cleanup-time exitCode have no
|
|
42
|
+
* way to intercept teardown.
|
|
43
|
+
*/
|
|
44
|
+
_destroy(error: Error | null, callback: ErrCallback): void;
|
|
35
45
|
private _maybeFlush;
|
|
36
46
|
private _doWrite;
|
|
37
47
|
private _drainWriteBuffer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/stream",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.15",
|
|
4
4
|
"description": "Node.js stream module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -47,14 +47,14 @@
|
|
|
47
47
|
"stream"
|
|
48
48
|
],
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@gjsify/cli": "^0.4.
|
|
51
|
-
"@gjsify/unit": "^0.4.
|
|
50
|
+
"@gjsify/cli": "^0.4.15",
|
|
51
|
+
"@gjsify/unit": "^0.4.15",
|
|
52
52
|
"@types/node": "^25.6.2",
|
|
53
53
|
"typescript": "^6.0.3"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@gjsify/events": "^0.4.
|
|
57
|
-
"@gjsify/utils": "^0.4.
|
|
58
|
-
"@gjsify/web-streams": "^0.4.
|
|
56
|
+
"@gjsify/events": "^0.4.15",
|
|
57
|
+
"@gjsify/utils": "^0.4.15",
|
|
58
|
+
"@gjsify/web-streams": "^0.4.15"
|
|
59
59
|
}
|
|
60
60
|
}
|