@trenskow/stream-reader 0.2.1 → 0.2.3
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/index.js +5 -11
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
export default (stream
|
|
1
|
+
export default (stream) => {
|
|
2
2
|
|
|
3
3
|
return new Promise((resolve, reject) => {
|
|
4
4
|
|
|
5
|
-
let rejected = false;
|
|
6
|
-
|
|
7
5
|
let result = new Buffer.alloc(0);
|
|
8
6
|
|
|
9
7
|
stream.on('data', (buffer) => {
|
|
10
|
-
if (rejected) return;
|
|
11
8
|
result = Buffer.concat([result, buffer]);
|
|
12
|
-
if (typeof options.limit === 'number' && result.length > options.limit) {
|
|
13
|
-
rejected = true;
|
|
14
|
-
reject(options.error ? options.error() : new Error('Stream length limit reached.'));
|
|
15
|
-
}
|
|
16
9
|
});
|
|
17
10
|
|
|
18
|
-
stream.
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
stream.once('end', () => resolve(result));
|
|
12
|
+
|
|
13
|
+
stream.once('error', (err) => {
|
|
14
|
+
reject(err);
|
|
21
15
|
});
|
|
22
16
|
|
|
23
17
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trenskow/stream-reader",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "A simple promise to read the content of a stream in Node.js.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@eslint/eslintrc": "^3.2.0",
|
|
27
27
|
"@eslint/js": "^9.13.0",
|
|
28
|
-
"eslint": "^9.
|
|
29
|
-
"globals": "^15.
|
|
28
|
+
"eslint": "^9.17.0",
|
|
29
|
+
"globals": "^15.14.0"
|
|
30
30
|
}
|
|
31
31
|
}
|