Node.js Stream readable[Symbol.asyncIterator]() Method Last Updated : 11 Oct, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The readable[Symbol.asyncIterator]() method in a Readable Stream is utilized to fully consume the stream. Syntax: readable[Symbol.asyncIterator]() Parameters: This method does not accept any parameters. Return Value: It returns asyncIterator to fully consume the stream. Below examples illustrate the use of readable[Symbol.asyncIterator]() method in Node.js: Example 1: JavaScript // Node.js program to demonstrate the // readable[Symbol.asyncIterator]() // method // Include fs module const fs = require('fs'); // Using async function async function print(readable) { // Setting the encoding readable.setEncoding('utf8'); let data = ''; for await (const chunk of readable) { data += chunk; } console.log(data); } print(fs.createReadStream('input.text')).catch(console.error); Output: Promise { <Pending> } GeeksforGeeks Example 2: JavaScript // Node.js program to demonstrate the // readable[Symbol.asyncIterator]() // method // Constructing readable from stream const { Readable } = require('stream'); // Using async function async function * generate() { yield 'GfG'; yield 'CS-Portal'; } // Creating readable streams from iterables const readable = Readable.from(generate()); readable.on('data', (chunk) => { console.log(chunk); }); console.log("program ends!!!"); Output: program ends!!! GfG CS-Portal Reference: https://nodejs.org/api/stream.html#stream_readable_symbol_asynciterator. Comment More infoAdvertise with us Next Article Node.js Stream readable.destroy() Method N nidhi1352singh Follow Improve Article Tags : Web Technologies Node.js Node.js-Stream-module Similar Reads Node.js Stream readable.destroy() Method The readable.destroy() method is an inbuilt application programming interface of Stream module which is used to destroy the stream. Syntax: readable.destroy( error ) Parameters: This method accepts single parameter error which is optional and it emits an error while handling error event. Return Valu 2 min read Node.js stream.Readable.from() Method The stream.Readable.from() method is an inbuilt application programming interface of the Stream module which is used to construct Readable Streams out of iterators. Syntax: stream.Readable.from( iterable, options ) Parameters: This method accept two parameters as mentioned above and described below: 2 min read Node.js Stream readable.isPaused() Method The readable.isPaused() method is an inbuilt application programming interface of Stream module which is used to check the current operating state of the Readable streams. Syntax: readable.isPaused() Parameters: This method does not accept any parameters. Return Value: It returns true if the Readabl 1 min read Node.js Stream readable.unshift() Method The readable.unshift() method in a Readable Stream is utilized to push a chunk of data back into the internal buffer. However, when a stream is being fully consumed and it needs to be "un-consumed" then this method is helpful. Syntax: readable.unshift( chunk, encoding ) Parameters: This method accep 2 min read Node.js Stream readable.read() Method The readable.read() method is an inbuilt application programming interface of Stream module which is used to read the data out of the internal buffer. It returns data as a buffer object if no encoding is being specified or if the stream is working in object mode. Syntax: readable.read( size ) Parame 2 min read Node.js Stream readable.pipe() Method The readable.pipe() method in a Readable Stream is used to attach a Writable stream to the readable stream so that it consequently switches into flowing mode and then pushes all the data that it has to the attached Writable. Syntax:readable.pipe( destination, options )Parameters: This method accepts 2 min read Like