Skip to content
This repository

gridfs-stream should be able to store 12 lettered file names #14

Merged
merged 1 commit into from about 1 year ago

2 participants

Tim de Koning Aaron Heckmann
Tim de Koning
Collaborator

Issue #11

Tim de Koning Reggino merged commit 1a6191b into from April 05, 2013
Tim de Koning Reggino closed this April 05, 2013
Aaron Heckmann
Owner

:+1:

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

Showing 1 unique commit by 1 author.

Apr 05, 2013
Tim de Koning Gridfs should be able to store 12 lettered file names
Issue #11
611cc1d
This page is out of date. Refresh to see the latest.
11  lib/index.js
@@ -31,15 +31,18 @@ function Grid (db, mongo) {
31 31
 }
32 32
 
33 33
 /**
34  
- * Creates a writable stream ior the given `filename`.
  34
+ * Creates a writable stream for the given `filename`.
35 35
  *
36  
- * @param {ObjectId|String} filename
  36
+ * __NOTE__ It is advised to pass a filename using the option 'filename', since some filenames can not be distinguished
  37
+ * from ObjectIds
  38
+ *
  39
+ * @param {ObjectId|String} objectId (optional)
37 40
  * @param {Object} [options]
38 41
  * @return Stream
39 42
  */
40 43
 
41  
-Grid.prototype.createWriteStream = function (filename, options) {
42  
-  return new GridWriteStream(this, filename, options);
  44
+Grid.prototype.createWriteStream = function (objectId, options) {
  45
+  return new GridWriteStream(this, objectId, options);
43 46
 }
44 47
 
45 48
 /**
11  lib/writestream.js
@@ -30,7 +30,9 @@ function GridWriteStream (grid, filename, options) {
30 30
   this._opening = false;
31 31
 
32 32
   this._grid = grid;
33  
-  this.name = '';
  33
+  this.options = filename && 'Object' == filename.constructor.name
  34
+      ? filename
  35
+      : options || {};
34 36
 
35 37
   if (filename && filename.toHexString) {
36 38
     this.id = filename;
@@ -41,14 +43,11 @@ function GridWriteStream (grid, filename, options) {
41 43
     if ('string' == typeof filename) {
42 44
       // filenames are not unique
43 45
       // http://mongodb.github.com/node-mongodb-native/api-generated/gridstore.html
44  
-      this.name = filename;
  46
+      this.options.filename = filename;
45 47
     }
46 48
   }
47 49
 
48  
-  this.options = filename && 'Object' == filename.constructor.name
49  
-    ? filename
50  
-    : options || {};
51  
-
  50
+  this.name = this.options.filename || '';
52 51
   this.options.limit || (this.options.limit = Infinity);
53 52
 
54 53
   this.mode = this.options.mode && /^w[+]?$/.test(this.options.mode)
10  test/index.js
@@ -104,8 +104,8 @@ describe('test', function(){
104 104
       assert(ws.name == 'logo.png')
105 105
     })
106 106
     describe('options', function(){
107  
-      it('should have one key', function(){
108  
-        assert(Object.keys(ws.options).length === 1);
  107
+      it('should have two keys', function(){
  108
+        assert(Object.keys(ws.options).length === 2);
109 109
       });
110 110
       it('limit should be Infinity', function(){
111 111
         assert(ws.options.limit === Infinity)
@@ -189,7 +189,6 @@ describe('test', function(){
189 189
       var pipe = readStream.pipe(ws);
190 190
     });
191 191
 
192  
-
193 192
     it('should pipe more data to an existing GridFS file', function(done){
194 193
       function pipe (id, cb) {
195 194
         if (!cb) cb = id, id = null;
@@ -212,6 +211,11 @@ describe('test', function(){
212 211
         });
213 212
       })
214 213
     });
  214
+
  215
+    it('should be able to store a 12-letter file name', function() {
  216
+      var rs = g.createWriteStream({ filename: '12345678.png' });
  217
+      assert.equal(rs.name,'12345678.png');
  218
+    });
215 219
   });
216 220
 
217 221
   describe('createReadStream', function(){
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.