Skip to content

Instantly share code, notes, and snippets.

@Raynos
Forked from sergioramos/cursorapi.js
Last active December 11, 2015 09:48
Show Gist options
  • Select an option

  • Save Raynos/4582216 to your computer and use it in GitHub Desktop.

Select an option

Save Raynos/4582216 to your computer and use it in GitHub Desktop.
var WriteStream = require("write-stream")
var toArray = require("write-stream/array")
/************************************** A *************************************/
db.readStream().pipe(WriteStream(function write(data) {
assert.equal(data, {
value: 'value',
key: 'key'
})
}, function end() {
// fini
})).on("error", function (err) {
// error?
})
db.readStream().pipe(toArray(function finish(data) {
assert.equal(data, [{
value: 'value',
key: 'key'
}, {
value: 'value2',
key: 'key2'
}])
})).on("error", function (err) {
// error?
})
@sergioramos
Copy link
Copy Markdown

Thanks for the tip. I'm still not very confortable with streams and I wasn't aware of the write-stream module.

How about the error handling? with cursor, when a error occurs, it is passed to the end function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment