【问题标题】:Count bytes from Busboy stream从 Busboy 流中计算字节数
【发布时间】:2015-10-13 19:51:02
【问题描述】:

我从 Busboy 获取文件流,然后我需要计算字节数,抓取第一行,然后将其发送到天蓝色存储。它适用于最大约 25MB 的文件,但之后不计算所有字节。我不知道如何让它等待。我使用直通流只是为了在获取第一行时保存原始数据。

busboy
.on('file', function(fieldname, file, filename, encoding, mimetype) {
    file
    .on('data', function(data) {
        bytes = bytes + data.length;
    })
    .on('end', function() {
        console.log("end");
    })
    .pipe(passthrough)
    .pipe(firstLine)
    .pipe(es.wait(function (err, body) {
        blobService.createBlockBlobFromStream(containter, name, passthrough, bytes, function (error, result) {
            if(error) {
                return sendResponse(error.toString(), res, null);
            }
            sendResponse(null, res, "done");
        });
    }));
})
.on('finish', function() {
    console.log("busboy done");
});

【问题讨论】:

    标签: node.js stream busboy


    【解决方案1】:

    如果要将数据通过管道传输到 blob,createWriteStreamToBlockBlob 是您可能需要的 API。

    busboy
    .on('file', function(fieldname, file, filename, encoding, mimetype) {
      file
      .on('data', function(data) {
        bytes = bytes + data.length;
      })
      .on('end', function() {
        console.log("end");
      })
      .pipe(passthrough)
      .pipe(firstLine)
      .pipe(blobService.createWriteStreamToBlockBlob(containter, name, function (error, result) {
         if(error) {
            return sendResponse(error.toString(), res, null);
         }
         sendResponse(null, res, "done");
      }))
    })
    .on('finish', function() {
      console.log("busboy done");
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-06
      • 1970-01-01
      • 2016-10-27
      • 2015-08-08
      • 1970-01-01
      相关资源
      最近更新 更多