Skip to content

Commit

Permalink
Minor fixes to the pull request for gridstore to make all tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
christkv committed Sep 10, 2012
1 parent bb063bb commit 087fdd8
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 86 deletions.
7 changes: 4 additions & 3 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
1.1.7
----------------
- protect against starting PingStrategy being called more than once (Issue #694, https://github.com/aheckmann)
- make PingStrategy interval configurable (was 1 second, relaxed to 5) (Issue #693, https://github.com/aheckmann)
- made PingStrategy api more consistant, callback to start/stop methods are optional (Issue #693, https://github.com/aheckmann)
- Protect against starting PingStrategy being called more than once (Issue #694, https://github.com/aheckmann)
- Make PingStrategy interval configurable (was 1 second, relaxed to 5) (Issue #693, https://github.com/aheckmann)
- Made PingStrategy api more consistant, callback to start/stop methods are optional (Issue #693, https://github.com/aheckmann)
- Proper stopping of strategy on replicaset stop
- Throw error when gridstore file is not found in read mode (Issue #702, https://github.com/jbrumwell)

1.1.6 2012-09-01
----------------
Expand Down
20 changes: 11 additions & 9 deletions lib/mongodb/gridfs/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ var GridStore = require('./gridstore').GridStore,
function Grid(db, fsName) {

if(!(this instanceof Grid)) return new Grid(db, fsName);

this.db = db;
this.fsName = fsName == null ? GridStore.DEFAULT_ROOT_COLLECTION : fsName;
}
}

/**
* Puts binary data to the grid
Expand All @@ -33,9 +33,9 @@ Grid.prototype.put = function(data, options, callback) {
options = args.length ? args.shift() : {};
// If root is not defined add our default one
options['root'] = options['root'] == null ? this.fsName : options['root'];

// Return if we don't have a buffer object as data
if(!(Buffer.isBuffer(data))) return callback(new Error("Data object must be a buffer object"), null);
if(!(Buffer.isBuffer(data))) return callback(new Error("Data object must be a buffer object"), null);
// Get filename if we are using it
var filename = options['filename'];
// Create gridstore
Expand All @@ -50,7 +50,7 @@ Grid.prototype.put = function(data, options, callback) {
if(err) return callback(err, null);
callback(null, result);
})
})
})
})
}

Expand All @@ -64,16 +64,18 @@ Grid.prototype.put = function(data, options, callback) {
*/
Grid.prototype.get = function(id, callback) {
// Validate that we have a valid ObjectId
if(!(id instanceof ObjectID)) return callback(new Error("Not a valid ObjectID", null));
if(!(id instanceof ObjectID)) return callback(new Error("Not a valid ObjectID", null));
// Create gridstore
var gridStore = new GridStore(this.db, id, "r", {root:this.fsName});
gridStore.open(function(err, gridStore) {
console.log("==================================== hello")

if(err) return callback(err, null);

// Return the data
gridStore.read(function(err, data) {
return callback(err, data)
});
});
})
}

Expand All @@ -87,7 +89,7 @@ Grid.prototype.get = function(id, callback) {
*/
Grid.prototype.delete = function(id, callback) {
// Validate that we have a valid ObjectId
if(!(id instanceof ObjectID)) return callback(new Error("Not a valid ObjectID", null));
if(!(id instanceof ObjectID)) return callback(new Error("Not a valid ObjectID", null));
// Create gridstore
GridStore.unlink(this.db, id, {root:this.fsName}, function(err, result) {
if(err) return callback(err, false);
Expand Down
4 changes: 2 additions & 2 deletions lib/mongodb/gridfs/gridstore.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ var _open = function(self, callback) {
self.internalChunkSize = self.internalChunkSize == null ? Chunk.DEFAULT_CHUNK_SIZE : self.internalChunkSize;
self.length = 0;
} else {
self.length = 0;
return error(new Error((self.referenceBy == REFERENCE_BY_ID ? self.toHexString() : self.filename) + " does not exist", self));
self.length = 0;
return error(new Error((self.referenceBy == REFERENCE_BY_ID ? self.fileId.toHexString() : self.filename) + " does not exist", self));
}

// Process the mode of the object
Expand Down
Loading

0 comments on commit 087fdd8

Please sign in to comment.