Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

continue-stream

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

continue-stream

Lazily merge multiple streams in to a single stream

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

continue-stream

Lazily merge multiple streams in to a single stream. continueStream can also be thought of as a pagination stream.

npm install continue-stream

build status

Usage

Pass continueStream a function that provides a new stream to it's callback. This function will be called on initialization and after each stream has ended. If the callback is called without any arguments the continueStream will end.

var continueStream = require('continue-stream')
var request = require('request')

var page = 1

function next(callback, previousStream) {
  if (page >= 4) return callback()

  var stream = request({
    url: 'https://api.github.com/repos/joyent/node/events?page=' + (page++),
    headers: {'user-agent': 'pug'}
  })

  callback(null, stream)
}

continueStream(next)
  .pipe(process.stdout)

Or you can use continueStream.obj as a convenience for objectMode

var continueStream = require('continue-stream')
var request = require('request')
var pumpify = require('pumpify')
var JSONStream = require('JSONStream')

var page = 1

function next(callback, previousStream) {
  if (page >= 4) return callback()

  var req = request({
    url: 'https://api.github.com/repos/joyent/node/events?page=' + (page++),
    headers: {'user-agent': 'pug'}
  })

  var stream = pumpify.obj(req, JSONStream.parse('*'))

  callback(null, stream)
}

continueStream.obj(next)
  .on('data', function(data) {
    console.log(data)
  })

A good use case for this is paginated requests. Need to read the last n pages of a feed and want all items piped through a single stream? That is exactly what the last example is showing.

License

MIT

Keywords

FAQs

Package last updated on 24 May 2018

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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc