Skip to content

Commit

Permalink
fix: Allow GridFS write stream to destroy (#2702)
Browse files Browse the repository at this point in the history
  • Loading branch information
durran authored Jan 20, 2021
1 parent e257e6b commit b5e9d67
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/gridfs-stream/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions test/functional/gridfs_stream.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit b5e9d67

Please sign in to comment.