const response = await fetch('https://www.google.com')
response.body.pipeThrough(new TextDecoderStream()).pipeTo(process.stdout)
TypeError [ERR_INVALID_ARG_TYPE]: The "transform.writable" property must be an instance of WritableStream. Received an instance of WriteStream
process.stdout
) be converted to a writable stream?I tried to make stdout writable to no avail:
// fails
process.stdout.writable = true
response.body.pipeTo(process.stdout)
Some methods that work include:
// works
const response = await fetch('http://www.google.com')
const reader = response.body.pipeThrough(new TextDecoderStream())
for await (const chunk of reader){
process.stdout.write(chunk)
}
// works
Readable.fromWeb(response.body).pipe(process.stdout)
I don't exactly understand the difference between a "web" stream and a "node" stream, which I'm guessing are just source and destination, but I thought every I/O stream was able to redirect to each other. It seems like using the Readable.fromWeb
works, but what is it doing? It seems inefficient.
Can the reverse be done to process.stdout
? Something like...
response.body.pipeTo(new WritableStream(process.stdout)
WriteStream is a stream that is writable to a file.
WritableStream is a stream that is writable to a destination. It can be a file, a socket, a pipe, etc.
Can the reverse be done to
process.stdout
? Something like...
Yes, see Stream.Writable.toWeb
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With