Skip to content

Commit

Permalink
cursor is a 0.10 and 0.8 compat readable stream
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh committed Mar 1, 2013
1 parent bf89980 commit e20e689
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var mongodb = require('mongodb');
var memolite = require('memolite');
var Readable = require('stream').Readable || require('readable-stream');

var DRIVER_COLLECTION_PROTO = mongodb.Collection.prototype;
var DRIVER_CURSOR_PROTO = mongodb.Cursor.prototype;
Expand All @@ -24,9 +25,12 @@ var getCallback = function(args) {
// arguments to fit the mongo shell.

var Cursor = function(oncursor) {
Readable.call(this, {objectMode:true});
this._get = oncursor;
};

Cursor.prototype.__proto__ = Readable.prototype;

Cursor.prototype.toArray = function() {
this._apply(DRIVER_CURSOR_PROTO.toArray, arguments);
};
Expand Down Expand Up @@ -68,6 +72,10 @@ Cursor.prototype._apply = function(fn, args) {
return this;
};

Cursor.prototype._read = function(size, callback) { // 0.10 stream support
this.next(callback);
};

Cursor.prototype._config = function(fn, args) {
if (typeof args[args.length-1] !== 'function') return this._apply(fn, args);

Expand Down
39 changes: 22 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
{
"name":"mongojs",
"description":"a simple mongo module that implements the mongo api",
"keywords": ["mongo", "db", "mongodb"],
"version":"0.6.4",
"repository": "git://github.com/gett/mongojs.git",
"author": "Ge.tt <hello@ge.tt>",
"contributors": [
"Mathias Buus Madsen <m@ge.tt>",
"Ian Jorgensen <i@ge.tt>"
],
"dependencies": {
"mongodb":"1.2.x",
"memolite":"~0.1.0"
},
"scripts": {
"test":"node ./tests"
}
"name": "mongojs",
"description": "a simple mongo module that implements the mongo api",
"keywords": [
"mongo",
"db",
"mongodb"
],
"version": "0.6.4",
"repository": "git://github.com/gett/mongojs.git",
"author": "Ge.tt <hello@ge.tt>",
"contributors": [
"Mathias Buus Madsen <m@ge.tt>",
"Ian Jorgensen <i@ge.tt>"
],
"dependencies": {
"mongodb": "~1.2.13",
"memolite": "~0.1.0",
"readable-stream": "~0.3.1"
},
"scripts": {
"test": "node ./tests"
}
}

0 comments on commit e20e689

Please sign in to comment.