gpt4 book ai didi

javascript - 基本的 Node.js 转换流出现问题

转载 作者:行者123 更新时间:2023-12-03 04:26:15 25 4
gpt4 key购买 nike

我现在正在学习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 遵循 ' Simplified Constructor Approach ' NodeJS v7.9.0 文档中描述的形式。

以下是我收到的错误:

$ 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; 吗?

关于javascript - 基本的 Node.js 转换流出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43702053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com