multibuffer-stream

A streaming interface for multibuffer.

npm install multibuffer-stream
8 downloads in the last day
62 downloads in the last week
155 downloads in the last month

multibuffer-stream

NPM

david-dm david-dm

A streaming version of multibuffer

This is useful for packaging your buffers to cross transport layers that may alter the stream frame boundaries (e.g. combine chunks or break in the middle of them) so they can be re-assembled into the original buffers.

var mbstream = require("multibuffer-stream")
var through2 = require("through2")
var spigot = require("stream-spigot")

spigot(["my", "dear", "aunt", "sally"])
  .pipe(mbstream.packStream()) // encode
  .pipe(through2(function (chunk, encoding, callback) {
    // Brutally chunk the stream into <= 3 byte chunks
    var len = chunk.length
    for (var i = 0; i < len; i += 3) {
      this.push(chunk.slice(i, i + 3))
    }
    callback()
  }))
  .pipe(mbstream.unpackStream()) // re-assemble into original buffers
  .pipe(through2(function (chunk, encoding, callback) {
    chunk[0] = chunk[0] - 32 // upper-case first character
    this.push(chunk)
    return callback()
  }))
  .pipe(process.stdout)

/*
MyDearAuntSally
 */

API

.packStream()

Create a stream.Transform instance that will convert buffers written to it into multibuffers

.unpackStream()

Create a stream.Transform instance that will re-assemble the original packed stream.

LICENSE

MIT

npm loves you