Comparing version 1.0.0 to 1.1.0
45
index.js
@@ -8,2 +8,4 @@ var Stream = require('stream') | ||
exports = module.exports = through | ||
@@ -19,3 +21,4 @@ through.through = through | ||
var ended = false, destroyed = false | ||
var stream = new Stream() | ||
var stream = new Stream(), buffer = [] | ||
stream.buffer = buffer | ||
stream.readable = stream.writable = true | ||
@@ -27,5 +30,24 @@ stream.paused = false | ||
} | ||
function drain() { | ||
while(buffer.length && !stream.paused) { | ||
var data = buffer.shift() | ||
if(null === data) | ||
return stream.emit('end') | ||
else | ||
stream.emit('data', data) | ||
} | ||
} | ||
stream.queue = function (data) { | ||
buffer.push(data) | ||
drain() | ||
} | ||
//this will be registered as the first 'end' listener | ||
//must call destroy next tick, to make sure we're after any | ||
//stream piped from here. | ||
//this is only a problem if end is not emitted synchronously. | ||
//a nicer way to do this is to make sure this is the last listener for 'end' | ||
stream.on('end', function () { | ||
@@ -39,2 +61,9 @@ stream.readable = false | ||
function _end () { | ||
stream.writable = false | ||
end.call(stream) | ||
if(!stream.readable) | ||
stream.destroy() | ||
} | ||
stream.end = function (data) { | ||
@@ -46,7 +75,5 @@ if(ended) return | ||
if(arguments.length) stream.write(data) | ||
this.writable = false | ||
end.call(this) | ||
if(!this.readable) | ||
this.destroy() | ||
if(!buffer.length) _end() | ||
} | ||
stream.destroy = function () { | ||
@@ -56,5 +83,7 @@ if(destroyed) return | ||
ended = true | ||
buffer.length = 0 | ||
stream.writable = stream.readable = false | ||
stream.emit('close') | ||
} | ||
stream.pause = function () { | ||
@@ -69,3 +98,7 @@ if(stream.paused) return | ||
} | ||
stream.emit('drain') | ||
drain() | ||
//may have become paused again, | ||
//as drain emits 'data'. | ||
if(!stream.paused) | ||
stream.emit('drain') | ||
} | ||
@@ -72,0 +105,0 @@ return stream |
{ | ||
"name": "through", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "simplified stream contruction", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
8914
9
225
45
0
1