pull-buffered
v0.3.4 pull-stream
pull-buffered
Transform a pull-stream so that it can be read from in useful buffered ways.
var b = pullBuffered()
pull(
bufferOrStringSource,
b
)
Read line by line
pull(
b.lines,
pull.drain(function (line) {
console.log('got line', line)
})
)
Read chunks of fixed size
pull(
b.chunks(5),
pull.drain(function (chunk) {
console.log('got chunk of length 5', chunk)
})
)
Read as a stream of fixed size
pull(
b.take(10),
pull.collect(function (err, chunks) {
console.log('got the first 10 characters', chunks.join(''))
})
)
Mix and match
b.lines(null, function (end, line) {
console.log('got first line with length', line)
var len = parseInt(line, 10)
b.chunks(len)(end, function (end, buf) {
console.log('got chunk with length ' + len + ':', buf)
pull(
b, // Pass-through the rest
pull.collect(function (err, chunks) {
console.log('got the rest', chunks.join(''))
})
)
})
})
See also
License
ISC