From 755d805bf471423631fb8320b223298c88a61969 Mon Sep 17 00:00:00 2001 From: Ivan Filenko Date: Thu, 15 Feb 2018 23:53:13 +0300 Subject: doc: add fs declarations to stream doc js examples PR-URL: https://github.com/nodejs/node/pull/18804 Reviewed-By: Weijia Wang Reviewed-By: Ruben Bridgewater Reviewed-By: James M Snell Reviewed-By: Vse Mozhet Byt --- doc/api/stream.md | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'doc/api/stream.md') 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 = ''; -- cgit v1.2.3