File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ module.exports = GridFSBucketWriteStream;
33
33
34
34
function GridFSBucketWriteStream ( bucket , filename , options ) {
35
35
options = options || { } ;
36
+ stream . Writable . call ( this , options ) ;
36
37
this . bucket = bucket ;
37
38
this . chunks = bucket . s . _chunksCollection ;
38
39
this . filename = filename ;
Original file line number Diff line number Diff line change @@ -99,6 +99,39 @@ describe('GridFS Stream', function() {
99
99
}
100
100
} ) ;
101
101
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
+
102
135
/**
103
136
* Correctly stream a file from disk into GridFS using openUploadStream
104
137
*
You can’t perform that action at this time.
0 commit comments