Add buffer support to split, join, replace and parse streams

This commit is contained in:
Sami Turcotte
2018-12-03 09:18:49 -05:00
parent 407bb79260
commit 63c3681211
4 changed files with 53 additions and 9 deletions

View File

@@ -495,6 +495,30 @@ test.cb("split() splits chunks using the specified separator", t => {
source.push(null);
});
test.cb(
"split() splits utf-8 encoded buffers using the specified separator",
t => {
t.plan(3);
const expectedElements = ["a", "b", "c"];
let i = 0;
const through = split(",");
const buf = Buffer.from("a,b,c");
through
.on("data", element => {
expect(element).to.equal(expectedElements[i]);
i++;
t.pass();
})
.on("error", t.end)
.on("end", t.end);
for (let j = 0; j < buf.length; ++j) {
through.write(buf.slice(j, j + 1));
}
through.end();
},
);
test.cb("join() joins chunks using the specified separator", t => {
t.plan(9);
const source = new Readable({ objectMode: true });