【问题标题】:What is experimental in this Node snippet that reads a file?在这个读取文件的节点片段中有什么实验性的?
【发布时间】:2019-06-18 08:36:07
【问题描述】:

我从这里运行代码:

https://nodejs.org/dist/latest-v10.x/docs/api/readline.html#readline_example_read_file_stream_line_by_line

const fs = require('fs');
const readline = require('readline');

async function processLineByLine() {
  const fileStream = fs.createReadStream('input.txt');

  const rl = readline.createInterface({
    input: fileStream,
    crlfDelay: Infinity
  });
  // Note: we use the crlfDelay option to recognize all instances of CR LF
  // ('\r\n') in input.txt as a single line break.

  for await (const line of rl) {
    // Each line in input.txt will be successively available here as `line`.
    console.log(`Line from file: ${line}`);
  }
}

processLineByLine();

并收到此警告:

(node:13735) ExperimentalWarning: readline Interface [Symbol.asyncIterator] is an experimental feature. This feature could change at any time
(node:13735) ExperimentalWarning: Readable[Symbol.asyncIterator] is an experimental feature. This feature could change at any time

究竟什么是实验性的?没有行号。

【问题讨论】:

    标签: javascript node.js


    【解决方案1】:

    上面写着:

    readline 接口 [Symbol.asyncIterator]

    所以找个接口:

    const rl = readline.createInterface
    

    您正在迭代:

    const line of rl
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-31
      • 2016-09-19
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-25
      • 1970-01-01
      相关资源
      最近更新 更多