How to convert Web Stream to NodeJS native Stream
Asked Answered
G

2

2

I am taking file input from user as

<input type="file"/>

It returns file object has Blob. This object has a method .stream() which returns ReadableStream. Now, i want to pass this stream to stream-json library. But it takes NodeJS native stream - Readable. Now, how do i convert the ReadableStream (webstream) to Readable (node stream) ?

Gilded answered 17/3, 2022 at 8:59 Comment(1)
"This object has a method .stream()" what is "this" object?! Post more info, complete the Tour and read "How to Ask". If possible you should provide a Minimal, Reproducible ExamplePyrite
P
2

Node has an helper function:

https://nodejs.org/api/stream.html#streamreadablefromwebreadablestream-options

Another more complex way is to implement a node stream that consumes the web stream.

Pipit answered 1/5, 2022 at 14:33 Comment(0)
T
0
import { Stream } from 'stream';
    
const readable = Stream.Readable.fromWeb(readableStream);
Triangular answered 15/7 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.