Home > Web Front-end > JS Tutorial > Read stream Write Stream Work together use(Pipe)

Read stream Write Stream Work together use(Pipe)

Linda Hamilton
Release: 2025-01-07 20:33:42
Original
764 people have browsed it

Read stream Write Stream Work together use(Pipe)

const fs = require('fs');
const readStream = fs.createReadStream('input.txt');
const writeStream = fs.createWriteStream('output.txt');

// Pipe the readable stream to the writable stream
readStream.pipe(writeStream);

// You can also handle events for more control
readStream.on('data', chunk => {
console.log(Reading chunk: ${chunk.length} bytes);
});

writeStream.on('finish', () => {
console.log('Write operation finished!');
});

The above is the detailed content of Read stream Write Stream Work together use(Pipe). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template