Nodejs清空ReadableStream

时间:2015-08-11 03:46:40

标签: node.js filestream fs

我有以下简单的功能来复制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
}

0 个答案:

没有答案