| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 787c5d9 commit 3912b5c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -232,6 +232,22 @@ line interface: | |||
| 232 | 232 | process.exit(0); | |
| 233 | 233 | }); | |
| 234 | 234 | ||
| 235 | + ## Example: Read File Stream Line-by-Line | ||
| 236 | + | ||
| 237 | + A common case for `readline`'s `input` option is to pass a filesystem readable | ||
| 238 | + stream to it. This is how one could craft line-by-line parsing of a file: | ||
| 239 | + | ||
| 240 | + const readline = require('readline'); | ||
| 241 | + const fs = require('fs'); | ||
| 242 | + | ||
| 243 | + const rl = readline.createInterface({ | ||
| 244 | + input: fs.createReadStream('sample.txt') | ||
| 245 | + }); | ||
| 246 | + | ||
| 247 | + rl.on('line', function (line) { | ||
| 248 | + console.log('Line from file:', line); | ||
| 249 | + }); | ||
| 250 | + | ||
| 235 | 251 | ## readline.clearLine(stream, dir) | |
| 236 | 252 | ||
| 237 | 253 | Clears current line of given TTY stream in a specified direction. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments