简体   繁体   English

NodeJS Readline模块在从文件读取时修剪空格

[英]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? 有没有办法阻止Readline模块删除文件本身换行前的空格? I'm parsing a non text file and those spaces are important. 我正在解析非文本文件,这些空格很重要。

And why a Reader modifies the file it reads? 为什么Reader会修改它读取的文件?

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. 对于今天(2018)的nodejs,包n读取线确实保留了该行的全部内容,包括EOL字符。 This is very handy for counting the number of bytes seen; 这对于计算看到的字节数非常方便; as in when one is building an index to a file's contents. 就像在构建文件内容的索引时一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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