🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

pull-buffered

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pull-buffered

read buffered data from a pull-stream

0.3.4
latest
npm
Version published
Maintainers
1
Created
Source

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

Keywords

pull-stream

FAQs

Package last updated on 09 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts