Permalink
Browse files

Bump to 0.0.9

Fixes #2.
  • Loading branch information...
1 parent f50fe97 commit 2ac4dd40e9e300a0ea8edfad16a8661eb7ef7eff Siddharth Mahendraker committed Nov 6, 2011
Showing with 46 additions and 47 deletions.
  1. +2 −0 .gitignore
  2. +1 −0 TODO.md
  3. +28 −31 lib/GridFS.js
  4. +14 −15 lib/GridStream.js
  5. +1 −1 package.json
View
2 .gitignore
@@ -1 +1,3 @@
.DS_Store
+/node_modules
+
View
1 TODO.md
@@ -1,2 +1,3 @@
# TODO
+
View
59 lib/GridFS.js
@@ -53,7 +53,7 @@ function GridFS(dbname,filesys){
if(self.opQueue.length > 0) self.performOp();
});
- if(!(this.dbcon)) throw new Error('Database creation failed.');
+ if(!(this.dbcon)) throw new Error('Database connection failed.');
this.open();
};
@@ -122,7 +122,7 @@ GridFS.prototype.put = function(buffer, filename, mode, options, callback){
* @param {Function} callback
*
* The callback function takes an error and data as parameters. The data object is
- * a string.
+ * a buffer.
*
* @see put() for option details.
*
@@ -289,11 +289,25 @@ GridFS.prototype._get = function(filename, length, offset, options, callback){
}
if(exists === true){
- GridStore.read(db, filename, length, offset, options, function(err, data){
- self.emitter.emit('_op');
- var sendData = new Buffer(data);
- callback(err, sendData);
- });
+ new GridStore(db, filename, "r", options).open(function(err, gs){
+ if(offset != null){
+ gs.seek(offset, function(err, gridS){
+ if(err){
+ self.emitter.emit('_op');
+ return callback(err, null);
+ }
+ gridS.readBuffer(length, function(err, data){
+ callback(err, data);
+ self.emitter.emit('_op');
+ });
+ });
+ }else{
+ gs.readBuffer(length, function(err, data){
+ callback(err, data);
+ self.emitter.emit('_op');
+ });
+ }
+ });
}
else{
callback(new Error('The file you wish to read does not exist.'),null);
@@ -313,31 +327,14 @@ GridFS.prototype._get = function(filename, length, offset, options, callback){
GridFS.prototype._delete = function(filename, callback){
var db = this.dbcon;
+ var fs = this.fs;
+
var self = this;
-
- GridStore.exist(db, filename, function(err,exists){
- if(err){
- self.emitter.emit('_op');
- if(callback)
- callback(err);
- else
- throw err;
- }
-
- if(exists){
- GridStore.unlink(db,filename,function(){
- self.emitter.emit('_op');
- if(callback) callback(null);
- });
- }
- else{
- self.emitter.emit('_op');
- err = new Error('The file you wish to delete does not exist.');
- if(callback)
- callback(err);
- else
- throw err;
- }
+
+ GridStore.unlink(db, filename, function(err, gs){
+ if(callback) callback(err);
+
+ self.emitter.emit('_op');
});
};
View
29 lib/GridStream.js
@@ -190,21 +190,20 @@ GridReadStream.prototype._read = function(){
else
len = this.options.chunk_size;
- GridStore.read(self.db, self.filename, len, self.head, { 'root' : self.options.root }, function(err, data){
- var emitData = new Buffer(data);
-
- if(self.encoding !== null)
- emitData = emitData.toString(self.encoding);
-
- self.emit('data', emitData);
-
- self.head += len;
- if(self.head !== self.gridStore.length)
- self._read();
- else{
- self.emit('end');
- self.destroy();
- }
+ this.gridStore.seek(self.head, function(err, gridStore){
+ gridStore.readBuffer(len, function(err, data){
+ if(self.encoding !== null)
+ data = data.toString(self.encoding);
+
+ self.emit('data',data);
+ self.head += len;
+ if(self.head !== self.gridStore.length)
+ self._read();
+ else{
+ self.emit('end');
+ self.destroy();
+ }
+ });
});
}
}else{
View
2 package.json
@@ -2,7 +2,7 @@
"author": "Siddharth Mahendraker <siddharth_mahen@me.com>",
"name": "GridFS",
"description": "GridFS made easy.",
- "version": "0.0.8",
+ "version": "0.0.9",
"homepage": "https://github.com/siddMahen/GridFS",
"keywords": ["GridFS", "mongodb"],
"repository": {

0 comments on commit 2ac4dd4

Please sign in to comment.