Skip to content

unpipe() and resume() in _transform() #31190

Closed
@utftu

Description

@utftu
  • Node.js Version: 13.*
  • OS: mac
  • Scope (install, code, runtime, meta, other?):
  • Module (and version) (if relevant):

In case of synchronous pipe removal in _transform, the resume method does not resume as expected

const stream = require('stream')

const fs = require('fs');
const readStream = fs.createReadStream('big.txt')
const writeStream = fs.createWriteStream('result.txt');

const transformStream = new class extends stream.Transform {

  _transform(chunk, encoding, callback) {
    readStream.unpipe()
    readStream.resume()
  }
}

readStream.on('end', () => {
  console.log('never print')
})


readStream
  .pipe(transformStream)
  .pipe(writeStream)

Nevertheless, resume operation during an asynchronous call and removal not from the _transform method

Can someone explain this behavior why unpipe () and resume () do not work in the _transform method?

Metadata

Metadata

Assignees

No one assigned

    Labels

    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