From 9ca7aced8a7ff7eabd90611414aab8cf38749075 Mon Sep 17 00:00:00 2001 From: zero1five Date: Sun, 19 May 2019 03:15:13 +0800 Subject: [PATCH] doc: add code sample for WriteStream Add a code example for WriteStream(alse explaining `ws and `rs`) to compare and briefly explain with ReadStream. --- doc/api/fs.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/api/fs.md b/doc/api/fs.md index 9e3b0df9a487b9..19c22e127dd0eb 100644 --- a/doc/api/fs.md +++ b/doc/api/fs.md @@ -1569,6 +1569,16 @@ should be passed to [`net.Socket`][]. If `options` is a string, then it specifies the encoding. +```js +// Create a stream of file copy functions +const fs = require('fs'); + +const rs = fs.createReadStream('./out.txt'); +const ws = fs.createWriteStream('./input.txt', { flags: 'a' }); + +rs.pipe(ws); // Out.txt content pipe to input.txt +``` + ## fs.exists(path, callback)