@util.js/node-streams 0.41.6 → 0.41.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 +7 -3
- package/test/StreamsTest.js +0 -130
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "Chris Topher <c@creemama.com>",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@util.js/promises": "0.41.
|
|
5
|
-
"@util.js/strings": "0.41.
|
|
4
|
+
"@util.js/promises": "0.41.8",
|
|
5
|
+
"@util.js/strings": "0.41.8"
|
|
6
6
|
},
|
|
7
7
|
"description": "JavaScript utility methods for streams",
|
|
8
|
+
"files": [
|
|
9
|
+
"index.js",
|
|
10
|
+
"lib"
|
|
11
|
+
],
|
|
8
12
|
"keywords": [
|
|
9
13
|
"fromString",
|
|
10
14
|
"stream",
|
|
@@ -27,5 +31,5 @@
|
|
|
27
31
|
"type": "git",
|
|
28
32
|
"url": "https://github.com/creemama/utiljs/tree/master/packages/utiljs-node-streams"
|
|
29
33
|
},
|
|
30
|
-
"version": "0.41.
|
|
34
|
+
"version": "0.41.8"
|
|
31
35
|
}
|
package/test/StreamsTest.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { expect } = require("chai");
|
|
4
|
-
const stream = require("stream");
|
|
5
|
-
const streams = require("..");
|
|
6
|
-
|
|
7
|
-
describe("Streams", () => {
|
|
8
|
-
describe("#finished(stream[, callback])", () => {
|
|
9
|
-
it("should call callback when finished", (callback) => {
|
|
10
|
-
if (!stream.finished) return callback();
|
|
11
|
-
const readable = streams.fromString("frog\ncat");
|
|
12
|
-
streams.finished(readable, callback);
|
|
13
|
-
});
|
|
14
|
-
it("should resolve the returned Promise when finished", () => {
|
|
15
|
-
if (!stream.finished) return;
|
|
16
|
-
const readable = streams.fromString("frog\ncat");
|
|
17
|
-
const promise = streams.finished(readable);
|
|
18
|
-
return promise;
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe("#pipeline(...streams[, callback])", () => {
|
|
23
|
-
it("should call callback when finished", (callback) => {
|
|
24
|
-
if (!stream.pipeline) return callback();
|
|
25
|
-
const readable = streams.fromString("frog\ncat");
|
|
26
|
-
let out = "";
|
|
27
|
-
const writable = streams.newWritable({
|
|
28
|
-
write(chunk, encoding, callback) {
|
|
29
|
-
out += chunk.toString();
|
|
30
|
-
callback();
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
streams.pipeline(readable, writable, (error) => {
|
|
34
|
-
expect(out).to.eql("frog\ncat");
|
|
35
|
-
callback(error);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
it("should resolve the returned Promise when finished", () => {
|
|
39
|
-
if (!stream.pipeline) return;
|
|
40
|
-
const readable = streams.fromString("frog\ncat");
|
|
41
|
-
let out = "";
|
|
42
|
-
const writable = streams.newWritable({
|
|
43
|
-
write(chunk, encoding, callback) {
|
|
44
|
-
out += chunk.toString();
|
|
45
|
-
callback();
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
|
-
return streams.pipeline(readable, writable).then(() => {
|
|
49
|
-
expect(out).to.eql("frog\ncat");
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe("#stringify(readable[, callback])", () => {
|
|
55
|
-
it("should successfully stringify a Readable and return a Promise", () => {
|
|
56
|
-
const readable = streams.fromString("frog\ncat");
|
|
57
|
-
return streams
|
|
58
|
-
.stringify(readable)
|
|
59
|
-
.then((string) => expect(string).to.equal("frog\ncat"));
|
|
60
|
-
});
|
|
61
|
-
it("should throw an error if the readable is null and return a Promise", async function () {
|
|
62
|
-
await streams.stringify().then(
|
|
63
|
-
() => {
|
|
64
|
-
throw new Error("Unexpected success");
|
|
65
|
-
},
|
|
66
|
-
(error) => {
|
|
67
|
-
if (!error) throw new Error("Unexpected");
|
|
68
|
-
},
|
|
69
|
-
);
|
|
70
|
-
await streams.stringify(null).then(
|
|
71
|
-
() => {
|
|
72
|
-
throw new Error("Unexpected success");
|
|
73
|
-
},
|
|
74
|
-
(error) => {
|
|
75
|
-
if (!error) throw new Error("Unexpected");
|
|
76
|
-
},
|
|
77
|
-
);
|
|
78
|
-
await streams.stringify(null, null).then(
|
|
79
|
-
() => {
|
|
80
|
-
throw new Error("Unexpected success");
|
|
81
|
-
},
|
|
82
|
-
(error) => {
|
|
83
|
-
if (!error) throw new Error("Unexpected");
|
|
84
|
-
},
|
|
85
|
-
);
|
|
86
|
-
});
|
|
87
|
-
it("should successfully stringify a Readable and notify a callback", (callback) => {
|
|
88
|
-
const stream = streams.fromString("frog\ncat");
|
|
89
|
-
streams.stringify(stream, (error, string) => {
|
|
90
|
-
expect(error).to.be.null;
|
|
91
|
-
expect(string).to.equal("frog\ncat");
|
|
92
|
-
callback();
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
it("should throw an error if any argument is null and notify a callback", () => {
|
|
96
|
-
expect(() => {
|
|
97
|
-
streams.stringify(null, () => {});
|
|
98
|
-
}).to.throw(Error);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
describe("#fromString(string[, encoding])", () => {
|
|
103
|
-
it("should create a Readable from a string", () => {
|
|
104
|
-
const readable = streams.fromString("foo bar");
|
|
105
|
-
return streams
|
|
106
|
-
.stringify(readable)
|
|
107
|
-
.then((string) => expect(string).to.eql("foo bar"));
|
|
108
|
-
});
|
|
109
|
-
it("should create a Readable from an empty string", () => {
|
|
110
|
-
const readable = streams.fromString("");
|
|
111
|
-
return streams
|
|
112
|
-
.stringify(readable)
|
|
113
|
-
.then((string) => expect(string).to.eql(""));
|
|
114
|
-
});
|
|
115
|
-
it("should properly handle encoding", async function () {
|
|
116
|
-
let readable = streams.fromString("El Niño & La Niña", "ascii");
|
|
117
|
-
const ascii = await streams.stringify(readable);
|
|
118
|
-
expect(ascii).to.eql("El Ni�o & La Ni�a");
|
|
119
|
-
readable = streams.fromString("El Niño & La Niña", "utf8");
|
|
120
|
-
const utf8 = await streams.stringify(readable);
|
|
121
|
-
expect(utf8).to.eql("El Niño & La Niña");
|
|
122
|
-
});
|
|
123
|
-
it("should error on non-string input", () => {
|
|
124
|
-
expect(() => streams.fromString()).to.throw(TypeError);
|
|
125
|
-
expect(() => streams.fromString({ foo: "bar" })).to.throw(TypeError);
|
|
126
|
-
expect(() => streams.fromString(["a", "b"])).to.throw(TypeError);
|
|
127
|
-
expect(() => streams.fromString(null)).to.throw(TypeError);
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
});
|