@promistream/from-node-stream 0.1.6 → 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/package.json +10 -7
- package/src/index.js +8 -4
- package/test.js +47 -1
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promistream/from-node-stream",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"main": "src/index.js",
|
|
5
|
-
"repository":
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://codeberg.org/promistream/from-node-stream.git"
|
|
8
|
+
},
|
|
6
9
|
"author": "Sven Slootweg <admin@cryto.net>",
|
|
7
10
|
"license": "WTFPL OR CC0-1.0",
|
|
8
11
|
"dependencies": {
|
|
@@ -15,24 +18,24 @@
|
|
|
15
18
|
"@promistream/propagate-abort": "^0.1.7",
|
|
16
19
|
"@promistream/propagate-peek": "^0.1.2",
|
|
17
20
|
"@promistream/simple-sink": "^0.3.5",
|
|
18
|
-
"@promistream/simple-source": "^0.1.
|
|
21
|
+
"@promistream/simple-source": "^0.1.11",
|
|
19
22
|
"debug-instanced": "^1.0.0",
|
|
20
|
-
"promisify-event": "^1.0.0",
|
|
21
23
|
"push-buffer": "^1.5.7",
|
|
22
24
|
"single-concurrent": "^1.0.0",
|
|
23
25
|
"split-filter": "^1.1.3"
|
|
24
26
|
},
|
|
25
27
|
"devDependencies": {
|
|
26
28
|
"@promistream/buffered-map": "^0.1.1",
|
|
27
|
-
"@promistream/collect": "^0.1.
|
|
29
|
+
"@promistream/collect": "^0.1.4",
|
|
28
30
|
"@promistream/debug": "^0.1.2",
|
|
29
31
|
"@promistream/from-iterable": "^0.1.1",
|
|
30
32
|
"@promistream/map": "^0.1.10",
|
|
31
|
-
"@promistream/parallelize": "^0.1.
|
|
33
|
+
"@promistream/parallelize": "^0.1.10",
|
|
32
34
|
"@promistream/pipe": "^0.1.8",
|
|
33
35
|
"@promistream/range-numbers": "^0.1.2",
|
|
36
|
+
"@promistream/test-abort": "^0.1.0",
|
|
34
37
|
"bluebird": "^3.7.2",
|
|
35
38
|
"p-defer": "^4.0.1",
|
|
36
39
|
"through2": "^4.0.2"
|
|
37
40
|
}
|
|
38
|
-
}
|
|
41
|
+
}
|
package/src/index.js
CHANGED
|
@@ -11,7 +11,6 @@ const makeDebug = require("debug-instanced")("promistream:from-node-stream");
|
|
|
11
11
|
|
|
12
12
|
const { once } = require("node:events");
|
|
13
13
|
const pushBuffer = require("push-buffer");
|
|
14
|
-
const promisifyEvent = require("promisify-event");
|
|
15
14
|
const singleConcurrent = require("single-concurrent");
|
|
16
15
|
const warning = require("@joepie91/warning");
|
|
17
16
|
const util = require("node:util");
|
|
@@ -106,8 +105,12 @@ function convertFromReadable(stream) {
|
|
|
106
105
|
onRequest: () => {
|
|
107
106
|
return read();
|
|
108
107
|
},
|
|
109
|
-
onAbort: () => {
|
|
110
|
-
|
|
108
|
+
onAbort: (reason) => {
|
|
109
|
+
if (reason === true) {
|
|
110
|
+
return abort();
|
|
111
|
+
} else {
|
|
112
|
+
return abort(reason);
|
|
113
|
+
}
|
|
111
114
|
}
|
|
112
115
|
});
|
|
113
116
|
}
|
|
@@ -131,6 +134,7 @@ function wireWritable(debug, stream) {
|
|
|
131
134
|
if (stream.writableNeedDrain) {
|
|
132
135
|
/* Wait for the write buffer to be fully processed */
|
|
133
136
|
// FIXME: Verify that this cannot cause a never-ending wait; if we wait to close the stream until it has drained, then during that time writes to it can continue to happen indefinitely, never letting it drain? Or is this prevented by the backpressure mechanisms we already have (re: .pause and .resume)?
|
|
137
|
+
debug("Waiting for internal write queue to drain...");
|
|
134
138
|
await once(stream, "drain");
|
|
135
139
|
}
|
|
136
140
|
}
|
|
@@ -172,7 +176,7 @@ function wireWritable(debug, stream) {
|
|
|
172
176
|
|
|
173
177
|
if (!canWriteMore) {
|
|
174
178
|
debug("Stream is backlogged, waiting for drain event...");
|
|
175
|
-
await
|
|
179
|
+
await once(stream, "drain");
|
|
176
180
|
debug("Drain event received");
|
|
177
181
|
} else {
|
|
178
182
|
debug("Write successful, can write more");
|
package/test.js
CHANGED
|
@@ -13,7 +13,9 @@ const fromIterable = require("@promistream/from-iterable");
|
|
|
13
13
|
const fromNodeStream = require(".");
|
|
14
14
|
const collect = require("@promistream/collect");
|
|
15
15
|
const parallelize = require("@promistream/parallelize");
|
|
16
|
+
const testAbort = require("@promistream/test-abort");
|
|
16
17
|
const debug = require("@promistream/debug");
|
|
18
|
+
const { once } = require("node:events");
|
|
17
19
|
|
|
18
20
|
test("readable stream", async () => {
|
|
19
21
|
let testFile = path.join(__dirname, "pnpm-lock.yaml"); // Big-ish file, so we're likely to read in multiple chunks
|
|
@@ -24,9 +26,41 @@ test("readable stream", async () => {
|
|
|
24
26
|
collect()
|
|
25
27
|
]).read();
|
|
26
28
|
|
|
27
|
-
assert.deepStrictEqual(result, [ expected ]);
|
|
29
|
+
assert.deepStrictEqual(result, [ expected ]);
|
|
28
30
|
});
|
|
29
31
|
|
|
32
|
+
test("readable stream with error abort", { timeout: 500 }, async () => {
|
|
33
|
+
let testFile = path.join(__dirname, "pnpm-lock.yaml");
|
|
34
|
+
let nodeStream = fs.createReadStream(testFile);
|
|
35
|
+
|
|
36
|
+
let errorFromNodeStreamPromise = once(nodeStream, "error");
|
|
37
|
+
|
|
38
|
+
assert.rejects(async () => {
|
|
39
|
+
let result = await pipe([
|
|
40
|
+
fromNodeStream.fromReadable(nodeStream),
|
|
41
|
+
testAbort(0, new Error("sample error")),
|
|
42
|
+
collect()
|
|
43
|
+
]).read();
|
|
44
|
+
}, { message: "sample error" });
|
|
45
|
+
|
|
46
|
+
let [ errorFromNodeStream ] = await errorFromNodeStreamPromise;
|
|
47
|
+
assert.strictEqual(errorFromNodeStream.message, "sample error");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
test("readable stream with happy abort", { timeout: 500 }, async () => {
|
|
52
|
+
let testFile = path.join(__dirname, "pnpm-lock.yaml");
|
|
53
|
+
|
|
54
|
+
let result = await pipe([
|
|
55
|
+
fromNodeStream.fromReadable(fs.createReadStream(testFile)),
|
|
56
|
+
testAbort(0, true),
|
|
57
|
+
collect()
|
|
58
|
+
]).read();
|
|
59
|
+
|
|
60
|
+
assert.deepStrictEqual(result, []);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
|
|
30
64
|
test("writable stream", async () => {
|
|
31
65
|
let buffer = Buffer.alloc(400000);
|
|
32
66
|
|
|
@@ -116,6 +150,18 @@ test("transform stream, parallel", async () => {
|
|
|
116
150
|
});
|
|
117
151
|
|
|
118
152
|
/* FIXME: Do network socket test with both happy abort and error abort */
|
|
153
|
+
/* TODO: Flaky test behaviour was observed for the below test:
|
|
154
|
+
|
|
155
|
+
✖ network socket (9.891608ms)
|
|
156
|
+
AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
|
|
157
|
+
+ actual - expected
|
|
158
|
+
|
|
159
|
+
+ Buffer(0) [Uint8Array] []
|
|
160
|
+
- Buffer(2) [Uint8Array] [
|
|
161
|
+
- 99,
|
|
162
|
+
- 100
|
|
163
|
+
- ]
|
|
164
|
+
*/
|
|
119
165
|
test("network socket", async () => {
|
|
120
166
|
let { resolve, promise } = pDefer();
|
|
121
167
|
|