Skip to content

Commit 99fc7d4

Browse files
committed
fix data being emitted out of order on a large peeked stream
1 parent e0d3bde commit 99fc7d4

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# buffer-peek-stream changelog
22

3+
## 0.1.2 (2014/11/07)
4+
5+
- fix data being emitted out of order on a large peeked stream
6+
37
## 0.1.1 (2014/11/05)
48

59
- fix typo in require

lib/buffer-peek-stream.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ BufferPeekStream.prototype.__stopPeeking = function __stopPeeking() {
5656
// unpipe from upstream
5757
this.__src.unpipe(this);
5858

59+
//TODO: find out if this stream can still get data after unpiping under any circumstance
60+
5961
var buffer = Buffer.concat(this.__buffer);
6062
var source = this.__src;
6163

@@ -78,16 +80,10 @@ BufferPeekStream.prototype.__stopPeeking = function __stopPeeking() {
7880
source._readableState.emittedReadable = true;
7981
source._readableState.readableListening = false;
8082
source._readableState.readingMore = false;
81-
82-
source.unshift(buffer);
83-
} else {
84-
// delay unshifting all chunks back onto parent until we're drained so we don't lose chunks that
85-
// have already been put onto the event stack before we unpiped.
86-
this.once('drain', function () {
87-
source.unshift(buffer);
88-
});
8983
}
9084

85+
source.unshift(buffer);
86+
9187
// we don't need to keep the original buffers
9288
this.__buffer = null;
9389
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "buffer-peek-stream",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Transform stream that lets you inspect the start of a ReadStream before deciding what to do with it",
55
"main": "lib/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)