diff --git a/lib/_stream_transform.js b/lib/_stream_transform.js index 1b6bbb00c9d..ec2b46a9534 100644 --- a/lib/_stream_transform.js +++ b/lib/_stream_transform.js @@ -101,6 +101,7 @@ function afterTransform(stream, er, data) { cb(er); var rs = stream._readableState; + rs.reading = false; if (rs.needReadable || rs.length < rs.highWaterMark) { stream._read(rs.highWaterMark); } diff --git a/test/simple/test-stream2-transform.js b/test/simple/test-stream2-transform.js index 500c48b8ac0..7a32a3cce8b 100644 --- a/test/simple/test-stream2-transform.js +++ b/test/simple/test-stream2-transform.js @@ -235,6 +235,42 @@ test('assymetric transform (compress)', function(t) { }); }); +// this tests for a stall when data is written to a full stream +// that has empty transforms. +test('complex transform', function(t) { + var count = 0; + var saved = null; + var pt = new Transform({highWaterMark:3}); + pt._transform = function(c, e, cb) { + if (count++ === 1) + saved = c; + else { + if (saved) { + pt.push(saved); + saved = null; + } + pt.push(c); + } + + cb(); + }; + + pt.once('readable', function() { + process.nextTick(function() { + pt.write(new Buffer('d')); + pt.write(new Buffer('ef'), function() { + pt.end(); + t.end(); + }); + t.equal(pt.read().toString(), 'abc'); + t.equal(pt.read().toString(), 'def'); + t.equal(pt.read(), null); + }); + }); + + pt.write(new Buffer('abc')); +}); + test('passthrough event emission', function(t) { var pt = new PassThrough();