Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NODE-2355: Allow GridFS write stream to destroy #2702

Merged
merged 1 commit into from Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/gridfs-stream/upload.js
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
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