pull-buffered

v0.3.4
read buffered data from a pull-stream
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

npm i pull-buffered

Metadata

  • ISC
  • Whatever
  • cel
  • released 6/9/2017

Downloads

Maintainers