kill-stream

1.0.0 • Public • Published

kill-stream

Close a stream when test function returns truthy value

build status

Example

var killStream = require('kill-stream')
var JSONStream = require('JSONStream')
var request = require('request')
 
var twoHoursAgo = (new Date(Date.now() - 3600000))
  .toISOString()
  .replace(/\.\d+Z$/, 'Z')
 
function test(obj) {
  return obj.created_at < twoHoursAgo
}
 
var options = {
  url: 'https://api.github.com/repos/joyent/node/events',
  headers: {'user-agent': 'pug'}
}
 
request(options)
  .pipe(JSONStream.parse('*'))
  .pipe(killStream.obj(test))
  .on('data', function(data) {
    console.log(data.created_at)
  })

killStream(test=fn, includeKill=Boolean)

Closes stream when test returns truthy value. Pass truthy includeKill value if you want the last chunk to be included in output.

killStream.obj(test=fn, includeKill=Boolean)

Object

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i kill-stream

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • timhudson