A streaming interface for multibuffer.
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"pipembstreampackStream // encodepipethrough2// Brutally chunk the stream into <= 3 byte chunksvar len = chunklengthfor var i = 0; i < len; i += 3thispushchunkslicei i + 3callbackpipembstreamunpackStream // re-assemble into original bufferspipethrough2chunk0 = chunk0 - 32 // upper-case first characterthispushchunkreturn callbackpipeprocessstdout/*MyDearAuntSally*/// Convert a stream into a multibuffer stream with `wrap`// **NOTE** You **MUST** know the full length of the stream first!var fs = require"fs"var file = "./README.md"var size = fsstatSyncfilesizefscreateReadStreamfilepipembstreamwrapsize // convert to multibuffer-streampipembstreamunpackStream // convert back to regular stream
stream.Transform instance that will convert buffers written to it into multibuffers
stream.Transform instance that will re-assemble the original packed stream.
Transform stream that will wrap a known length stream as a multibuffer (i.e. prefix the first chunk with the length).
This means it is not suitable for never-ending streams.