summaryrefslogtreecommitdiff
path: root/doc/api/stream.md
diff options
context:
space:
mode:
authorIvan Filenko <ivan.filenko@protonmail.com>2018-02-15 23:53:13 +0300
committerVse Mozhet Byt <vsemozhetbyt@gmail.com>2018-02-16 23:34:32 +0200
commit755d805bf471423631fb8320b223298c88a61969 (patch)
tree6fb582181871a78e2a0241e15da8948f84a2740b /doc/api/stream.md
parent94e8d2a5ff410a51ee0845782801844babea6031 (diff)
downloadandroid-node-v8-755d805bf471423631fb8320b223298c88a61969.tar.gz
android-node-v8-755d805bf471423631fb8320b223298c88a61969.tar.bz2
android-node-v8-755d805bf471423631fb8320b223298c88a61969.zip
doc: add fs declarations to stream doc js examples
PR-URL: https://github.com/nodejs/node/pull/18804 Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Diffstat (limited to 'doc/api/stream.md')
-rw-r--r--doc/api/stream.md6
1 files changed, 6 insertions, 0 deletions
diff --git a/doc/api/stream.md b/doc/api/stream.md
index 023ba4d77b..14be27cbf2 100644
--- a/doc/api/stream.md
+++ b/doc/api/stream.md
@@ -378,6 +378,7 @@ Calling the [`stream.write()`][stream-write] method after calling
```js
// write 'hello, ' and then end with 'world!'
+const fs = require('fs');
const file = fs.createWriteStream('example.txt');
file.write('hello, ');
file.end('world!');
@@ -861,6 +862,7 @@ The following example pipes all of the data from the `readable` into a file
named `file.txt`:
```js
+const fs = require('fs');
const readable = getReadableStreamSomehow();
const writable = fs.createWriteStream('file.txt');
// All the data from readable goes into 'file.txt'
@@ -872,6 +874,7 @@ The `readable.pipe()` method returns a reference to the *destination* stream
making it possible to set up chains of piped streams:
```js
+const fs = require('fs');
const r = fs.createReadStream('file.txt');
const z = zlib.createGzip();
const w = fs.createWriteStream('file.txt.gz');
@@ -1036,6 +1039,7 @@ If the `destination` is specified, but no pipe is set up for it, then
the method does nothing.
```js
+const fs = require('fs');
const readable = getReadableStreamSomehow();
const writable = fs.createWriteStream('file.txt');
// All the data from readable goes into 'file.txt',
@@ -1173,6 +1177,8 @@ added: REPLACEME
Returns an [AsyncIterator][async-iterator] to fully consume the stream.
```js
+const fs = require('fs');
+
async function print(readable) {
readable.setEncoding('utf8');
let data = '';