From e042946bce0542b9e057cb31e8199aa348eee3c4 Mon Sep 17 00:00:00 2001 From: Ivan Filenko Date: Thu, 15 Feb 2018 23:53:13 +0300 Subject: [PATCH] doc: add fs declarations to stream doc js examples --- doc/api/stream.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/api/stream.md b/doc/api/stream.md index 023ba4d77ba489..14be27cbf2d911 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 = '';