@gjsify/stream 0.1.7 → 0.1.8
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/callable.js +4 -0
- package/lib/esm/index.js +172 -57
- package/lib/esm/spec-internals.d.js +0 -0
- package/lib/types/callable.d.ts +1 -0
- package/lib/types/callable.spec.d.ts +2 -0
- package/lib/types/consumers/index.spec.d.ts +2 -0
- package/lib/types/edge-cases.spec.d.ts +2 -0
- package/lib/types/index.d.ts +44 -21
- package/lib/types/index.spec.d.ts +2 -0
- package/lib/types/inheritance.spec.d.ts +2 -0
- package/lib/types/pipe.spec.d.ts +2 -0
- package/lib/types/promises/index.spec.d.ts +2 -0
- package/lib/types/transform.spec.d.ts +2 -0
- package/package.json +6 -6
- package/src/callable.spec.ts +157 -0
- package/src/callable.ts +3 -0
- package/src/consumers/index.spec.ts +2 -2
- package/src/index.ts +237 -61
- package/src/inheritance.spec.ts +315 -0
- package/src/pipe.spec.ts +530 -0
- package/src/spec-internals.d.ts +28 -0
- package/src/test.mts +16 -2
- package/src/transform.spec.ts +520 -0
- package/tsconfig.json +1 -3
- package/tsconfig.tsbuildinfo +1 -1
package/lib/esm/index.js
CHANGED
|
@@ -15,50 +15,81 @@ function setDefaultHighWaterMark(objectMode, value) {
|
|
|
15
15
|
defaultHighWaterMark = value;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
|
|
18
|
+
function validateHighWaterMark(name, value) {
|
|
19
|
+
if (value === void 0) return;
|
|
20
|
+
if (typeof value !== "number" || Number.isNaN(value)) {
|
|
21
|
+
const err = new TypeError(`The value of "${name}" is invalid. Received ${value}`);
|
|
22
|
+
err.code = "ERR_INVALID_ARG_VALUE";
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class Stream_ extends EventEmitter {
|
|
19
27
|
constructor(opts) {
|
|
20
28
|
super(opts);
|
|
21
29
|
}
|
|
22
30
|
pipe(destination, options) {
|
|
23
31
|
const source = this;
|
|
24
32
|
const doEnd = options?.end !== false;
|
|
33
|
+
let drainListenerAdded = false;
|
|
34
|
+
const ondrain = () => {
|
|
35
|
+
drainListenerAdded = false;
|
|
36
|
+
destination.removeListener("drain", ondrain);
|
|
37
|
+
if (typeof source.resume === "function") {
|
|
38
|
+
source.resume();
|
|
39
|
+
}
|
|
40
|
+
};
|
|
25
41
|
const ondata = (chunk) => {
|
|
26
42
|
if (destination.writable) {
|
|
27
43
|
if (destination.write(chunk) === false && typeof source.pause === "function") {
|
|
28
44
|
source.pause();
|
|
45
|
+
if (!drainListenerAdded) {
|
|
46
|
+
drainListenerAdded = true;
|
|
47
|
+
destination.on("drain", ondrain);
|
|
48
|
+
}
|
|
29
49
|
}
|
|
30
50
|
}
|
|
31
51
|
};
|
|
32
52
|
source.on("data", ondata);
|
|
33
|
-
|
|
34
|
-
if (typeof source.resume === "function") {
|
|
35
|
-
source.resume();
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
destination.on("drain", ondrain);
|
|
53
|
+
let didEnd = false;
|
|
39
54
|
const onend = () => {
|
|
55
|
+
if (didEnd) return;
|
|
56
|
+
didEnd = true;
|
|
57
|
+
if (doEnd) destination.end();
|
|
58
|
+
};
|
|
59
|
+
const onclose = () => {
|
|
60
|
+
if (didEnd) return;
|
|
61
|
+
didEnd = true;
|
|
40
62
|
if (doEnd) {
|
|
41
|
-
destination.
|
|
63
|
+
if (!(source instanceof Readable) && typeof destination.destroy === "function") {
|
|
64
|
+
destination.destroy();
|
|
65
|
+
}
|
|
42
66
|
}
|
|
43
67
|
};
|
|
44
68
|
if (doEnd) {
|
|
45
69
|
source.on("end", onend);
|
|
70
|
+
source.on("close", onclose);
|
|
46
71
|
}
|
|
47
72
|
const cleanup = () => {
|
|
48
73
|
source.removeListener("data", ondata);
|
|
49
|
-
destination.removeListener("drain", ondrain);
|
|
74
|
+
if (drainListenerAdded) destination.removeListener("drain", ondrain);
|
|
50
75
|
source.removeListener("end", onend);
|
|
76
|
+
source.removeListener("close", onclose);
|
|
77
|
+
source.removeListener("end", cleanup);
|
|
78
|
+
source.removeListener("close", cleanup);
|
|
79
|
+
destination.removeListener("close", cleanup);
|
|
51
80
|
};
|
|
81
|
+
source.on("end", cleanup);
|
|
52
82
|
source.on("close", cleanup);
|
|
53
83
|
destination.on("close", cleanup);
|
|
54
84
|
if (source instanceof Readable) {
|
|
55
|
-
source._pipeDests.push({ dest: destination,
|
|
85
|
+
source._pipeDests.push({ dest: destination, cleanup });
|
|
86
|
+
source._readableState.pipes.push(destination);
|
|
56
87
|
}
|
|
57
88
|
destination.emit("pipe", source);
|
|
58
89
|
return destination;
|
|
59
90
|
}
|
|
60
91
|
}
|
|
61
|
-
class
|
|
92
|
+
class Readable_ extends Stream_ {
|
|
62
93
|
readable = true;
|
|
63
94
|
readableFlowing = null;
|
|
64
95
|
readableLength = 0;
|
|
@@ -71,7 +102,7 @@ class Readable extends Stream {
|
|
|
71
102
|
/** @internal Tracked pipe destinations for unpipe. */
|
|
72
103
|
_pipeDests = [];
|
|
73
104
|
_buffer = [];
|
|
74
|
-
_readableState = { ended: false, endEmitted: false, reading: false, constructed: true };
|
|
105
|
+
_readableState = { ended: false, endEmitted: false, reading: false, constructed: true, highWaterMark: 0, objectMode: false, pipes: [] };
|
|
75
106
|
_readablePending = false;
|
|
76
107
|
_readImpl;
|
|
77
108
|
_destroyImpl;
|
|
@@ -81,6 +112,8 @@ class Readable extends Stream {
|
|
|
81
112
|
this.readableHighWaterMark = opts?.highWaterMark ?? getDefaultHighWaterMark(opts?.objectMode ?? false);
|
|
82
113
|
this.readableEncoding = opts?.encoding ?? null;
|
|
83
114
|
this.readableObjectMode = opts?.objectMode ?? false;
|
|
115
|
+
this._readableState.highWaterMark = this.readableHighWaterMark;
|
|
116
|
+
this._readableState.objectMode = this.readableObjectMode;
|
|
84
117
|
if (opts?.read) this._readImpl = opts.read;
|
|
85
118
|
if (opts?.destroy) this._destroyImpl = opts.destroy;
|
|
86
119
|
if (opts?.construct) this._constructImpl = opts.construct;
|
|
@@ -194,6 +227,17 @@ class Readable extends Stream {
|
|
|
194
227
|
this._scheduleReadable();
|
|
195
228
|
return false;
|
|
196
229
|
}
|
|
230
|
+
if (!this.readableObjectMode) {
|
|
231
|
+
const isValid = typeof chunk === "string" || ArrayBuffer.isView(chunk);
|
|
232
|
+
if (!isValid) {
|
|
233
|
+
const err = Object.assign(
|
|
234
|
+
new TypeError(`Invalid non-string/buffer chunk type: ${typeof chunk}`),
|
|
235
|
+
{ code: "ERR_INVALID_ARG_TYPE" }
|
|
236
|
+
);
|
|
237
|
+
nextTick(() => this.emit("error", err));
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
197
241
|
this._buffer.push(chunk);
|
|
198
242
|
this.readableLength += this.readableObjectMode ? 1 : chunk.length ?? 1;
|
|
199
243
|
if (this.readableFlowing && !this._flowing) {
|
|
@@ -299,6 +343,7 @@ class Readable extends Stream {
|
|
|
299
343
|
state.dest.emit("unpipe", this);
|
|
300
344
|
}
|
|
301
345
|
this._pipeDests = [];
|
|
346
|
+
this._readableState.pipes = [];
|
|
302
347
|
this.readableFlowing = false;
|
|
303
348
|
} else {
|
|
304
349
|
const idx = this._pipeDests.findIndex((s) => s.dest === destination);
|
|
@@ -306,6 +351,8 @@ class Readable extends Stream {
|
|
|
306
351
|
const state = this._pipeDests[idx];
|
|
307
352
|
state.cleanup();
|
|
308
353
|
this._pipeDests.splice(idx, 1);
|
|
354
|
+
const pipeIdx = this._readableState.pipes.indexOf(destination);
|
|
355
|
+
if (pipeIdx !== -1) this._readableState.pipes.splice(pipeIdx, 1);
|
|
309
356
|
destination.emit("unpipe", this);
|
|
310
357
|
if (this._pipeDests.length === 0) {
|
|
311
358
|
this.readableFlowing = false;
|
|
@@ -314,6 +361,13 @@ class Readable extends Stream {
|
|
|
314
361
|
}
|
|
315
362
|
return this;
|
|
316
363
|
}
|
|
364
|
+
_destroy(error, callback) {
|
|
365
|
+
if (this._destroyImpl) {
|
|
366
|
+
this._destroyImpl.call(this, error, callback);
|
|
367
|
+
} else {
|
|
368
|
+
callback(error ?? void 0);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
317
371
|
destroy(error) {
|
|
318
372
|
if (this.destroyed) return this;
|
|
319
373
|
this.destroyed = true;
|
|
@@ -323,7 +377,9 @@ class Readable extends Stream {
|
|
|
323
377
|
if (err) nextTick(() => this.emit("error", err));
|
|
324
378
|
nextTick(() => this.emit("close"));
|
|
325
379
|
};
|
|
326
|
-
if (this
|
|
380
|
+
if (Object.prototype.hasOwnProperty.call(this, "_destroy")) {
|
|
381
|
+
this._destroy(error ?? null, cb);
|
|
382
|
+
} else if (this._destroyImpl) {
|
|
327
383
|
this._destroyImpl.call(this, error ?? null, cb);
|
|
328
384
|
} else {
|
|
329
385
|
cb(error);
|
|
@@ -412,7 +468,19 @@ class Readable extends Stream {
|
|
|
412
468
|
return readable;
|
|
413
469
|
}
|
|
414
470
|
}
|
|
415
|
-
class
|
|
471
|
+
class Writable_ extends Stream_ {
|
|
472
|
+
// Allow `duplex instanceof Writable` to return true even though Duplex inherits
|
|
473
|
+
// from Readable_ only. Mirrors Node.js: standard prototype-chain check first,
|
|
474
|
+
// then duck-type fallback — but only when checking against Writable itself, not
|
|
475
|
+
// against a user subclass. Because `Writable` is exported as a makeCallable Proxy,
|
|
476
|
+
// `this === Writable_` fails for `obj instanceof Writable`; however the Proxy's
|
|
477
|
+
// default `get` trap forwards `.prototype` straight to the target, so the
|
|
478
|
+
// prototype reference check below correctly recognises both.
|
|
479
|
+
static [Symbol.hasInstance](obj) {
|
|
480
|
+
if (typeof this.prototype !== "undefined" && Object.prototype.isPrototypeOf.call(this.prototype, obj)) return true;
|
|
481
|
+
if (this.prototype !== Writable_.prototype) return false;
|
|
482
|
+
return obj !== null && obj !== void 0 && typeof obj.writableHighWaterMark === "number";
|
|
483
|
+
}
|
|
416
484
|
writable = true;
|
|
417
485
|
writableHighWaterMark;
|
|
418
486
|
writableLength = 0;
|
|
@@ -509,7 +577,7 @@ class Writable extends Stream {
|
|
|
509
577
|
} else {
|
|
510
578
|
nextTick(() => {
|
|
511
579
|
callback();
|
|
512
|
-
if (this.writableNeedDrain && this.writableLength
|
|
580
|
+
if (this.writableNeedDrain && this.writableLength <= this.writableHighWaterMark) {
|
|
513
581
|
this.writableNeedDrain = false;
|
|
514
582
|
this.emit("drain");
|
|
515
583
|
}
|
|
@@ -645,7 +713,7 @@ class Writable extends Stream {
|
|
|
645
713
|
this.emit("error", err);
|
|
646
714
|
} else {
|
|
647
715
|
for (const b of buffered) b.callback();
|
|
648
|
-
if (this.writableNeedDrain && this.writableLength
|
|
716
|
+
if (this.writableNeedDrain && this.writableLength <= this.writableHighWaterMark) {
|
|
649
717
|
this.writableNeedDrain = false;
|
|
650
718
|
this.emit("drain");
|
|
651
719
|
}
|
|
@@ -680,7 +748,7 @@ class Writable extends Stream {
|
|
|
680
748
|
return this;
|
|
681
749
|
}
|
|
682
750
|
}
|
|
683
|
-
class
|
|
751
|
+
class Duplex_ extends Readable_ {
|
|
684
752
|
writable = true;
|
|
685
753
|
writableHighWaterMark;
|
|
686
754
|
writableLength = 0;
|
|
@@ -691,6 +759,8 @@ class Duplex extends Readable {
|
|
|
691
759
|
writableNeedDrain = false;
|
|
692
760
|
allowHalfOpen;
|
|
693
761
|
_decodeStrings;
|
|
762
|
+
// Exposed writable-side state (mirrors Node.js _writableState for split HWM tests)
|
|
763
|
+
_writableState = { highWaterMark: 0, objectMode: false };
|
|
694
764
|
_duplexCorkedBuffer = [];
|
|
695
765
|
_writeImpl;
|
|
696
766
|
_finalImpl;
|
|
@@ -699,8 +769,24 @@ class Duplex extends Readable {
|
|
|
699
769
|
_pendingEndCb = null;
|
|
700
770
|
constructor(opts) {
|
|
701
771
|
super(opts);
|
|
702
|
-
|
|
772
|
+
validateHighWaterMark("writableHighWaterMark", opts?.writableHighWaterMark);
|
|
773
|
+
validateHighWaterMark("readableHighWaterMark", opts?.readableHighWaterMark);
|
|
703
774
|
this.writableObjectMode = opts?.writableObjectMode ?? opts?.objectMode ?? false;
|
|
775
|
+
this.writableHighWaterMark = opts?.highWaterMark ?? opts?.writableHighWaterMark ?? getDefaultHighWaterMark(this.writableObjectMode);
|
|
776
|
+
this._writableState.highWaterMark = this.writableHighWaterMark;
|
|
777
|
+
this._writableState.objectMode = this.writableObjectMode;
|
|
778
|
+
if (opts?.highWaterMark === void 0 && opts?.readableHighWaterMark !== void 0) {
|
|
779
|
+
this.readableHighWaterMark = opts.readableHighWaterMark;
|
|
780
|
+
this._readableState.highWaterMark = opts.readableHighWaterMark;
|
|
781
|
+
}
|
|
782
|
+
if (opts?.readableObjectMode !== void 0) {
|
|
783
|
+
this.readableObjectMode = opts.readableObjectMode;
|
|
784
|
+
this._readableState.objectMode = opts.readableObjectMode;
|
|
785
|
+
if (opts?.readableHighWaterMark === void 0 && opts?.highWaterMark === void 0) {
|
|
786
|
+
this.readableHighWaterMark = getDefaultHighWaterMark(opts.readableObjectMode);
|
|
787
|
+
this._readableState.highWaterMark = this.readableHighWaterMark;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
704
790
|
this.allowHalfOpen = opts?.allowHalfOpen !== false;
|
|
705
791
|
this._decodeStrings = opts?.decodeStrings !== false;
|
|
706
792
|
if (opts?.write) this._writeImpl = opts.write;
|
|
@@ -785,7 +871,7 @@ class Duplex extends Readable {
|
|
|
785
871
|
} else {
|
|
786
872
|
nextTick(() => {
|
|
787
873
|
cb();
|
|
788
|
-
if (this.writableNeedDrain && this.writableLength
|
|
874
|
+
if (this.writableNeedDrain && this.writableLength <= this.writableHighWaterMark) {
|
|
789
875
|
this.writableNeedDrain = false;
|
|
790
876
|
this.emit("drain");
|
|
791
877
|
}
|
|
@@ -815,11 +901,13 @@ class Duplex extends Readable {
|
|
|
815
901
|
const doFinal = () => {
|
|
816
902
|
this._final((err) => {
|
|
817
903
|
this.writableFinished = true;
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
904
|
+
this._doPrefinishHooks(() => {
|
|
905
|
+
nextTick(() => {
|
|
906
|
+
if (err) this.emit("error", err);
|
|
907
|
+
this.emit("finish");
|
|
908
|
+
nextTick(() => this.emit("close"));
|
|
909
|
+
if (callback) callback();
|
|
910
|
+
});
|
|
823
911
|
});
|
|
824
912
|
});
|
|
825
913
|
};
|
|
@@ -830,6 +918,10 @@ class Duplex extends Readable {
|
|
|
830
918
|
}
|
|
831
919
|
return this;
|
|
832
920
|
}
|
|
921
|
+
/** Hook for subclasses to run logic between _final and 'finish'. Default: no-op. */
|
|
922
|
+
_doPrefinishHooks(cb) {
|
|
923
|
+
cb();
|
|
924
|
+
}
|
|
833
925
|
cork() {
|
|
834
926
|
this.writableCorked++;
|
|
835
927
|
}
|
|
@@ -849,7 +941,7 @@ class Duplex extends Readable {
|
|
|
849
941
|
}
|
|
850
942
|
});
|
|
851
943
|
}
|
|
852
|
-
if (this.writableNeedDrain && this.writableLength
|
|
944
|
+
if (this.writableNeedDrain && this.writableLength <= this.writableHighWaterMark) {
|
|
853
945
|
this.writableNeedDrain = false;
|
|
854
946
|
nextTick(() => this.emit("drain"));
|
|
855
947
|
}
|
|
@@ -861,44 +953,50 @@ class Duplex extends Readable {
|
|
|
861
953
|
return this;
|
|
862
954
|
}
|
|
863
955
|
}
|
|
864
|
-
class
|
|
865
|
-
_transformImpl;
|
|
866
|
-
_flushImpl;
|
|
956
|
+
class Transform_ extends Duplex_ {
|
|
867
957
|
constructor(opts) {
|
|
868
|
-
super({
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
});
|
|
873
|
-
if (opts?.transform) this._transformImpl = opts.transform;
|
|
874
|
-
if (opts?.flush) this._flushImpl = opts.flush;
|
|
958
|
+
super({ ...opts, write: void 0, final: void 0 });
|
|
959
|
+
if (opts?.transform) this._transform = opts.transform;
|
|
960
|
+
if (opts?.flush) this._flush = opts.flush;
|
|
961
|
+
if (opts?.final) this._final = opts.final;
|
|
875
962
|
}
|
|
876
|
-
_transform(
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
963
|
+
_transform(_chunk, _encoding, _callback) {
|
|
964
|
+
const err = Object.assign(
|
|
965
|
+
new Error("The _transform() method is not implemented"),
|
|
966
|
+
{ code: "ERR_METHOD_NOT_IMPLEMENTED" }
|
|
967
|
+
);
|
|
968
|
+
throw err;
|
|
882
969
|
}
|
|
883
970
|
_flush(callback) {
|
|
884
|
-
|
|
885
|
-
this._flushImpl.call(this, callback);
|
|
886
|
-
} else {
|
|
887
|
-
callback();
|
|
888
|
-
}
|
|
971
|
+
callback();
|
|
889
972
|
}
|
|
890
973
|
_write(chunk, encoding, callback) {
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
974
|
+
let called = false;
|
|
975
|
+
try {
|
|
976
|
+
this._transform(chunk, encoding, (err, data) => {
|
|
977
|
+
if (called) {
|
|
978
|
+
const e = Object.assign(new Error("Callback called multiple times"), { code: "ERR_MULTIPLE_CALLBACK" });
|
|
979
|
+
nextTick(() => this.emit("error", e));
|
|
980
|
+
return;
|
|
981
|
+
}
|
|
982
|
+
called = true;
|
|
983
|
+
if (err) {
|
|
984
|
+
callback(err);
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
987
|
+
if (data !== void 0 && data !== null) {
|
|
988
|
+
this.push(data);
|
|
989
|
+
}
|
|
990
|
+
callback();
|
|
991
|
+
});
|
|
992
|
+
} catch (err) {
|
|
993
|
+
if (err?.code === "ERR_METHOD_NOT_IMPLEMENTED") throw err;
|
|
994
|
+
callback(err);
|
|
995
|
+
}
|
|
901
996
|
}
|
|
997
|
+
// Transform's built-in _final: calls _flush then pushes null.
|
|
998
|
+
// This is the default; when the user provides opts.final it is overridden on
|
|
999
|
+
// the instance and _doPrefinishHooks ensures _flush is still called after it.
|
|
902
1000
|
_final(callback) {
|
|
903
1001
|
this._flush((err, data) => {
|
|
904
1002
|
if (err) {
|
|
@@ -912,8 +1010,18 @@ class Transform extends Duplex {
|
|
|
912
1010
|
callback();
|
|
913
1011
|
});
|
|
914
1012
|
}
|
|
1013
|
+
// When a user-provided _final overrides the prototype method, we still need
|
|
1014
|
+
// to call the built-in flush+push-null logic (mirroring Node.js's prefinish).
|
|
1015
|
+
_doPrefinishHooks(cb) {
|
|
1016
|
+
const protoFinal = Transform_.prototype._final;
|
|
1017
|
+
if (this._final !== protoFinal) {
|
|
1018
|
+
protoFinal.call(this, cb);
|
|
1019
|
+
} else {
|
|
1020
|
+
cb();
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
915
1023
|
}
|
|
916
|
-
class
|
|
1024
|
+
class PassThrough_ extends Transform_ {
|
|
917
1025
|
constructor(opts) {
|
|
918
1026
|
super({
|
|
919
1027
|
...opts,
|
|
@@ -1058,6 +1166,13 @@ function isErrored(stream) {
|
|
|
1058
1166
|
if (s.destroyed === true && typeof s.writable === "boolean" && s.writable === false) return true;
|
|
1059
1167
|
return false;
|
|
1060
1168
|
}
|
|
1169
|
+
import { makeCallable } from "./callable.js";
|
|
1170
|
+
const Stream = makeCallable(Stream_);
|
|
1171
|
+
const Readable = makeCallable(Readable_);
|
|
1172
|
+
const Writable = makeCallable(Writable_);
|
|
1173
|
+
const Duplex = makeCallable(Duplex_);
|
|
1174
|
+
const Transform = makeCallable(Transform_);
|
|
1175
|
+
const PassThrough = makeCallable(PassThrough_);
|
|
1061
1176
|
const _default = Object.assign(Stream, {
|
|
1062
1177
|
Stream,
|
|
1063
1178
|
Readable,
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { makeCallable } from '@gjsify/utils';
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,19 +13,15 @@ export type { ReadableOptions, WritableOptions, DuplexOptions, TransformOptions,
|
|
|
13
13
|
/** Tracked pipe destination for unpipe support. */
|
|
14
14
|
interface PipeState {
|
|
15
15
|
dest: Writable;
|
|
16
|
-
ondata: (chunk: unknown) => void;
|
|
17
|
-
ondrain: () => void;
|
|
18
|
-
onend: () => void;
|
|
19
16
|
cleanup: () => void;
|
|
20
|
-
doEnd: boolean;
|
|
21
17
|
}
|
|
22
|
-
|
|
18
|
+
declare class Stream_ extends EventEmitter {
|
|
23
19
|
constructor(opts?: StreamOptions);
|
|
24
20
|
pipe<T extends Writable>(destination: T, options?: {
|
|
25
21
|
end?: boolean;
|
|
26
22
|
}): T;
|
|
27
23
|
}
|
|
28
|
-
|
|
24
|
+
declare class Readable_ extends Stream_ {
|
|
29
25
|
readable: boolean;
|
|
30
26
|
readableFlowing: boolean | null;
|
|
31
27
|
readableLength: number;
|
|
@@ -38,7 +34,15 @@ export declare class Readable extends Stream {
|
|
|
38
34
|
/** @internal Tracked pipe destinations for unpipe. */
|
|
39
35
|
_pipeDests: PipeState[];
|
|
40
36
|
private _buffer;
|
|
41
|
-
|
|
37
|
+
_readableState: {
|
|
38
|
+
ended: boolean;
|
|
39
|
+
endEmitted: boolean;
|
|
40
|
+
reading: boolean;
|
|
41
|
+
constructed: boolean;
|
|
42
|
+
highWaterMark: number;
|
|
43
|
+
objectMode: boolean;
|
|
44
|
+
pipes: any[];
|
|
45
|
+
};
|
|
42
46
|
private _readablePending;
|
|
43
47
|
private _readImpl;
|
|
44
48
|
private _destroyImpl;
|
|
@@ -63,11 +67,13 @@ export declare class Readable extends Stream {
|
|
|
63
67
|
private _flow;
|
|
64
68
|
isPaused(): boolean;
|
|
65
69
|
unpipe(destination?: Writable): this;
|
|
70
|
+
_destroy(error: Error | null, callback: (error?: Error | null) => void): void;
|
|
66
71
|
destroy(error?: Error): this;
|
|
67
72
|
[Symbol.asyncIterator](): AsyncIterableIterator<unknown>;
|
|
68
73
|
static from(iterable: Iterable<unknown> | AsyncIterable<unknown>, opts?: ReadableOptions): Readable;
|
|
69
74
|
}
|
|
70
|
-
|
|
75
|
+
declare class Writable_ extends Stream_ {
|
|
76
|
+
static [Symbol.hasInstance](obj: any): boolean;
|
|
71
77
|
writable: boolean;
|
|
72
78
|
writableHighWaterMark: number;
|
|
73
79
|
writableLength: number;
|
|
@@ -108,7 +114,7 @@ export declare class Writable extends Stream {
|
|
|
108
114
|
setDefaultEncoding(encoding: string): this;
|
|
109
115
|
destroy(error?: Error): this;
|
|
110
116
|
}
|
|
111
|
-
|
|
117
|
+
declare class Duplex_ extends Readable_ {
|
|
112
118
|
writable: boolean;
|
|
113
119
|
writableHighWaterMark: number;
|
|
114
120
|
writableLength: number;
|
|
@@ -119,6 +125,10 @@ export declare class Duplex extends Readable {
|
|
|
119
125
|
writableNeedDrain: boolean;
|
|
120
126
|
allowHalfOpen: boolean;
|
|
121
127
|
private _decodeStrings;
|
|
128
|
+
_writableState: {
|
|
129
|
+
highWaterMark: number;
|
|
130
|
+
objectMode: boolean;
|
|
131
|
+
};
|
|
122
132
|
private _duplexCorkedBuffer;
|
|
123
133
|
private _writeImpl;
|
|
124
134
|
private _finalImpl;
|
|
@@ -131,20 +141,21 @@ export declare class Duplex extends Readable {
|
|
|
131
141
|
destroy(error?: Error): this;
|
|
132
142
|
write(chunk: any, encoding?: string | ((error?: Error | null) => void), callback?: (error?: Error | null) => void): boolean;
|
|
133
143
|
end(chunk?: any, encoding?: string | (() => void), callback?: () => void): this;
|
|
144
|
+
/** Hook for subclasses to run logic between _final and 'finish'. Default: no-op. */
|
|
145
|
+
protected _doPrefinishHooks(cb: () => void): void;
|
|
134
146
|
cork(): void;
|
|
135
147
|
uncork(): void;
|
|
136
148
|
setDefaultEncoding(encoding: string): this;
|
|
137
149
|
}
|
|
138
|
-
|
|
139
|
-
private _transformImpl;
|
|
140
|
-
private _flushImpl;
|
|
150
|
+
declare class Transform_ extends Duplex_ {
|
|
141
151
|
constructor(opts?: TransformOptions);
|
|
142
|
-
_transform(
|
|
152
|
+
_transform(_chunk: any, _encoding: string, _callback: (error?: Error | null, data?: any) => void): void;
|
|
143
153
|
_flush(callback: (error?: Error | null, data?: any) => void): void;
|
|
144
154
|
_write(chunk: any, encoding: string, callback: (error?: Error | null) => void): void;
|
|
145
155
|
_final(callback: (error?: Error | null) => void): void;
|
|
156
|
+
protected _doPrefinishHooks(cb: () => void): void;
|
|
146
157
|
}
|
|
147
|
-
|
|
158
|
+
declare class PassThrough_ extends Transform_ {
|
|
148
159
|
constructor(opts?: TransformOptions);
|
|
149
160
|
}
|
|
150
161
|
type PipelineCallback = (err: Error | null) => void;
|
|
@@ -161,13 +172,25 @@ export declare function isWritable(stream: unknown): boolean;
|
|
|
161
172
|
export declare function isDestroyed(stream: unknown): boolean;
|
|
162
173
|
export declare function isDisturbed(stream: unknown): boolean;
|
|
163
174
|
export declare function isErrored(stream: unknown): boolean;
|
|
164
|
-
declare const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
175
|
+
export declare const Stream: typeof Stream_;
|
|
176
|
+
export declare const Readable: typeof Readable_;
|
|
177
|
+
export declare const Writable: typeof Writable_;
|
|
178
|
+
export declare const Duplex: typeof Duplex_;
|
|
179
|
+
export declare const Transform: typeof Transform_;
|
|
180
|
+
export declare const PassThrough: typeof PassThrough_;
|
|
181
|
+
export type Stream = Stream_;
|
|
182
|
+
export type Readable = Readable_;
|
|
183
|
+
export type Writable = Writable_;
|
|
184
|
+
export type Duplex = Duplex_;
|
|
185
|
+
export type Transform = Transform_;
|
|
186
|
+
export type PassThrough = PassThrough_;
|
|
187
|
+
declare const _default: typeof Stream_ & {
|
|
188
|
+
Stream: typeof Stream_;
|
|
189
|
+
Readable: typeof Readable_;
|
|
190
|
+
Writable: typeof Writable_;
|
|
191
|
+
Duplex: typeof Duplex_;
|
|
192
|
+
Transform: typeof Transform_;
|
|
193
|
+
PassThrough: typeof PassThrough_;
|
|
171
194
|
pipeline: typeof pipeline;
|
|
172
195
|
finished: typeof finished;
|
|
173
196
|
addAbortSignal: typeof addAbortSignal;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/stream",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Node.js stream module for Gjs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"stream"
|
|
44
44
|
],
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@gjsify/cli": "^0.1.
|
|
47
|
-
"@gjsify/unit": "^0.1.
|
|
46
|
+
"@gjsify/cli": "^0.1.8",
|
|
47
|
+
"@gjsify/unit": "^0.1.8",
|
|
48
48
|
"@types/node": "^25.5.2",
|
|
49
49
|
"typescript": "^6.0.2"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@gjsify/events": "^0.1.
|
|
53
|
-
"@gjsify/utils": "^0.1.
|
|
54
|
-
"@gjsify/web-streams": "^0.1.
|
|
52
|
+
"@gjsify/events": "^0.1.8",
|
|
53
|
+
"@gjsify/utils": "^0.1.8",
|
|
54
|
+
"@gjsify/web-streams": "^0.1.8"
|
|
55
55
|
}
|
|
56
56
|
}
|