buffer-split-transform
v1.0.1
Published
creates a transform stream that splits chunks without intermediate string conversion
Downloads
2
Maintainers
Readme
buffer-split-transform
Creates a transform stream that splits chunks without intermediate string conversion.
usage
import split from 'buffer-split-transform'
// source is a readable stream which emits:
// <Buffer 74 68 69 73 20 69 73 0a 69 74>
const sink = source.pipe(split())
sink.on(`data`, console.log)
// <Buffer 74 68 69 73 20 69 73>
// <Buffer 69 74>
api
split([delimiter], [options])
delimiter
if set overrides the default delimiter of Buffer.from('\n')
.
options
defualts to:
{ flushRemainingChunk: true }
If flushRemainingChunk
is set to false
, the remainder of a split chunk will be omitted when the source stream ends. This can be useful if you are only interested in data before the specified delimiter.
In cases where extra verbosity is desired, split can be called like so:
split({
delimiter: Buffer.from(`\n\n`),
flushRemainingChunk: false
})