@@ -420,6 +420,41 @@ describe('GridFS Stream', function() {
420
420
}
421
421
} ) ;
422
422
423
+ it ( 'should emit close after all chunks are received' , {
424
+ metadata : { requires : { topology : [ 'single' ] } } ,
425
+
426
+ test : function ( done ) {
427
+ const configuration = this . configuration ;
428
+ const GridFSBucket = configuration . require . GridFSBucket ;
429
+
430
+ const client = configuration . newClient ( configuration . writeConcernMax ( ) , { poolSize : 1 } ) ;
431
+ client . connect ( ( err , client ) => {
432
+ expect ( err ) . to . not . exist ;
433
+ const db = client . db ( configuration . db ) ;
434
+ const bucket = new GridFSBucket ( db , {
435
+ bucketName : 'gridfsdownload' ,
436
+ chunkSizeBytes : 6000
437
+ } ) ;
438
+
439
+ const readStream = fs . createReadStream ( './LICENSE.md' ) ;
440
+ const uploadStream = bucket . openUploadStream ( 'teststart.dat' ) ;
441
+ uploadStream . once ( 'finish' , function ( ) {
442
+ const downloadStream = bucket . openDownloadStreamByName ( 'teststart.dat' ) ;
443
+
444
+ const events = [ ] ;
445
+ downloadStream . on ( 'data' , ( ) => events . push ( 'data' ) ) ;
446
+ downloadStream . on ( 'close' , ( ) => events . push ( 'close' ) ) ;
447
+ downloadStream . on ( 'end' , ( ) => {
448
+ expect ( events ) . to . eql ( [ 'data' , 'data' , 'close' ] ) ;
449
+ client . close ( done ) ;
450
+ } ) ;
451
+ } ) ;
452
+
453
+ readStream . pipe ( uploadStream ) ;
454
+ } ) ;
455
+ }
456
+ } ) ;
457
+
423
458
/**
424
459
* Deleting a file from GridFS
425
460
*
0 commit comments