From 89b2254a7531a32a202336635ae5d3b07192e4a1 Mon Sep 17 00:00:00 2001 From: Robert Jefe Lindstaedt Date: Sun, 10 Jan 2016 17:18:49 +0100 Subject: [PATCH 1/2] docs: Adds usage of readline line-by-line parsing In order to make developers aware of node-core built-in functionality, which might replace module APIs, we should add an example of readline`s interface usage. SEO will eventually aid this goal, since it is well searched on Q&A sites. PR-URL: #4609 Reviewed-By: --- doc/api/readline.markdown | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/api/readline.markdown b/doc/api/readline.markdown index 05a52cd25cc390..86690dc07c0576 100644 --- a/doc/api/readline.markdown +++ b/doc/api/readline.markdown @@ -232,6 +232,22 @@ line interface: process.exit(0); }); +## Example: Read File Stream Line-by-Line + +Also a common case for `readline`'s `input` option is passing a file system +readable Stream to it. This is how one could craft line-by-line parsing: + + const readline = require('readline'); + const fs = require('fs'); + + const rl = readline.createInterface({ + input: fs.createReadStream('sample.txt') + }); + + rl.on('line', function (line) { + console.log('Line from file:', line); + }); + ## readline.clearLine(stream, dir) Clears current line of given TTY stream in a specified direction. From 228dd240fd556d7995a76aa1641a183626f03da4 Mon Sep 17 00:00:00 2001 From: Robert Jefe Lindstaedt Date: Mon, 11 Jan 2016 12:04:33 +0100 Subject: [PATCH 2/2] readline parsing example: change of wording --- doc/api/readline.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/readline.markdown b/doc/api/readline.markdown index 86690dc07c0576..a83b492b0b5621 100644 --- a/doc/api/readline.markdown +++ b/doc/api/readline.markdown @@ -234,8 +234,8 @@ line interface: ## Example: Read File Stream Line-by-Line -Also a common case for `readline`'s `input` option is passing a file system -readable Stream to it. This is how one could craft line-by-line parsing: +A common case for `readline`'s `input` option is to pass a filesystem readable +stream to it. This is how one could craft line-by-line parsing of a file: const readline = require('readline'); const fs = require('fs');