File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ module.exports = GridFSBucketWriteStream;
3333
3434function GridFSBucketWriteStream ( bucket , filename , options ) {
3535 options = options || { } ;
36+ stream . Writable . call ( this , options ) ;
3637 this . bucket = bucket ;
3738 this . chunks = bucket . s . _chunksCollection ;
3839 this . filename = filename ;
Original file line number Diff line number Diff line change @@ -99,6 +99,39 @@ describe('GridFS Stream', function() {
9999 }
100100 } ) ;
101101
102+ it ( 'destroy publishes provided error' , {
103+ metadata : { requires : { topology : [ 'single' ] } } ,
104+ test : function ( done ) {
105+ var configuration = this . configuration ;
106+ var GridFSBucket = configuration . require . GridFSBucket ;
107+
108+ var client = configuration . newClient ( configuration . writeConcernMax ( ) , { poolSize : 1 } ) ;
109+
110+ client . connect ( function ( err , client ) {
111+ var db = client . db ( configuration . db ) ;
112+ db . dropDatabase ( function ( error ) {
113+ test . equal ( error , null ) ;
114+
115+ var bucket = new GridFSBucket ( db ) ;
116+ var readStream = fs . createReadStream ( './LICENSE.md' ) ;
117+ var uploadStream = bucket . openUploadStream ( 'test.dat' ) ;
118+ var errorMessage = 'error' ;
119+
120+ uploadStream . once ( 'error' , function ( e ) {
121+ test . equal ( e , errorMessage ) ;
122+ client . close ( done ) ;
123+ } ) ;
124+
125+ uploadStream . once ( 'finish' , function ( ) {
126+ uploadStream . destroy ( errorMessage ) ;
127+ } ) ;
128+
129+ readStream . pipe ( uploadStream ) ;
130+ } ) ;
131+ } ) ;
132+ }
133+ } ) ;
134+
102135 /**
103136 * Correctly stream a file from disk into GridFS using openUploadStream
104137 *
You can’t perform that action at this time.
0 commit comments