NodeJS:Readstream.read() 无法与 Buffer.concat() 一起使用

NodeJS: Readstream.read() not working with Buffer.concat()

我正在尝试使用以下代码创建 BlobContentReadStream 中读取 chunks指定的 thresholdSize 然后将其传递给函数 putBlock():

let blobContent = Buffer.from([])
let contentLength = 0
const thresholdSize = 100 * 1024

readStream.on('readable', function () {
  let chunk
  while (null !== (chunk = readStream.read())) {
    Buffer.concat([blobContent, chunk], blobContent.length + chunk.length)
    contentLength = contentLength + chunk.length
    if (contentLength >= thresholdSize) {
      putBlock(blobContent, contentLength)
      contentLength = 0
      blobContent = Buffer.from([])
    }
  }
})

我没有得到此代码预期的 BlobContent。 有人可以检查出什么问题吗?

Buffer.concat returns 一个新的 Buffer,它是将列表中的所有 Buffer 实例连接在一起的结果。

所以尝试 blobContent = Buffer.concat([blobContent, chunk])