【发布时间】:2013-07-23 05:53:57
【问题描述】:
我正在通过双工字符串(through 提供)传输文件,并且无法将信息打印到 stdout 写入文件。一个或另一个工作得很好。
var fs = require('fs');
var path = require('path');
var through = require('through'); // easy duplexing, i'm young
catify = new through(function(data){
this.queue(data.toString().replace(/(woof)/gi, 'meow'));
});
var reader = fs.createReadStream('dogDiary.txt'); // woof woof etc.
var writer = fs.createWriteStream(path.normalize('generated/catDiary.txt')); // meow meow etc.
// yay!
reader.pipe(catify).pipe(writer)
// blank file. T_T
reader.pipe(catify).pipe(process.stdout).pipe(writer)
我假设这是因为process.stdout 是一个可写流,但我不确定如何做我想做的事情(我试过传递{end: false} 无济于事)。
仍在努力将我的头包裹在溪流中,如果我错过了一些明显的东西,请原谅我:)
【问题讨论】: