node_modules/browserify/node_modules/through/index.js in sprockets-browserify-0.2.0 vs node_modules/browserify/node_modules/through/index.js in sprockets-browserify-0.3.0

- old
+ new

@@ -3,26 +3,27 @@ // through // // a stream that does nothing but re-emit the input. // useful for aggregating a series of changing but not ending streams into one stream) - - exports = module.exports = through through.through = through //create a readable writable stream. -function through (write, end) { +function through (write, end, opts) { write = write || function (data) { this.queue(data) } end = end || function () { this.queue(null) } - var ended = false, destroyed = false, buffer = [] + var ended = false, destroyed = false, buffer = [], _ended = false var stream = new Stream() stream.readable = stream.writable = true stream.paused = false +// stream.autoPause = !(opts && opts.autoPause === false) + stream.autoDestroy = !(opts && opts.autoDestroy === false) + stream.write = function (data) { write.call(this, data) return !stream.paused } @@ -35,10 +36,13 @@ stream.emit('data', data) } } stream.queue = stream.push = function (data) { +// console.error(ended) + if(_ended) return stream + if(data == null) _ended = true buffer.push(data) drain() return stream } @@ -48,20 +52,20 @@ //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 () { stream.readable = false - if(!stream.writable) + if(!stream.writable && stream.autoDestroy) process.nextTick(function () { stream.destroy() }) }) function _end () { stream.writable = false end.call(stream) - if(!stream.readable) + if(!stream.readable && stream.autoDestroy) stream.destroy() } stream.end = function (data) { if(ended) return @@ -82,15 +86,16 @@ } stream.pause = function () { if(stream.paused) return stream.paused = true - stream.emit('pause') return stream } + stream.resume = function () { if(stream.paused) { stream.paused = false + stream.emit('resume') } drain() //may have become paused again, //as drain emits 'data'. if(!stream.paused)