Skip to content

Transform stream misses final readable event for small inputs #25810

Closed
@sfriesel

Description

@sfriesel
  • Version: v11.8.0
  • Platform: Ubuntu 18.10
  • Subsystem: stream

A Transform stream that transforms the entire input in one shot will generate just one readable event, when it should be two (one for data and one for EOS).

const stream = require('stream')
const fs = require('fs');

const r = new stream.Readable();
r._read = function(n) { this.push('content'); this.push(null); };
// const r = fs.createReadStream('/boot/memtest86+.bin');

var t = new stream.Transform({
  transform: function(chunk, encoding, callback) {
    console.log('_transform');
    this.push(chunk);
    return void callback();
  },
  flush: function(callback) {
    console.log('_flush');
    return void callback();
  }
});

r.pipe(t);
t.on("readable", function() {
  console.log("on readable");
  while (true) {
    var chunk = t.read();
    console.log("chunk", chunk);
    if (!chunk)
      break;
  }
});

The output of this example is:

_transform
_flush
on readable
chunk <Buffer 63 6f 6e 74 65 6e 74>
chunk null

But it should be

_transform
_flush
on readable
chunk <Buffer 63 6f 6e 74 65 6e 74>
chunk null
on readable
chunk null

Using a larger input stream (like the commented out line) correctly produces the last readable event.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions