node package manager
We need your input. Help make JavaScript better: Take the 2017 JavaScript Ecosystem survey »

buffer-to-stream

Build Status npm version Dependency Status

buffer-to-stream

Convert buffer or string to readable stream.

NPM

Usage

const toStream = require('buffer-to-stream')
 
const readable = toStream(Buffer.from('hello world!', 'utf8'))
readable.on('readable', () => {
  let chunk
  while ((chunk = reader.read()) !== null) {
    console.log('got data', chunk)
  }
})
readable.on('end', () => console.log('done'))

API

toStream(buffer[, chunkSize])

  • buffer is the source buffer or string, and the type is String|Buffer.
  • chunkSize specifies stream data push chunk size, and type is Number.

And the return value is a readable stream.

License

MIT