1 var common = require('../common');
2 var assert = require('assert');
3 var util = require('util');
4 var stream = require('stream');
8 function PassThrough () {
9 stream.Transform.call(this);
11 util.inherits(PassThrough, stream.Transform);
12 PassThrough.prototype._transform = function (chunk, encoding, done) {
17 function TestStream () {
18 stream.Transform.call(this);
20 util.inherits(TestStream, stream.Transform);
21 TestStream.prototype._transform = function (chunk, encoding, done) {
23 // Char 'a' only exists in the last write
24 passed = chunk.toString().indexOf('a') >= 0;
29 var s1 = new PassThrough();
30 var s2 = new PassThrough();
31 var s3 = new TestStream();
33 // Don't let s2 auto close which may close s3
34 s2.pipe(s3, {end: false});
36 // We must write a buffer larger than highWaterMark
37 var big = new Buffer(s1._writableState.highWaterMark + 1);
40 // Since big is larger than highWaterMark, it will be buffered internally.
41 assert(!s1.write(big));
42 // 'tiny' is small enough to pass through internal buffer.
43 assert(s2.write('tiny'));
45 // Write some small data in next IO loop, which will never be written to s3
46 // Because 'drain' event is not emitted from s1 and s1 is still paused
47 setImmediate(s1.write.bind(s1), 'later');
49 // Assert after two IO loops when all operations have been done.
50 process.on('exit', function () {
51 assert(passed, 'Large buffer is not handled properly by Writable Stream');