read-bytes-stream

1.0.1 • Public • Published

read-bytes-stream

Build Status

Read n bytes of a stream, then swap to another stream

Usage

var readBytes = require('read-bytes-stream')
var xsalsaStream = require('...')
 
var nonce = Buffer.alloc(32)
var key = Buffer.from('my secret key')
 
var streamCipher = readBytes(32, function (bytes, swap) {
  if (bytes.length < 32) return swap(new Error('Too few bytes'))
 
  nonce.set(bytes)
 
  swap(null, xsalsaStream(nonce, key))
})
 

API

var stream = readBytes(n, onchunk)

Will read n bytes, unless the source stream ends prematurely. onchunck(bytes, swap) will be called with as many bytes as was read, but at most n, and a callback to either return an Error or swap to another stream. You can optionally re-write the received bytes to the new stream which effectively turns this module into peek-stream

Install

npm install read-bytes-stream

License

ISC

Package Sidebar

Install

npm i read-bytes-stream

Weekly Downloads

7

Version

1.0.1

License

ISC

Last publish

Collaborators

  • emilbayes