writeStream open事件上的多个管道给出了undefined

时间:2017-02-09 21:53:07

标签: javascript node.js stream fs serverside-javascript

我正在从URL下载文件,然后我想在确保创建目标文件后(即在fs.createWriteStream(path)成功之后)将该文件的元数据写入目标流。所以我使用了" open"可写流的事件继续进行。但是,这段代码完全在第二个管道上给出了错误:

var fs = require('fs');
var digestStream = require('digest-stream')
callHandle();


function callHandle(){
   var stream  = request.get(url)
   var result = {}
   handle(reader, result)
}

function handle(reader,metadata){
const writer = fs.createWriteStream('pathToFile');
writer.on('open', function(){
    reader.pipe(
        digestStream('sha1', 'hex', function(digest, length) {
            result.sha1 = digest;
            result.size = length;
        }))
        .pipe(
            digestStream('md5', 'hex', function(digest) {
                result.md5 = digest;
            })
        ).pipe(writer)
   })
  }

除此之外还有更多代码使用此处计算的哈希值。但不知怎的,我现在仍然坚持这个错误。我一直在努力解决这个问题。非常感谢任何帮助/指针。

我还尝试运行示例

For a = 1 To ScenarioTableLastRow
    For f = 1 To ScenarioTableLastColumn

       If Cells(a, f) <> "" Then
            Cells(a, f) = Excel.Application.Trim(Cells(a, f))
       End If

    Next f
Next a

0 个答案:

没有答案