我现在正在学习nodejs,并试图建立一个简单的转换流。我正在创建的代码与一些教程相似-但我不断遇到错误。
现在,我只是尝试直接传递数据,但不做任何更改(为简便起见,我删除了一些注释行):

newstream.js:

var fs = require('fs');
var makeBig = require('./makeBig');

var myReadStream = fs.createReadStream(__dirname + '/Sample.txt');
var myWriteStream = fs.createWriteStream(__dirname + '/WriteMe.txt')

myReadStream
.pipe(makeBig)
.pipe(myWriteStream);


makeBig.js:

const Transform = require('stream').Transform;
const makeBig = new Transform({
        transform(chunk, encoding, callback){
        //chunk = chunk.toUpperCase();
        //console.log(chunk);
        this.push(chunk);
        callback();
    }
});


makeBig.js遵循NodeJS v7.9.0文档中描述的“ Simplified Constructor Approach”形式。

这是我得到的错误:

$ node newStream.js
_stream_readable.js:501
  dest.on('unpipe', onunpipe);
       ^

TypeError: dest.on is not a function
    at ReadStream.Readable.pipe (_stream_readable.js:501:8)
    at Object.<anonymous> (/home/thodges/Workspace/Node/streams/newStream.js:15:2)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)

最佳答案

您的makeBig.js文件中是否包含module.exports = makeBig;

09-05 10:29