
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
continue-stream
Advanced tools
Lazily merge multiple streams in to a single stream. continueStream
can also
be thought of as a pagination stream.
npm install continue-stream
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.
MIT
FAQs
Lazily merge multiple streams in to a single stream
The npm package continue-stream receives a total of 12 weekly downloads. As such, continue-stream popularity was classified as not popular.
We found that continue-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.