@@ -23,6 +23,7 @@ module.exports = GridFSBucketWriteStream;
2323 * @param {number } [options.w=null] The write concern
2424 * @param {number } [options.wtimeout=null] The write concern timeout
2525 * @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
2627 * @fires GridFSBucketWriteStream#error
2728 * @fires GridFSBucketWriteStream#finish
2829 * @return {GridFSBucketWriteStream } a GridFSBucketWriteStream instance.
@@ -42,7 +43,7 @@ function GridFSBucketWriteStream(bucket, filename, options) {
4243 this . chunkSizeBytes = this . options . chunkSizeBytes ;
4344 this . bufToStore = new Buffer ( this . chunkSizeBytes ) ;
4445 this . length = 0 ;
45- this . md5 = crypto . createHash ( 'md5' ) ;
46+ this . md5 = ! options . disableMD5 && crypto . createHash ( 'md5' ) ;
4647 this . n = 0 ;
4748 this . pos = 0 ;
4849 this . state = {
@@ -264,7 +265,7 @@ function checkDone(_this, callback) {
264265 _this . id ,
265266 _this . length ,
266267 _this . chunkSizeBytes ,
267- _this . md5 . digest ( 'hex' ) ,
268+ _this . md5 && _this . md5 . digest ( 'hex' ) ,
268269 _this . filename ,
269270 _this . options . contentType ,
270271 _this . options . aliases ,
@@ -357,10 +358,13 @@ function createFilesDoc(_id, length, chunkSize, md5, filename, contentType, alia
357358 length : length ,
358359 chunkSize : chunkSize ,
359360 uploadDate : new Date ( ) ,
360- md5 : md5 ,
361361 filename : filename
362362 } ;
363363
364+ if ( md5 ) {
365+ ret . md5 = md5 ;
366+ }
367+
364368 if ( contentType ) {
365369 ret . contentType = contentType ;
366370 }
@@ -414,7 +418,9 @@ function doWrite(_this, chunk, encoding, callback) {
414418 _this . pos += numToCopy ;
415419 spaceRemaining -= numToCopy ;
416420 if ( spaceRemaining === 0 ) {
417- _this . md5 . update ( _this . bufToStore ) ;
421+ if ( _this . md5 ) {
422+ _this . md5 . update ( _this . bufToStore ) ;
423+ }
418424 var doc = createChunkDoc ( _this . id , _this . n , _this . bufToStore ) ;
419425 ++ _this . state . outstandingRequests ;
420426 ++ outstandingRequests ;
@@ -497,7 +503,9 @@ function writeRemnant(_this, callback) {
497503 // to be.
498504 var remnant = new Buffer ( _this . pos ) ;
499505 _this . bufToStore . copy ( remnant , 0 , 0 , _this . pos ) ;
500- _this . md5 . update ( remnant ) ;
506+ if ( _this . md5 ) {
507+ _this . md5 . update ( remnant ) ;
508+ }
501509 var doc = createChunkDoc ( _this . id , _this . n , remnant ) ;
502510
503511 // If the stream was aborted, do not write remnant
0 commit comments