Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Node Stream to Web Stream

How to convert NodeJS stream to Web Stream

import * as fs from 'node:fs';
const nodeReadable = fs.createReadStream('data.txt', {encoding: 'utf-8'});
like image 859
Rex Pan Avatar asked Sep 02 '26 18:09

Rex Pan


1 Answers

We can use the Readable.toWeb(), Writable.toWeb().

import * as fs from 'node:fs';
import {Readable} from 'node:stream';
const nodeReadable = fs.createReadStream('data.txt', {encoding: 'utf-8'});
const webReadableStream = Readable.toWeb(nodeReadable);

const nodeWritable = fs.createWriteStream('data.txt', {encoding: 'utf-8'});
const webWritableStream = Writable.toWeb(nodeWritable);
like image 72
Rex Pan Avatar answered Sep 05 '26 18:09

Rex Pan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!