Node.js报错:_read() is not implemented

报错如下:
events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: _read() is not implemented
    at Readable._read (_stream_readable.js:551:22)
    at Readable.read (_stream_readable.js:442:10)
    at resume_ (_stream_readable.js:822:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
    at Function.Module.runMain (module.js:678:11)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
原因:

使用Readable的push方法时,最后没有关闭。

解决方法:

添加.push(null)来指明可读流已执行完毕。

例如

let Readable = require('stream').Readable;
let Writable = require('stream').Writable;

let readStream = new Readable();
let writeStream = new Writable();

readStream.push('I');
....

readStream.push(null);

你可能感兴趣的:(nodejs)