@promistream/from-node-stream 0.1.9 → 0.1.10
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 +1 -1
- package/src/index.js +19 -7
- package/test.js +42 -0
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -36,6 +36,12 @@ function wireReadable(debug, stream) {
|
|
|
36
36
|
let buffer = pushBuffer({ mode: "push" });
|
|
37
37
|
let isPaused = false;
|
|
38
38
|
let abortSeen = false;
|
|
39
|
+
let endError;
|
|
40
|
+
|
|
41
|
+
function finishStream(error) {
|
|
42
|
+
endError = error;
|
|
43
|
+
buffer.pushError(error);
|
|
44
|
+
}
|
|
39
45
|
|
|
40
46
|
stream.on("data", (value) => {
|
|
41
47
|
debug("Received value from underlying Readable stream");
|
|
@@ -58,13 +64,14 @@ function wireReadable(debug, stream) {
|
|
|
58
64
|
if (!abortSeen) {
|
|
59
65
|
debug(`Underlying Readable stream produced an error: ${error.message}`);
|
|
60
66
|
abortSeen = true;
|
|
61
|
-
|
|
67
|
+
finishStream(ensureValidError(error));
|
|
62
68
|
}
|
|
63
69
|
});
|
|
64
70
|
|
|
65
71
|
stream.on("end", () => {
|
|
72
|
+
// TODO: How/where do we propagate Aborted markers, especially on subsequent overreads?
|
|
66
73
|
debug("Reached end of underlying Readable stream");
|
|
67
|
-
|
|
74
|
+
finishStream(new EndOfStream("The underlying stream has ended"));
|
|
68
75
|
});
|
|
69
76
|
|
|
70
77
|
return {
|
|
@@ -72,11 +79,16 @@ function wireReadable(debug, stream) {
|
|
|
72
79
|
read: async function () {
|
|
73
80
|
let promise = buffer.request();
|
|
74
81
|
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
let counts = buffer.countLane();
|
|
83
|
+
if (counts.requests > 0 && counts.values === 0) {
|
|
84
|
+
// We have run out of values
|
|
85
|
+
if (endError != null) {
|
|
86
|
+
buffer.pushError(endError);
|
|
87
|
+
} else if (isPaused) {
|
|
88
|
+
debug("Resuming underlying Readable stream, as our buffer ran out");
|
|
89
|
+
isPaused = false;
|
|
90
|
+
stream.resume();
|
|
91
|
+
}
|
|
80
92
|
}
|
|
81
93
|
|
|
82
94
|
return promise;
|
package/test.js
CHANGED
|
@@ -177,6 +177,48 @@ test("transform stream, parallel", async () => {
|
|
|
177
177
|
assert.deepStrictEqual(result, [ 0, 0, 1, 2, 2, 4, 3, 6, 4, 8, 5, 10, 6, 12, 7, 14, 8, 16, 9, 18, 10, 20 ]);
|
|
178
178
|
});
|
|
179
179
|
|
|
180
|
+
test("transform stream, overread", { timeout: 500 }, async () => {
|
|
181
|
+
let pipeline = pipe([
|
|
182
|
+
fromIterable([ 0 ]),
|
|
183
|
+
fromNodeStream(new stream.Transform({
|
|
184
|
+
objectMode: true,
|
|
185
|
+
transform(chunk, _encoding, callback) {
|
|
186
|
+
setTimeout(() => {
|
|
187
|
+
this.push(chunk);
|
|
188
|
+
this.push(chunk * 2);
|
|
189
|
+
callback();
|
|
190
|
+
}, 10);
|
|
191
|
+
}
|
|
192
|
+
}))
|
|
193
|
+
]);
|
|
194
|
+
|
|
195
|
+
assert.strictEqual(await pipeline.read(), 0);
|
|
196
|
+
assert.strictEqual(await pipeline.read(), 0);
|
|
197
|
+
await assert.rejects(() => pipeline.read(), { name: "EndOfStream" });
|
|
198
|
+
await assert.rejects(() => pipeline.read(), { name: "EndOfStream" }); /* This should repeat the last error, just like a normal source stream would */
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("transform stream, abort overread", { timeout: 500 }, async () => {
|
|
202
|
+
let pipeline = pipe([
|
|
203
|
+
fromIterable([ 0 ]),
|
|
204
|
+
testAbort(0, new Error("sample error")),
|
|
205
|
+
fromNodeStream(new stream.Transform({
|
|
206
|
+
objectMode: true,
|
|
207
|
+
transform(chunk, _encoding, callback) {
|
|
208
|
+
setTimeout(() => {
|
|
209
|
+
this.push(chunk);
|
|
210
|
+
this.push(chunk * 2);
|
|
211
|
+
callback();
|
|
212
|
+
}, 10);
|
|
213
|
+
}
|
|
214
|
+
}))
|
|
215
|
+
]);
|
|
216
|
+
|
|
217
|
+
/* Since we're reading directly from the pipeline, we will get an Aborted marker in both cases; it is normally the sink stream that is responsible for unpacking and throwing the original cause, but we don't have a sink stream in this case. */
|
|
218
|
+
await assert.rejects(() => pipeline.read(), { name: "Aborted", message: "Stream was aborted due to error: sample error" });
|
|
219
|
+
await assert.rejects(() => pipeline.read(), { name: "Aborted", message: "Stream was aborted due to error: sample error" });
|
|
220
|
+
});
|
|
221
|
+
|
|
180
222
|
/* FIXME: Do network socket test with both happy abort and error abort */
|
|
181
223
|
/* TODO: Flaky test behaviour was observed for the below test:
|
|
182
224
|
|