Comparing version 0.0.4 to 0.0.5
var stream = require("stream"); | ||
var bun = module.exports = function bun(streams) { | ||
var inner = new stream.Duplex({objectMode: true}), | ||
outer = new stream.Duplex({objectMode: true}); | ||
// useful for debugging | ||
/* | ||
[["inner", inner], ["outer", outer]].forEach(function(e) { | ||
for (var k in e[1]) { | ||
if (typeof e[1][k] === "function") { | ||
(function(k) { | ||
var f = e[1][k]; | ||
e[1][k] = function() { | ||
console.log(e[0], k, "" + arguments[0]); | ||
return f.apply(e[1], arguments); | ||
}; | ||
}(k)); | ||
} | ||
} | ||
}); | ||
*/ | ||
// inner | ||
@@ -20,4 +36,5 @@ inner._write = function _write(input, encoding, done) { | ||
if (outer.continue) { | ||
outer.continue(); | ||
var c = outer.continue; | ||
delete outer.continue; | ||
c(); | ||
} | ||
@@ -34,2 +51,6 @@ }; | ||
inner.once("end", function onEnd() { | ||
outer.end(); | ||
}); | ||
// outer | ||
@@ -47,4 +68,5 @@ outer._write = function _write(input, encoding, done) { | ||
if (inner.continue) { | ||
inner.continue(); | ||
var c = inner.continue; | ||
delete inner.continue; | ||
c(); | ||
} | ||
@@ -61,2 +83,6 @@ }; | ||
outer.once("end", function onFinish() { | ||
inner.end(); | ||
}); | ||
// piping time | ||
@@ -63,0 +89,0 @@ var s = inner; |
{ | ||
"name": "bun", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "A useful container for streams", | ||
@@ -5,0 +5,0 @@ "main": "lib/bun.js", |
@@ -0,10 +1,403 @@ | ||
var stream = require("stream"); | ||
var bun = require(".."); | ||
var assert = require("assert"); | ||
describe("bun", function() { | ||
it("should be the best", function() { | ||
var bun = "is the best"; | ||
assert.strictEqual(bun, "is the best"); | ||
}); | ||
it("should pass data through one stream", function(done) { | ||
var uppercaser = new stream.Transform({objectMode: true}); | ||
uppercaser._transform = function _transform(input, encoding, done) { | ||
this.push(input.toString().toUpperCase()); | ||
return done(); | ||
}; | ||
var stack = bun([uppercaser]); | ||
stack.on("readable", function() { | ||
var data = stack.read(); | ||
assert(typeof data === "string", "data should be a string"); | ||
assert(data === "HELLO", "data should be transformed correctly"); | ||
done(); | ||
}); | ||
stack.write("hello"); | ||
}); | ||
it("should pass data through two streams", function(done) { | ||
var uppercaser = new stream.Transform({objectMode: true}), | ||
underscorer = new stream.Transform({objectMode: true}); | ||
uppercaser._transform = function _transform(input, encoding, done) { | ||
this.push(input.toString().toUpperCase()); | ||
return done(); | ||
}; | ||
underscorer._transform = function _transform(input, encoding, done) { | ||
this.push(input.toString().split("").join("_")); | ||
return done(); | ||
}; | ||
var stack = bun([uppercaser, underscorer]); | ||
stack.on("readable", function() { | ||
var data = stack.read(); | ||
assert(typeof data === "string", "data should be a string"); | ||
assert(data === "H_E_L_L_O", "data should be transformed correctly"); | ||
done(); | ||
}); | ||
stack.write("hello"); | ||
}); | ||
it("should finish correctly with no streams and no data written", function(done) { | ||
var stack = bun([]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
stack.end(); | ||
}); | ||
it("should finish correctly with one stream and no data written", function(done) { | ||
var alice = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
stack.end(); | ||
}); | ||
it("should finish correctly with two streams and no data written", function(done) { | ||
var alice = new stream.PassThrough({objectMode: true}), | ||
bob = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice, bob]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
stack.end(); | ||
}); | ||
it("should finish correctly with no streams and some data written", function(done) { | ||
var stack = bun([]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
stack.on("readable", function() { | ||
var e; | ||
while (e = stack.read()) { | ||
} | ||
}); | ||
stack.write("some data"); | ||
stack.end(); | ||
}); | ||
it("should finish correctly with one stream and some data written", function(done) { | ||
var alice = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
stack.on("readable", function() { | ||
var e; | ||
while (e = stack.read()) { | ||
} | ||
}); | ||
stack.write("some data"); | ||
stack.end(); | ||
}); | ||
it("should finish correctly with two streams and some data written", function(done) { | ||
var alice = new stream.PassThrough({objectMode: true}), | ||
bob = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice, bob]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
stack.on("readable", function() { | ||
var e; | ||
while (e = stack.read()) { | ||
} | ||
}); | ||
stack.write("some data"); | ||
stack.end(); | ||
}); | ||
it("should finish correctly when piped through with no streams and no data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var stack = bun([]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.end(); | ||
}); | ||
it("should finish correctly when piped through with one stream and no data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var alice = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.end(); | ||
}); | ||
it("should finish correctly when piped through with two streams and no data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var alice = new stream.PassThrough({objectMode: true}), | ||
bob = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice, bob]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.end(); | ||
}); | ||
it("should finish correctly when piped through with no streams and some data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var stack = bun([]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.write("hello"); | ||
input.end(); | ||
}); | ||
it("should finish correctly when piped through with one stream and some data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var alice = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.write("hello"); | ||
input.end(); | ||
}); | ||
it("should finish correctly when piped through with two streams and some data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var alice = new stream.PassThrough({objectMode: true}), | ||
bob = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice, bob]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.write("hello"); | ||
input.end(); | ||
}); | ||
it("should end correctly when piped through with no streams and no data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var stack = bun([]); | ||
stack.on("end", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.push(null); | ||
}); | ||
it("should end correctly when piped through with one stream and no data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var alice = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice]); | ||
stack.on("end", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.end(); | ||
}); | ||
it("should end correctly when piped through with two streams and no data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var alice = new stream.PassThrough({objectMode: true}), | ||
bob = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice, bob]); | ||
stack.on("end", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.end(); | ||
}); | ||
it("should end correctly when piped through with no streams and some data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var stack = bun([]); | ||
stack.on("end", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.write("hello"); | ||
input.end(); | ||
}); | ||
it("should end correctly when piped through with one stream and some data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var alice = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice]); | ||
stack.on("end", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.write("hello"); | ||
input.end(); | ||
}); | ||
it("should end correctly when piped through with two streams and some data written", function(done) { | ||
var input = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var alice = new stream.PassThrough({objectMode: true}), | ||
bob = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice, bob]); | ||
stack.on("end", function() { | ||
done(); | ||
}); | ||
input.pipe(stack).pipe(nowhere); | ||
input.write("hello"); | ||
input.end(); | ||
}); | ||
it("should end wrapped streams correctly when ended", function(done) { | ||
var alice = new stream.PassThrough({objectMode: true}); | ||
alice.on("finish", function() { | ||
done(); | ||
}); | ||
var stack = bun([alice]); | ||
stack.end(); | ||
}); | ||
it("should finish when wrapped streams finish", function(done) { | ||
var alice = new stream.PassThrough({objectMode: true}), | ||
outside = new stream.PassThrough({objectMode: true}); | ||
var stack = bun([alice]); | ||
stack.on("finish", function() { | ||
done(); | ||
}); | ||
outside.pipe(stack).pipe(outside); | ||
alice.end(); | ||
}); | ||
it("should end when wrapped streams end", function(done) { | ||
var alice = new stream.PassThrough({objectMode: true}); | ||
var nowhere = new stream.Writable({objectMode: true}); | ||
nowhere._write = function _write(input, encoding, done) { return done(); }; | ||
var stack = bun([alice]); | ||
stack.on("end", function() { | ||
done(); | ||
}); | ||
stack.pipe(nowhere); | ||
alice.push(null); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19219
9
510
1