Socket
Socket
Sign inDemoInstall

pull-buffered

Package Overview
Dependencies
2
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pull-buffered

read buffered data from a pull-stream


Version published
Weekly downloads
4
increased by100%
Maintainers
1
Install size
15.0 kB
Created
Weekly downloads
 

Readme

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

FAQs

Last updated on 09 Jun 2017

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc