Skip to content

piordev555/readable-stream-buf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

readable-stream-buffer-stream

Build status Coverage Status Dependencies Status

An async iterator that emits buffers containing bytes up to a certain length

Install

$ npm install --save readable-stream-buffer-stream

Usage

const totalLength = //... a big number

// all options are optional, defaults are shown
const options = {
  chunkSize: 4096, // how many bytes will be in each buffer
  generator: (size, callback) => {
    // call the passed callback with a Buffer object `size` bytes long.
    //
    // if omitted, `Promise.resolve(crypto.randomBytes(size))` will be used
  }
}

let buffers = []

const stream = bufferStream(totalLength, options)
stream.on('data', (buf) => {
  buffers.push(buf)
})
stream.on('end', (buf) => {
  if (buf) {
    buffers.push(buf)
  }

  // `buffers` is an array of Buffers the combined length of which === totalLength
})

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages