Created
May 17, 2021 08:52
-
-
Save bytemain/bd01b1cca2ddef1c8fb3a9138a7b0a3b to your computer and use it in GitHub Desktop.
Nodejs read buffer line by line. source: https://stackoverflow.com/questions/36896841/read-strings-line-by-line-from-buffer-instance-in-node-js-module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require('fs'); | |
| var readline = require('readline'); | |
| var stream = require('stream'); | |
| const buf = fs.readFileSync('./1.txt'); | |
| var bufferStream = new stream.PassThrough(); | |
| bufferStream.end(buf); | |
| var rl = readline.createInterface({ | |
| input: bufferStream, | |
| }); | |
| rl.on('line', function (line) { | |
| if (line.includes('report_id')) { | |
| console.log('content = ' + line); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment