简体   繁体   中英

NodeJS Readline module is trimming whitespaces when reading from a file

Is there a way to prevent Readline module from removing a whitespace that comes before the line break in the file itself? I'm parsing a non text file and those spaces are important.

And why a Reader modifies the file it reads?

I've tried using a terminal mode, no success there...

const readline = require('readline');
const fs = require('fs');
...
// Init reader interface
this.lineReader = readline.createInterface({
    input: fs.createReadStream(this.inputFile),
    terminal: true
});

this.lineReader.on('line', (line) => {
    return callback(null, line);
});

For the nodejs of today (2018), the package n-readlines does the trick of preserving the entire contents of the line, including the EOL characters. This is very handy for counting the number of bytes seen; as in when one is building an index to a file's contents.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM