开发者社区> 镜像站> NPM> read-bytes-stream
read-bytes-stream
Read `n` bytes of a stream, then swap to another stream
Last updated 3 years ago by emilbayes .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install read-bytes-stream 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.1                                ...           latest (3 years ago)

2 Versions

  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 2
Dependencies (3)
Dev Dependencies (2)