1- import * as crypto from 'crypto' ;
21import { Writable } from 'stream' ;
32import { MongoError , AnyError , MONGODB_ERROR_CODES , MongoDriverError } from '../error' ;
43import { WriteConcern } from './../write_concern' ;
@@ -31,8 +30,6 @@ export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions {
3130 contentType ?: string ;
3231 /** Array of strings to store in the file document's `aliases` field */
3332 aliases ?: string [ ] ;
34- /** If true, disables adding an md5 field to file data */
35- disableMD5 ?: boolean ;
3633}
3734
3835/**
@@ -52,7 +49,6 @@ export class GridFSBucketWriteStream extends Writable {
5249 chunkSizeBytes : number ;
5350 bufToStore : Buffer ;
5451 length : number ;
55- md5 : false | crypto . Hash ;
5652 n : number ;
5753 pos : number ;
5854 state : {
@@ -96,7 +92,6 @@ export class GridFSBucketWriteStream extends Writable {
9692 this . chunkSizeBytes = options . chunkSizeBytes || this . bucket . s . options . chunkSizeBytes ;
9793 this . bufToStore = Buffer . alloc ( this . chunkSizeBytes ) ;
9894 this . length = 0 ;
99- this . md5 = ! options . disableMD5 && crypto . createHash ( 'md5' ) ;
10095 this . n = 0 ;
10196 this . pos = 0 ;
10297 this . state = {
@@ -307,7 +302,6 @@ function checkDone(stream: GridFSBucketWriteStream, callback?: Callback): boolea
307302 stream . id ,
308303 stream . length ,
309304 stream . chunkSizeBytes ,
310- stream . md5 ? stream . md5 . digest ( 'hex' ) : undefined ,
311305 stream . filename ,
312306 stream . options . contentType ,
313307 stream . options . aliases ,
@@ -396,14 +390,13 @@ function checkIndexes(stream: GridFSBucketWriteStream, callback: Callback): void
396390}
397391
398392function createFilesDoc (
399- _id : GridFSFile [ '_id' ] ,
400- length : GridFSFile [ 'length' ] ,
401- chunkSize : GridFSFile [ 'chunkSize' ] ,
402- md5 : GridFSFile [ 'md5' ] ,
403- filename : GridFSFile [ 'filename' ] ,
404- contentType : GridFSFile [ 'contentType' ] ,
405- aliases : GridFSFile [ 'aliases' ] ,
406- metadata : GridFSFile [ 'metadata' ]
393+ _id : ObjectId ,
394+ length : number ,
395+ chunkSize : number ,
396+ filename : string ,
397+ contentType ?: string ,
398+ aliases ?: string [ ] ,
399+ metadata ?: Document
407400) : GridFSFile {
408401 const ret : GridFSFile = {
409402 _id,
@@ -413,10 +406,6 @@ function createFilesDoc(
413406 filename
414407 } ;
415408
416- if ( md5 ) {
417- ret . md5 = md5 ;
418- }
419-
420409 if ( contentType ) {
421410 ret . contentType = contentType ;
422411 }
@@ -472,9 +461,6 @@ function doWrite(
472461 spaceRemaining -= numToCopy ;
473462 let doc : GridFSChunk ;
474463 if ( spaceRemaining === 0 ) {
475- if ( stream . md5 ) {
476- stream . md5 . update ( stream . bufToStore ) ;
477- }
478464 doc = createChunkDoc ( stream . id , stream . n , Buffer . from ( stream . bufToStore ) ) ;
479465 ++ stream . state . outstandingRequests ;
480466 ++ outstandingRequests ;
@@ -550,9 +536,6 @@ function writeRemnant(stream: GridFSBucketWriteStream, callback?: Callback): boo
550536 // to be.
551537 const remnant = Buffer . alloc ( stream . pos ) ;
552538 stream . bufToStore . copy ( remnant , 0 , 0 , stream . pos ) ;
553- if ( stream . md5 ) {
554- stream . md5 . update ( remnant ) ;
555- }
556539 const doc = createChunkDoc ( stream . id , stream . n , remnant ) ;
557540
558541 // If the stream was aborted, do not write remnant
0 commit comments