diff --git a/lib/gridfs-stream/upload.js b/lib/gridfs-stream/upload.js index c5e28f08ec..b1e6f90e21 100644 --- a/lib/gridfs-stream/upload.js +++ b/lib/gridfs-stream/upload.js @@ -33,6 +33,7 @@ module.exports = GridFSBucketWriteStream; function GridFSBucketWriteStream(bucket, filename, options) { options = options || {}; + stream.Writable.call(this, options); this.bucket = bucket; this.chunks = bucket.s._chunksCollection; this.filename = filename; diff --git a/test/functional/gridfs_stream.test.js b/test/functional/gridfs_stream.test.js index 258b1890cc..635d137955 100644 --- a/test/functional/gridfs_stream.test.js +++ b/test/functional/gridfs_stream.test.js @@ -99,6 +99,39 @@ describe('GridFS Stream', function() { } }); + it('destroy publishes provided error', { + metadata: { requires: { topology: ['single'] } }, + test: function(done) { + var configuration = this.configuration; + var GridFSBucket = configuration.require.GridFSBucket; + + var client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 }); + + client.connect(function(err, client) { + var db = client.db(configuration.db); + db.dropDatabase(function(error) { + test.equal(error, null); + + var bucket = new GridFSBucket(db); + var readStream = fs.createReadStream('./LICENSE.md'); + var uploadStream = bucket.openUploadStream('test.dat'); + var errorMessage = 'error'; + + uploadStream.once('error', function(e) { + test.equal(e, errorMessage); + client.close(done); + }); + + uploadStream.once('finish', function() { + uploadStream.destroy(errorMessage); + }); + + readStream.pipe(uploadStream); + }); + }); + } + }); + /** * Correctly stream a file from disk into GridFS using openUploadStream *