【问题标题】:NodeJS Readline module is trimming whitespaces when reading from a file从文件读取时,NodeJS Readline 模块正在修剪空格
【发布时间】:2016-08-02 05:25:12
【问题描述】:

有没有办法防止 Readline 模块删除文件本身换行符之前的空格?我正在解析一个非文本文件,这些空格很重要。

为什么 Reader 会修改它读取的文件?

我试过使用终端模式,没有成功...

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);
});

【问题讨论】:

    标签: node.js readline


    【解决方案1】:

    对于今天(2018 年)的 nodejs,包 n-readlines 可以保留行的全部内容,包括 EOL 字符。这对于计算看到的字节数非常方便;就像为文件内容建立索引一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-06
      • 2012-03-14
      • 1970-01-01
      • 1970-01-01
      • 2018-01-15
      相关资源
      最近更新 更多