-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.2.10
-
Component/s: MongoDB 3.2
-
Environment:Node.js 4
-
Empty show more show less
Let's say I have a StaticBuffer which it's size is 2X bytes where the default chunkSizeBytes is X.
this is my starting code:
var bucket = new mongodb.GridFSBucket(db); var writer = bucket.openUploadStreamWithId(fileId, null, {contentType: ContentType}); writer.on('finish', function () { return true; }).on('error', function (Error) { return Error; }); writer.end(StaticBuffer);
When doing this, the app will crash because it is trying to close the stream twice.
But also when trying to write and then end like this:
writer.write(StaticBuffer, null, function () { writer.end(null) });
the problem will persist because the end will be called before all chunks are done flushing to the db.
The only way to workaround this, is to define the chunkSizeBytes to be bigger than the StaticBuffer and using only the end function in the following way:
var bucket = new mongodb.GridFSBucket(db); var writer = bucket.openUploadStreamWithId(fileId, null, {chunkSizeBytes: StaticBuffer.length + 1, contentType: ContentType}); writer.on('finish', function () { return true; }).on('error', function (Error) { return Error; }); writer.end(StaticBuffer);
But I want my buffer to be saved in multiple chunks which doesn't seems possible.