Skip to content

Commit

Permalink
Merge pull request #18 from marsaud/master
Browse files Browse the repository at this point in the history
BufferStreams emit finish and readable event
  • Loading branch information
Sam committed May 28, 2015
2 parents 7d8bc24 + 346e0da commit 93914f8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/readable_streambuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ var ReadableStreamBuffer = module.exports = function(opts) {
this.put = function(data, encoding) {
if(!that.readable) return;

var wasEmpty = size === 0;
if(Buffer.isBuffer(data)) {
increaseBufferIfNecessary(data.length);
data.copy(buffer, size, 0);
Expand All @@ -84,6 +85,10 @@ var ReadableStreamBuffer = module.exports = function(opts) {
size += dataSizeInBytes;
}

if (wasEmpty && size > 0) {
this.emit('readable')
}

if (!this.isPaused && !frequency) {
while (size > 0) {
sendData();
Expand Down
1 change: 1 addition & 0 deletions lib/writable_streambuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var WritableStreamBuffer = module.exports = function(opts) {
this.end = function() {
var args = Array.prototype.slice.apply(arguments);
if(args.length) that.write.apply(that, args);
that.emit('finish');
that.destroy();
};

Expand Down

0 comments on commit 93914f8

Please sign in to comment.