You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.pipe() and .pipeTo() fail when the source stream is constructed from a Buffer #56297
Darwin XXXXXXXXXX 24.2.0 Darwin Kernel Version 24.2.0: Fri Dec 6 19:01:59 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6000 arm64
Subsystem
stream
What steps will reproduce the bug?
constpath=require('node:path');constfs=require('node:fs');const{ Readable, Writable }=require('node:stream');constfileBuffer=fs.readFileSync(__filename);constreadable=fs.createReadStream(path.resolve(__filename));constwritable=fs.createWriteStream(`${__filename}_copy`);constwebReadable=Readable.toWeb(readable);constwebWritable=Writable.toWeb(writable);constwebReadableFromBuffer=ReadableStream.from(fileBuffer);constreadableFromBuffer=Readable.from(fileBuffer);constreadableFromWebReadableFromBuffer=Readable.from(webReadableFromBuffer);constreadableFromWebReadableFromReadable=Readable.from(webReadable);// readable.pipe(writable);// OK// readableFromBuffer.pipe(writable);// OK// readableFromWebReadableFromReadable.pipe(writable);// OK// webReadable.pipeTo(webWritable);// TypeError [ERR_INVALID_STATE]: Invalid state: The ReadableStream is locked// webReadableFromBuffer.pipeTo(webWritable);// TypeError [ERR_INVALID_STATE]: Invalid state: The ReadableStream is locked// readableFromWebReadableFromBuffer.pipe(writable);// TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (60)
How often does it reproduce? Is there a required condition?
Every time. No preconditions.
What is the expected behavior? Why is that the expected behavior?
All the above combinations should succeed.
What do you see instead?
Errors in the cases where the Readable or ReadableStream is constructed from a Buffer.
Creating a new stream each time solves the problem of the ReadableStream being locked:
constpath=require('node:path');constfs=require('node:fs');const{ Readable, Writable }=require('node:stream');constfileBuffer=()=>fs.readFileSync(__filename);constreadable=()=>fs.createReadStream(path.resolve(__filename));constwritable=()=>fs.createWriteStream(`${__filename}_copy`);constwebReadable=()=>Readable.toWeb(readable());constwebWritable=()=>Writable.toWeb(writable());constwebReadableFromBuffer=()=>ReadableStream.from(fileBuffer());constreadableFromBuffer=()=>Readable.from(fileBuffer());constreadableFromWebReadableFromBuffer=()=>Readable.from(webReadableFromBuffer());// If we don't return a new webReadable every time, the one we create gets// locked at this point, because it is used exclusively by the Readable that// wraps it.constreadableFromWebReadableFromReadable=()=>Readable.from(webReadable());// readable().pipe(writable());// OK// readableFromBuffer().pipe(writable());// OK// readableFromWebReadableFromReadable().pipe(writable());// OK// webReadable().pipeTo(webWritable());// OK// webReadableFromBuffer().pipeTo(webWritable());// TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (99)// readableFromWebReadableFromBuffer().pipe(writable());// TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (99)
Activity
gabrielschulhof commentedon Dec 17, 2024
Potentially related: #56139
gabrielschulhof commentedon Dec 17, 2024
Also potentially related: #44866
gabrielschulhof commentedon Dec 30, 2024
Creating a new stream each time solves the problem of the ReadableStream being locked:
gabrielschulhof commentedon Dec 30, 2024
As best I can tell,
outputs a sequence of numbers, whereas doing the same loop over a ReadableStream in a browser outputs a sequence of Uint8Array objects like
This may be the discrepancy.
gabrielschulhof commentedon Dec 30, 2024
OK. Need to pass a sequence of buffers to
ReadableStream.from().doc: add example for piping ReadableStream
doc: add example for piping ReadableStream
doc: add example for piping ReadableStream
doc: add example for piping ReadableStream
doc: add example for piping ReadableStream
doc: add example for piping ReadableStream