Skip to content

Commit ef0b8e0

Browse files
committed
Fix sink from preventing the readable event to fire on the underlying stream
1 parent 941b040 commit ef0b8e0

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/sink.js

+5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ function sink(stream) {
1111
});
1212

1313
return function() {
14+
// Respect readable listeners on the underlying stream
15+
if (stream.listeners('readable').length > 0) {
16+
return;
17+
}
18+
1419
stream.pipe(sinkStream);
1520
};
1621
}

test/dest.js

+23
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,29 @@ describe('dest stream', function() {
13371337
.pipe(slowCountFiles);
13381338
});
13391339

1340+
it('should respect readable listeners on destination stream', function(done) {
1341+
var srcPath = path.join(__dirname, './fixtures/test.coffee');
1342+
var srcStream = vfs.src(srcPath);
1343+
var destStream = vfs.dest('./out-fixtures/', { cwd: __dirname });
1344+
1345+
srcStream
1346+
.pipe(destStream);
1347+
1348+
var readables = 0;
1349+
destStream.on('readable', function() {
1350+
var data = destStream.read();
1351+
1352+
if (data == null) {
1353+
// Stream ended
1354+
readables.should.equal(1);
1355+
done();
1356+
} else {
1357+
// New data
1358+
readables++;
1359+
}
1360+
});
1361+
});
1362+
13401363
it('should pass options to through2', function(done) {
13411364
var srcPath = path.join(__dirname, './fixtures/test.coffee');
13421365
var content = fs.readFileSync(srcPath);

0 commit comments

Comments
 (0)