@@ -23,6 +23,7 @@ module.exports = GridFSBucketWriteStream;
23
23
* @param {number } [options.w=null] The write concern
24
24
* @param {number } [options.wtimeout=null] The write concern timeout
25
25
* @param {number } [options.j=null] The journal write concern
26
+ * @param {boolean } [options.disableMD5=false] If true, disables adding an md5 field to file data
26
27
* @fires GridFSBucketWriteStream#error
27
28
* @fires GridFSBucketWriteStream#finish
28
29
* @return {GridFSBucketWriteStream } a GridFSBucketWriteStream instance.
@@ -42,7 +43,7 @@ function GridFSBucketWriteStream(bucket, filename, options) {
42
43
this . chunkSizeBytes = this . options . chunkSizeBytes ;
43
44
this . bufToStore = new Buffer ( this . chunkSizeBytes ) ;
44
45
this . length = 0 ;
45
- this . md5 = crypto . createHash ( 'md5' ) ;
46
+ this . md5 = ! options . disableMD5 && crypto . createHash ( 'md5' ) ;
46
47
this . n = 0 ;
47
48
this . pos = 0 ;
48
49
this . state = {
@@ -264,7 +265,7 @@ function checkDone(_this, callback) {
264
265
_this . id ,
265
266
_this . length ,
266
267
_this . chunkSizeBytes ,
267
- _this . md5 . digest ( 'hex' ) ,
268
+ _this . md5 && _this . md5 . digest ( 'hex' ) ,
268
269
_this . filename ,
269
270
_this . options . contentType ,
270
271
_this . options . aliases ,
@@ -357,10 +358,13 @@ function createFilesDoc(_id, length, chunkSize, md5, filename, contentType, alia
357
358
length : length ,
358
359
chunkSize : chunkSize ,
359
360
uploadDate : new Date ( ) ,
360
- md5 : md5 ,
361
361
filename : filename
362
362
} ;
363
363
364
+ if ( md5 ) {
365
+ ret . md5 = md5 ;
366
+ }
367
+
364
368
if ( contentType ) {
365
369
ret . contentType = contentType ;
366
370
}
@@ -414,7 +418,9 @@ function doWrite(_this, chunk, encoding, callback) {
414
418
_this . pos += numToCopy ;
415
419
spaceRemaining -= numToCopy ;
416
420
if ( spaceRemaining === 0 ) {
417
- _this . md5 . update ( _this . bufToStore ) ;
421
+ if ( _this . md5 ) {
422
+ _this . md5 . update ( _this . bufToStore ) ;
423
+ }
418
424
var doc = createChunkDoc ( _this . id , _this . n , _this . bufToStore ) ;
419
425
++ _this . state . outstandingRequests ;
420
426
++ outstandingRequests ;
@@ -497,7 +503,9 @@ function writeRemnant(_this, callback) {
497
503
// to be.
498
504
var remnant = new Buffer ( _this . pos ) ;
499
505
_this . bufToStore . copy ( remnant , 0 , 0 , _this . pos ) ;
500
- _this . md5 . update ( remnant ) ;
506
+ if ( _this . md5 ) {
507
+ _this . md5 . update ( remnant ) ;
508
+ }
501
509
var doc = createChunkDoc ( _this . id , _this . n , remnant ) ;
502
510
503
511
// If the stream was aborted, do not write remnant
0 commit comments