1
- import * as crypto from 'crypto' ;
2
1
import { Writable } from 'stream' ;
3
2
import { MongoError , AnyError , MONGODB_ERROR_CODES , MongoDriverError } from '../error' ;
4
3
import { WriteConcern } from './../write_concern' ;
@@ -31,8 +30,6 @@ export interface GridFSBucketWriteStreamOptions extends WriteConcernOptions {
31
30
contentType ?: string ;
32
31
/** Array of strings to store in the file document's `aliases` field */
33
32
aliases ?: string [ ] ;
34
- /** If true, disables adding an md5 field to file data */
35
- disableMD5 ?: boolean ;
36
33
}
37
34
38
35
/**
@@ -52,7 +49,6 @@ export class GridFSBucketWriteStream extends Writable {
52
49
chunkSizeBytes : number ;
53
50
bufToStore : Buffer ;
54
51
length : number ;
55
- md5 : false | crypto . Hash ;
56
52
n : number ;
57
53
pos : number ;
58
54
state : {
@@ -96,7 +92,6 @@ export class GridFSBucketWriteStream extends Writable {
96
92
this . chunkSizeBytes = options . chunkSizeBytes || this . bucket . s . options . chunkSizeBytes ;
97
93
this . bufToStore = Buffer . alloc ( this . chunkSizeBytes ) ;
98
94
this . length = 0 ;
99
- this . md5 = ! options . disableMD5 && crypto . createHash ( 'md5' ) ;
100
95
this . n = 0 ;
101
96
this . pos = 0 ;
102
97
this . state = {
@@ -307,7 +302,6 @@ function checkDone(stream: GridFSBucketWriteStream, callback?: Callback): boolea
307
302
stream . id ,
308
303
stream . length ,
309
304
stream . chunkSizeBytes ,
310
- stream . md5 ? stream . md5 . digest ( 'hex' ) : undefined ,
311
305
stream . filename ,
312
306
stream . options . contentType ,
313
307
stream . options . aliases ,
@@ -396,14 +390,13 @@ function checkIndexes(stream: GridFSBucketWriteStream, callback: Callback): void
396
390
}
397
391
398
392
function 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
407
400
) : GridFSFile {
408
401
const ret : GridFSFile = {
409
402
_id,
@@ -413,10 +406,6 @@ function createFilesDoc(
413
406
filename
414
407
} ;
415
408
416
- if ( md5 ) {
417
- ret . md5 = md5 ;
418
- }
419
-
420
409
if ( contentType ) {
421
410
ret . contentType = contentType ;
422
411
}
@@ -472,9 +461,6 @@ function doWrite(
472
461
spaceRemaining -= numToCopy ;
473
462
let doc : GridFSChunk ;
474
463
if ( spaceRemaining === 0 ) {
475
- if ( stream . md5 ) {
476
- stream . md5 . update ( stream . bufToStore ) ;
477
- }
478
464
doc = createChunkDoc ( stream . id , stream . n , Buffer . from ( stream . bufToStore ) ) ;
479
465
++ stream . state . outstandingRequests ;
480
466
++ outstandingRequests ;
@@ -550,9 +536,6 @@ function writeRemnant(stream: GridFSBucketWriteStream, callback?: Callback): boo
550
536
// to be.
551
537
const remnant = Buffer . alloc ( stream . pos ) ;
552
538
stream . bufToStore . copy ( remnant , 0 , 0 , stream . pos ) ;
553
- if ( stream . md5 ) {
554
- stream . md5 . update ( remnant ) ;
555
- }
556
539
const doc = createChunkDoc ( stream . id , stream . n , remnant ) ;
557
540
558
541
// If the stream was aborted, do not write remnant
0 commit comments