1.0.2 • Published 5 years ago

pull-buffer-stream v1.0.2

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

pull-buffer-stream

Build status Coverage Status Dependencies Status

Emits streams of buffers

Install

$ npm install --save pull-buffer-stream

Usage

Generate streams of buffers containing bytes up to a certain length:

const pull = require('pull-stream')
const bufferStream = require('pull-buffer-stream')

const totalLength = //... a big number

// all options are optional, defaults are shown
const options = {
  chunkSize: 4096, // how many bytes will be in each buffer
  collector: (buffer) => {
    // will be called as each buffer is generated. the final buffer
    // may be smaller than `chunkSize`
  },
  generator: (size, callback) => {
    // generate a buffer of length `size` and pass it to the callback in
    // the `callback(error, buffer)` style
    //
    // if omitted, `crypto.randomBytes(size)` will be used
  }
}

pull(
  bufferStream(totalLength, options),
  pull.collect((error, buffers) => {
    // `buffers` is an array of Buffers the combined length of which === totalLength
  })
)
1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago