Skip to content

Commit 594ef3b

Browse files
committed
NODE-2355: Allow GridFS write stream to destroy
1 parent 7e89e47 commit 594ef3b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/gridfs-stream/upload.js

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = GridFSBucketWriteStream;
3333

3434
function 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;

test/functional/gridfs_stream.test.js

+33
Original file line numberDiff line numberDiff 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
*

0 commit comments

Comments
 (0)