@gjsify/stream 0.4.0 → 0.4.4
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/package.json +55 -51
- package/src/callable.spec.ts +0 -196
- package/src/callable.ts +0 -3
- package/src/consumers/index.spec.ts +0 -107
- package/src/consumers/index.ts +0 -39
- package/src/duplex.ts +0 -317
- package/src/edge-cases.spec.ts +0 -593
- package/src/index.spec.ts +0 -2252
- package/src/index.ts +0 -92
- package/src/inheritance.spec.ts +0 -315
- package/src/internal/state.ts +0 -34
- package/src/internal/types.ts +0 -31
- package/src/passthrough.ts +0 -19
- package/src/pipe.spec.ts +0 -530
- package/src/promises/index.spec.ts +0 -140
- package/src/promises/index.ts +0 -31
- package/src/readable.ts +0 -580
- package/src/spec-internals.d.ts +0 -28
- package/src/stream-base.ts +0 -37
- package/src/test.mts +0 -26
- package/src/transform.spec.ts +0 -520
- package/src/transform.ts +0 -108
- package/src/utils/finished.ts +0 -156
- package/src/utils/pipe.ts +0 -113
- package/src/utils/pipeline.ts +0 -59
- package/src/web/index.ts +0 -32
- package/src/writable.ts +0 -398
- package/tsconfig.json +0 -29
- package/tsconfig.tsbuildinfo +0 -1
package/src/index.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// Reference: Node.js lib/stream.js, lib/internal/streams/*.js
|
|
2
|
-
// Reimplemented for GJS using EventEmitter and microtask scheduling.
|
|
3
|
-
//
|
|
4
|
-
// This file is the public barrel — actual implementations live per-class:
|
|
5
|
-
// - stream-base.ts Stream_ (root EventEmitter + pipe glue)
|
|
6
|
-
// - readable.ts Readable_ (+ Readable_._autoClose protected hook)
|
|
7
|
-
// - writable.ts Writable_ (+ FIFO drain queue)
|
|
8
|
-
// - duplex.ts Duplex_ (Readable_ + writable-half re-implementation)
|
|
9
|
-
// - transform.ts Transform_
|
|
10
|
-
// - passthrough.ts PassThrough_
|
|
11
|
-
// - utils/pipe.ts Stream.pipe() helper
|
|
12
|
-
// - utils/pipeline.ts pipeline()
|
|
13
|
-
// - utils/finished.ts finished(), addAbortSignal(), is{Readable,…}()
|
|
14
|
-
// - internal/state.ts module-singleton defaults + validateHighWaterMark
|
|
15
|
-
// - internal/types.ts shared interfaces
|
|
16
|
-
//
|
|
17
|
-
// Public class names are makeCallable Proxy wrappers around the underscore-suffixed
|
|
18
|
-
// internal classes (`Stream_`, `Readable_`, …) so legacy CJS consumers can do
|
|
19
|
-
// `Stream.call(this)` (npm `send`, `util.inherits(Sub, Stream)`, our own
|
|
20
|
-
// `@gjsify/crypto` `Hash.copy()`). See `./callable.ts` for the rationale.
|
|
21
|
-
//
|
|
22
|
-
// The historical default export shape — the Stream constructor with all classes
|
|
23
|
-
// + helpers attached as static properties — is preserved for `cjs-compat.cjs`.
|
|
24
|
-
|
|
25
|
-
import { makeCallable } from './callable.js';
|
|
26
|
-
|
|
27
|
-
import { Stream_ } from './stream-base.js';
|
|
28
|
-
import { Readable_ } from './readable.js';
|
|
29
|
-
// Side-effect import: wires Stream_.prototype.pipe → pipe() at load time.
|
|
30
|
-
// See ./stream-base.ts (_setPipeImpl) for the late-binding rationale.
|
|
31
|
-
import './utils/pipe.js';
|
|
32
|
-
import { Writable_ } from './writable.js';
|
|
33
|
-
import { Duplex_ } from './duplex.js';
|
|
34
|
-
import { Transform_ } from './transform.js';
|
|
35
|
-
import { PassThrough_ } from './passthrough.js';
|
|
36
|
-
import { pipeline } from './utils/pipeline.js';
|
|
37
|
-
import { finished, addAbortSignal, isReadable, isWritable, isDestroyed, isDisturbed, isErrored } from './utils/finished.js';
|
|
38
|
-
import { getDefaultHighWaterMark, setDefaultHighWaterMark } from './internal/state.js';
|
|
39
|
-
|
|
40
|
-
// ---- Re-exports of internal helpers ----
|
|
41
|
-
|
|
42
|
-
export { getDefaultHighWaterMark, setDefaultHighWaterMark };
|
|
43
|
-
export { pipeline, finished, addAbortSignal };
|
|
44
|
-
export { isReadable, isWritable, isDestroyed, isDisturbed, isErrored };
|
|
45
|
-
|
|
46
|
-
// ---- Type-only re-exports ----
|
|
47
|
-
|
|
48
|
-
export type { ReadableOptions, WritableOptions, DuplexOptions, TransformOptions, FinishedOptions } from 'node:stream';
|
|
49
|
-
export type { StreamOptions } from './internal/types.js';
|
|
50
|
-
|
|
51
|
-
// ---- Class wrappers (callable for legacy CJS) ----
|
|
52
|
-
|
|
53
|
-
export const Stream = makeCallable(Stream_) as typeof Stream_;
|
|
54
|
-
export const Readable = makeCallable(Readable_) as typeof Readable_;
|
|
55
|
-
export const Writable = makeCallable(Writable_) as typeof Writable_;
|
|
56
|
-
export const Duplex = makeCallable(Duplex_) as typeof Duplex_;
|
|
57
|
-
export const Transform = makeCallable(Transform_) as typeof Transform_;
|
|
58
|
-
export const PassThrough = makeCallable(PassThrough_) as typeof PassThrough_;
|
|
59
|
-
|
|
60
|
-
export type Stream = Stream_;
|
|
61
|
-
export type Readable = Readable_;
|
|
62
|
-
export type Writable = Writable_;
|
|
63
|
-
export type Duplex = Duplex_;
|
|
64
|
-
export type Transform = Transform_;
|
|
65
|
-
export type PassThrough = PassThrough_;
|
|
66
|
-
|
|
67
|
-
// ---- Default export ----
|
|
68
|
-
//
|
|
69
|
-
// Node returns the Stream constructor with sub-classes + helpers hung off it.
|
|
70
|
-
// `cjs-compat.cjs` resolves `mod.default || mod` to this exact value, so the
|
|
71
|
-
// legacy `util.inherits(Sub, require('stream'))` pattern keeps working.
|
|
72
|
-
|
|
73
|
-
const _default = Object.assign(Stream, {
|
|
74
|
-
Stream,
|
|
75
|
-
Readable,
|
|
76
|
-
Writable,
|
|
77
|
-
Duplex,
|
|
78
|
-
Transform,
|
|
79
|
-
PassThrough,
|
|
80
|
-
pipeline,
|
|
81
|
-
finished,
|
|
82
|
-
addAbortSignal,
|
|
83
|
-
isReadable,
|
|
84
|
-
isWritable,
|
|
85
|
-
isDestroyed,
|
|
86
|
-
isDisturbed,
|
|
87
|
-
isErrored,
|
|
88
|
-
getDefaultHighWaterMark,
|
|
89
|
-
setDefaultHighWaterMark,
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
export default _default;
|
package/src/inheritance.spec.ts
DELETED
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
// Stream and util.inherits inheritance tests.
|
|
2
|
-
//
|
|
3
|
-
// Ported from:
|
|
4
|
-
// refs/node-test/parallel/test-stream-inheritance.js
|
|
5
|
-
// refs/node-test/parallel/test-util-inherits.js
|
|
6
|
-
// Original: MIT license, Node.js contributors
|
|
7
|
-
// Modifications: adapted to @gjsify/unit, async/await.
|
|
8
|
-
|
|
9
|
-
import { describe, it, expect } from '@gjsify/unit';
|
|
10
|
-
import { Readable, Writable, Duplex, Transform, PassThrough } from 'node:stream';
|
|
11
|
-
import { inherits } from 'node:util';
|
|
12
|
-
|
|
13
|
-
export default async () => {
|
|
14
|
-
|
|
15
|
-
// -------------------------------------------------------------------------
|
|
16
|
-
// instanceof hierarchy
|
|
17
|
-
// -------------------------------------------------------------------------
|
|
18
|
-
await describe('stream inheritance: instanceof checks', async () => {
|
|
19
|
-
await it('Readable is instanceof Readable only', async () => {
|
|
20
|
-
const r = new Readable({ read() {} });
|
|
21
|
-
expect(r instanceof Readable).toBe(true);
|
|
22
|
-
expect(r instanceof Writable).toBe(false);
|
|
23
|
-
expect(r instanceof Duplex).toBe(false);
|
|
24
|
-
expect(r instanceof Transform).toBe(false);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
await it('Writable is instanceof Writable only', async () => {
|
|
28
|
-
const w = new Writable({ write(_c, _e, cb) { cb(); } });
|
|
29
|
-
expect(w instanceof Readable).toBe(false);
|
|
30
|
-
expect(w instanceof Writable).toBe(true);
|
|
31
|
-
expect(w instanceof Duplex).toBe(false);
|
|
32
|
-
expect(w instanceof Transform).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
await it('Duplex is instanceof Readable and Writable and Duplex', async () => {
|
|
36
|
-
const d = new Duplex({ read() {}, write(_c, _e, cb) { cb(); } });
|
|
37
|
-
expect(d instanceof Readable).toBe(true);
|
|
38
|
-
expect(d instanceof Writable).toBe(true);
|
|
39
|
-
expect(d instanceof Duplex).toBe(true);
|
|
40
|
-
expect(d instanceof Transform).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
await it('Transform is instanceof Readable, Writable, Duplex, and Transform', async () => {
|
|
44
|
-
const t = new Transform({ transform(_c, _e, cb) { cb(); } });
|
|
45
|
-
expect(t instanceof Readable).toBe(true);
|
|
46
|
-
expect(t instanceof Writable).toBe(true);
|
|
47
|
-
expect(t instanceof Duplex).toBe(true);
|
|
48
|
-
expect(t instanceof Transform).toBe(true);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
await it('null and undefined are not instanceof Writable', async () => {
|
|
52
|
-
// Cast through unknown — TS rejects `null instanceof X` directly.
|
|
53
|
-
expect((null as unknown as object) instanceof Writable).toBe(false);
|
|
54
|
-
expect((undefined as unknown as object) instanceof Writable).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
await it('PassThrough is instanceof Transform, Duplex, Readable, Writable', async () => {
|
|
58
|
-
const pt = new PassThrough();
|
|
59
|
-
expect(pt instanceof PassThrough).toBe(true);
|
|
60
|
-
expect(pt instanceof Transform).toBe(true);
|
|
61
|
-
expect(pt instanceof Duplex).toBe(true);
|
|
62
|
-
expect(pt instanceof Readable).toBe(true);
|
|
63
|
-
expect(pt instanceof Writable).toBe(true);
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// -------------------------------------------------------------------------
|
|
68
|
-
// Object.setPrototypeOf-based subclass
|
|
69
|
-
// -------------------------------------------------------------------------
|
|
70
|
-
await describe('stream inheritance: Object.setPrototypeOf subclassing', async () => {
|
|
71
|
-
await it('subclass via setPrototypeOf is instanceof parent', async () => {
|
|
72
|
-
function CustomWritable(this: any) {}
|
|
73
|
-
Object.setPrototypeOf(CustomWritable, Writable);
|
|
74
|
-
Object.setPrototypeOf((CustomWritable as any).prototype, Writable.prototype);
|
|
75
|
-
|
|
76
|
-
const cw: any = new (CustomWritable as any)();
|
|
77
|
-
expect(cw instanceof CustomWritable).toBe(true);
|
|
78
|
-
expect(cw instanceof Writable).toBe(true);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
await it('ES6 class extending Writable is instanceof Writable', async () => {
|
|
82
|
-
class MyWritable extends Writable {
|
|
83
|
-
_write(_c: any, _e: any, cb: () => void) { cb(); }
|
|
84
|
-
}
|
|
85
|
-
const mw = new MyWritable();
|
|
86
|
-
expect(mw instanceof Writable).toBe(true);
|
|
87
|
-
expect(mw instanceof MyWritable).toBe(true);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
await it('different Writable subclasses are not cross-instanceof', async () => {
|
|
91
|
-
function CustomWritable(this: any) {}
|
|
92
|
-
Object.setPrototypeOf(CustomWritable, Writable);
|
|
93
|
-
Object.setPrototypeOf((CustomWritable as any).prototype, Writable.prototype);
|
|
94
|
-
|
|
95
|
-
class OtherWritable extends Writable {
|
|
96
|
-
_write(_c: any, _e: any, cb: () => void) { cb(); }
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
expect(new OtherWritable() instanceof (CustomWritable as any)).toBe(false);
|
|
100
|
-
expect(new (CustomWritable as any)() instanceof OtherWritable).toBe(false);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// -------------------------------------------------------------------------
|
|
105
|
-
// util.inherits — single and multi-level
|
|
106
|
-
// -------------------------------------------------------------------------
|
|
107
|
-
await describe('util.inherits: single-level inheritance', async () => {
|
|
108
|
-
await it('sets B.super_ to A', async () => {
|
|
109
|
-
function A(this: any) { this._a = 'a'; }
|
|
110
|
-
(A.prototype as any).a = function() { return this._a; };
|
|
111
|
-
|
|
112
|
-
function B(this: any, value: string) {
|
|
113
|
-
(A as any).call(this);
|
|
114
|
-
this._b = value;
|
|
115
|
-
}
|
|
116
|
-
inherits(B as any, A as any);
|
|
117
|
-
|
|
118
|
-
const desc = Object.getOwnPropertyDescriptor(B, 'super_');
|
|
119
|
-
expect(desc).toBeDefined();
|
|
120
|
-
expect((desc as any).value).toBe(A);
|
|
121
|
-
expect((desc as any).enumerable).toBe(false);
|
|
122
|
-
expect((desc as any).configurable).toBe(true);
|
|
123
|
-
expect((desc as any).writable).toBe(true);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
await it('instance methods from parent are accessible on child', async () => {
|
|
127
|
-
function A(this: any) { this._a = 'a'; }
|
|
128
|
-
(A.prototype as any).a = function() { return this._a; };
|
|
129
|
-
|
|
130
|
-
function B(this: any, value: string) {
|
|
131
|
-
(A as any).call(this);
|
|
132
|
-
this._b = value;
|
|
133
|
-
}
|
|
134
|
-
inherits(B as any, A as any);
|
|
135
|
-
(B.prototype as any).b = function() { return this._b; };
|
|
136
|
-
|
|
137
|
-
const b: any = new (B as any)('hello');
|
|
138
|
-
expect(b.a()).toBe('a');
|
|
139
|
-
expect(b.b()).toBe('hello');
|
|
140
|
-
expect(b.constructor).toBe(B);
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
await describe('util.inherits: two-level inheritance', async () => {
|
|
145
|
-
await it('C inherits from B inherits from A — all methods accessible', async () => {
|
|
146
|
-
function A(this: any) { this._a = 'a'; }
|
|
147
|
-
(A.prototype as any).a = function() { return this._a; };
|
|
148
|
-
|
|
149
|
-
function B(this: any) { (A as any).call(this); this._b = 'b'; }
|
|
150
|
-
inherits(B as any, A as any);
|
|
151
|
-
(B.prototype as any).b = function() { return this._b; };
|
|
152
|
-
|
|
153
|
-
function C(this: any) { (B as any).call(this); this._c = 'c'; }
|
|
154
|
-
inherits(C as any, B as any);
|
|
155
|
-
(C.prototype as any).c = function() { return this._c; };
|
|
156
|
-
(C.prototype as any).getValue = function() { return this.a() + this.b() + this.c(); };
|
|
157
|
-
|
|
158
|
-
expect((C as any).super_).toBe(B);
|
|
159
|
-
|
|
160
|
-
const c: any = new (C as any)();
|
|
161
|
-
expect(c.getValue()).toBe('abc');
|
|
162
|
-
expect(c.constructor).toBe(C);
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
await describe('util.inherits: prototype methods set before inherits()', async () => {
|
|
167
|
-
await it('prototype methods defined before inherits() are preserved', async () => {
|
|
168
|
-
function A(this: any) { this._a = 'a'; }
|
|
169
|
-
(A.prototype as any).a = function() { return this._a; };
|
|
170
|
-
|
|
171
|
-
function B(this: any) { (A as any).call(this); this._b = 'b'; }
|
|
172
|
-
inherits(B as any, A as any);
|
|
173
|
-
(B.prototype as any).b = function() { return this._b; };
|
|
174
|
-
|
|
175
|
-
function D(this: any) { (B as any).call(this); this._d = 'd'; }
|
|
176
|
-
// Set method BEFORE calling inherits
|
|
177
|
-
(D.prototype as any).d = function() { return this._d; };
|
|
178
|
-
inherits(D as any, B as any);
|
|
179
|
-
|
|
180
|
-
expect((D as any).super_).toBe(B);
|
|
181
|
-
const d: any = new (D as any)();
|
|
182
|
-
expect(d.b()).toBe('b');
|
|
183
|
-
expect(d.d()).toBe('d');
|
|
184
|
-
expect(d.constructor).toBe(D);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
await describe('util.inherits: invalid arguments', async () => {
|
|
189
|
-
await it('throws ERR_INVALID_ARG_TYPE when superCtor has no prototype', async () => {
|
|
190
|
-
function A(this: any) {}
|
|
191
|
-
let threw = false;
|
|
192
|
-
let code = '';
|
|
193
|
-
try {
|
|
194
|
-
inherits(A as any, {} as any);
|
|
195
|
-
} catch (e: any) {
|
|
196
|
-
threw = true;
|
|
197
|
-
code = e.code;
|
|
198
|
-
}
|
|
199
|
-
expect(threw).toBe(true);
|
|
200
|
-
expect(code).toBe('ERR_INVALID_ARG_TYPE');
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
await it('throws ERR_INVALID_ARG_TYPE when superCtor is null', async () => {
|
|
204
|
-
function A(this: any) {}
|
|
205
|
-
let threw = false;
|
|
206
|
-
let code = '';
|
|
207
|
-
try {
|
|
208
|
-
inherits(A as any, null as any);
|
|
209
|
-
} catch (e: any) {
|
|
210
|
-
threw = true;
|
|
211
|
-
code = e.code;
|
|
212
|
-
}
|
|
213
|
-
expect(threw).toBe(true);
|
|
214
|
-
expect(code).toBe('ERR_INVALID_ARG_TYPE');
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
await it('throws ERR_INVALID_ARG_TYPE when ctor is null', async () => {
|
|
218
|
-
function A(this: any) {}
|
|
219
|
-
(A.prototype as any).a = function() {};
|
|
220
|
-
let threw = false;
|
|
221
|
-
let code = '';
|
|
222
|
-
try {
|
|
223
|
-
inherits(null as any, A as any);
|
|
224
|
-
} catch (e: any) {
|
|
225
|
-
threw = true;
|
|
226
|
-
code = e.code;
|
|
227
|
-
}
|
|
228
|
-
expect(threw).toBe(true);
|
|
229
|
-
expect(code).toBe('ERR_INVALID_ARG_TYPE');
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
// -------------------------------------------------------------------------
|
|
234
|
-
// util.inherits + stream classes — integration
|
|
235
|
-
// -------------------------------------------------------------------------
|
|
236
|
-
await describe('util.inherits + stream: practical subclassing', async () => {
|
|
237
|
-
await it('function-based Readable subclass via inherits works', async () => {
|
|
238
|
-
function NumberSource(this: any, numbers: number[]) {
|
|
239
|
-
Readable.call(this, { objectMode: true });
|
|
240
|
-
this._numbers = numbers.slice();
|
|
241
|
-
}
|
|
242
|
-
inherits(NumberSource as any, Readable as any);
|
|
243
|
-
(NumberSource.prototype as any)._read = function() {
|
|
244
|
-
const n = this._numbers.shift();
|
|
245
|
-
this.push(n !== undefined ? n : null);
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
const collected: number[] = [];
|
|
249
|
-
const src: any = new (NumberSource as any)([10, 20, 30]);
|
|
250
|
-
await new Promise<void>((resolve, reject) => {
|
|
251
|
-
src.on('data', (n: number) => collected.push(n));
|
|
252
|
-
src.on('end', resolve);
|
|
253
|
-
src.on('error', reject);
|
|
254
|
-
});
|
|
255
|
-
expect(collected).toEqualArray([10, 20, 30]);
|
|
256
|
-
expect(src instanceof Readable).toBe(true);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
await it('function-based Writable subclass via inherits works', async () => {
|
|
260
|
-
function CollectWritable(this: any) {
|
|
261
|
-
Writable.call(this);
|
|
262
|
-
this.collected = [];
|
|
263
|
-
}
|
|
264
|
-
inherits(CollectWritable as any, Writable as any);
|
|
265
|
-
(CollectWritable.prototype as any)._write = function(
|
|
266
|
-
chunk: Buffer,
|
|
267
|
-
_enc: string,
|
|
268
|
-
cb: () => void,
|
|
269
|
-
) {
|
|
270
|
-
this.collected.push(chunk.toString());
|
|
271
|
-
cb();
|
|
272
|
-
};
|
|
273
|
-
|
|
274
|
-
const cw: any = new (CollectWritable as any)();
|
|
275
|
-
await new Promise<void>((resolve, reject) => {
|
|
276
|
-
cw.on('finish', resolve);
|
|
277
|
-
cw.on('error', reject);
|
|
278
|
-
cw.write('hello');
|
|
279
|
-
cw.write('world');
|
|
280
|
-
cw.end();
|
|
281
|
-
});
|
|
282
|
-
expect(cw.collected).toEqualArray(['hello', 'world']);
|
|
283
|
-
expect(cw instanceof Writable).toBe(true);
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
await it('function-based Transform subclass via inherits works', async () => {
|
|
287
|
-
function UpperCase(this: any) {
|
|
288
|
-
Transform.call(this);
|
|
289
|
-
}
|
|
290
|
-
inherits(UpperCase as any, Transform as any);
|
|
291
|
-
(UpperCase.prototype as any)._transform = function(
|
|
292
|
-
chunk: Buffer,
|
|
293
|
-
_enc: string,
|
|
294
|
-
cb: (err: null, data: Buffer) => void,
|
|
295
|
-
) {
|
|
296
|
-
cb(null, Buffer.from(chunk.toString().toUpperCase()));
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
const out: string[] = [];
|
|
300
|
-
const uc: any = new (UpperCase as any)();
|
|
301
|
-
await new Promise<void>((resolve, reject) => {
|
|
302
|
-
uc.on('data', (chunk: Buffer) => out.push(chunk.toString()));
|
|
303
|
-
uc.on('end', resolve);
|
|
304
|
-
uc.on('error', reject);
|
|
305
|
-
uc.write('hello');
|
|
306
|
-
uc.write('world');
|
|
307
|
-
uc.end();
|
|
308
|
-
});
|
|
309
|
-
expect(out).toEqualArray(['HELLO', 'WORLD']);
|
|
310
|
-
expect(uc instanceof Transform).toBe(true);
|
|
311
|
-
expect(uc instanceof Readable).toBe(true);
|
|
312
|
-
expect(uc instanceof Writable).toBe(true);
|
|
313
|
-
});
|
|
314
|
-
});
|
|
315
|
-
};
|
package/src/internal/state.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// Module-singleton state for the stream module.
|
|
2
|
-
//
|
|
3
|
-
// Reference: refs/node/lib/internal/streams/state.js
|
|
4
|
-
// Reimplemented for GJS — currently only the default high-water-mark pair.
|
|
5
|
-
// Centralised here so per-class files (Readable, Writable, Duplex) do not
|
|
6
|
-
// duplicate or fight over the values.
|
|
7
|
-
|
|
8
|
-
let defaultHighWaterMark = 16384;
|
|
9
|
-
let defaultObjectHighWaterMark = 16;
|
|
10
|
-
|
|
11
|
-
export function getDefaultHighWaterMark(objectMode: boolean): number {
|
|
12
|
-
return objectMode ? defaultObjectHighWaterMark : defaultHighWaterMark;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function setDefaultHighWaterMark(objectMode: boolean, value: number): void {
|
|
16
|
-
if (typeof value !== 'number' || value < 0 || Number.isNaN(value)) {
|
|
17
|
-
throw new TypeError(`Invalid highWaterMark: ${value}`);
|
|
18
|
-
}
|
|
19
|
-
if (objectMode) {
|
|
20
|
-
defaultObjectHighWaterMark = value;
|
|
21
|
-
} else {
|
|
22
|
-
defaultHighWaterMark = value;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Validate a named high-water-mark option and throw ERR_INVALID_ARG_VALUE on NaN/non-number. */
|
|
27
|
-
export function validateHighWaterMark(name: string, value: unknown): void {
|
|
28
|
-
if (value === undefined) return;
|
|
29
|
-
if (typeof value !== 'number' || Number.isNaN(value)) {
|
|
30
|
-
const err = new TypeError(`The value of "${name}" is invalid. Received ${value}`) as Error & { code?: string };
|
|
31
|
-
err.code = 'ERR_INVALID_ARG_VALUE';
|
|
32
|
-
throw err;
|
|
33
|
-
}
|
|
34
|
-
}
|
package/src/internal/types.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// Shared types used across the per-class stream modules.
|
|
2
|
-
//
|
|
3
|
-
// Reference: refs/node/lib/stream.js, refs/node/lib/internal/streams/*.js
|
|
4
|
-
// Reimplemented for GJS — kept tiny on purpose; per-class files own their own
|
|
5
|
-
// public option interfaces (re-exported via Node's `node:stream` types).
|
|
6
|
-
|
|
7
|
-
import type { EventEmitter } from '@gjsify/events';
|
|
8
|
-
|
|
9
|
-
/** Base options accepted by the Stream constructor (superset used by subclass options). */
|
|
10
|
-
export interface StreamOptions {
|
|
11
|
-
highWaterMark?: number;
|
|
12
|
-
objectMode?: boolean;
|
|
13
|
-
signal?: AbortSignal;
|
|
14
|
-
captureRejections?: boolean;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** A stream-like emitter that may have `pause` and `resume` methods (duck-typed). */
|
|
18
|
-
export interface StreamLike extends EventEmitter {
|
|
19
|
-
pause?(): void;
|
|
20
|
-
resume?(): void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** Internal write-buffer entry shared by Writable and Duplex queues. */
|
|
24
|
-
export interface BufferedWrite {
|
|
25
|
-
chunk: unknown;
|
|
26
|
-
encoding: string;
|
|
27
|
-
callback: (error?: Error | null) => void;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Generic node-style error callback. */
|
|
31
|
-
export type ErrCallback = (error?: Error | null) => void;
|
package/src/passthrough.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// PassThrough — Transform whose `_transform` is the identity.
|
|
2
|
-
//
|
|
3
|
-
// Reference: refs/node/lib/internal/streams/passthrough.js
|
|
4
|
-
// Reimplemented for GJS.
|
|
5
|
-
|
|
6
|
-
import type { TransformOptions } from 'node:stream';
|
|
7
|
-
|
|
8
|
-
import { Transform_ } from './transform.js';
|
|
9
|
-
|
|
10
|
-
export class PassThrough_ extends Transform_ {
|
|
11
|
-
constructor(opts?: TransformOptions) {
|
|
12
|
-
super({
|
|
13
|
-
...opts,
|
|
14
|
-
transform(chunk: unknown, _encoding: string, callback: (error?: Error | null, data?: unknown) => void) {
|
|
15
|
-
callback(null, chunk);
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|