0.3.4 • Published 8 years ago

pull-buffered v0.3.4

Weekly downloads
7
License
ISC
Repository
-
Last release
8 years ago

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

0.3.4

8 years ago

0.3.3

8 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago