rvagg / through2

Tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise
MIT License
1.9k stars 106 forks source link

Object `Transform`s not working well with `stream.compose` #114

Open WRtux opened 1 year ago

WRtux commented 1 year ago

Putting Transforms created by through2.obj first when using stream.compose function (introduced in Node.js 16) with object inputs causes type error, just like putting non-object Transforms in it does. Nevertheless, putting normal Transforms created by its constructor first and through2.obj in the middle works right.

Though using normal Transforms avoids the problem, as a lot of plugins like in gulp use through2 internally, it would be nice if this can be fixed.

Node version: v16.17.1

Snippet:

stream.Readable.from([{}])
    .pipe(stream.compose(
        require('through2').obj((chunk, enc, callback) => callback(null, chunk))
    ));

The error log:

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of File
    at new NodeError (node:internal/errors:387:5)
    at _write (node:internal/streams/writable:314:13)
    at ComposeDuplex.Writable.write (node:internal/streams/writable:336:10)
    at Readable.ondata (node:internal/streams/readable:754:22)
    at Readable.emit (node:events:513:28)
    at Readable.emit (node:domain:552:15)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Readable.push (node:internal/streams/readable:228:10)
    at Projects\...\node_modules\fork-stream\index.js:51:13