我有以下简单的功能来复制nodejs
function copyFileSync(source, target) {
var readerStream = fs.createReadStream(source);
var writerStream = fs.createWriteStream(target);
readerStream.pipe(writerStream);
}
readerStream.length == 0
我无法理解,因为source
是一个现有的,格式正确的文件。结果是创建一个空的target
文件。至于调试,我注意到没有发出data
事件。我还将文件权限设置为777
。
这是readerStream
对象的日志:
{
"_readableState":{
"highWaterMark":65536,
"buffer":[
],
"length":0,
"pipes":null,
"pipesCount":0,
"flowing":false,
"ended":false,
"endEmitted":false,
"reading":false,
"calledRead":false,
"sync":true,
"needReadable":false,
"emittedReadable":false,
"readableListening":false,
"objectMode":false,
"defaultEncoding":"utf8",
"ranOut":false,
"awaitDrain":0,
"readingMore":false,
"decoder":null,
"encoding":null
} ,
"readable":true,
"domain":null,
"_events":{
},
"_maxListeners":10,
"path":"/my/file/path",
"fd":null,
"flags":"r",
"mode":438,
"autoClose":true
}