# stream

# streamToBuffer

streamToBuffer (stream) {
  return new Promise((resolve, reject) => {
    let buffers = []
    stream.on('error', reject)
    stream.on('data', (data) => buffers.push(data))
    stream.on('end', () => resolve(Buffer.concat(buffers))
  })
}

# bufferToStream

bufferToStream (buffer) {
  const Duplex = require('stream').Duplex
  const stream = new Duplex()
  stream.push(buffer)
  stream.push(null)
  return stream
}
上次更新: 2021/8/25 下午2:06:48