Skip to content

Instantly share code, notes, and snippets.

@aj0strow
Created December 28, 2014 23:30
Show Gist options
  • Save aj0strow/9271dcb3d54f43008e2d to your computer and use it in GitHub Desktop.
Save aj0strow/9271dcb3d54f43008e2d to your computer and use it in GitHub Desktop.
firebase child readable stream
var PassThrough = require('stream').PassThrough
function createChildStream(ref) {
var stream = new PassThrough({ objectMode: true })
ref.limitToLast(1).once('child_added', function(snap) {
var stopKey = snap.key()
ref.on('child_added', function(snap) {
stream.push(snap.val())
if (snap.key() == stopKey) {
ref.off('child_added')
stream.end()
}
})
})
return stream
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment