|
It will be nice to had the posibility of writing new GridFS files as a stream.
I have an implementation ready in my fork, using a new class GridFileBuilder which allow to perform several data appends which are enqueued in an auxiliary buffer until a chunk of data is full an ready to be send to MongoDB. I will like to make pull request. Sugestions and comments are wellcome. My commit is here:
https://github.com/pakozm/mongo-cxx-driver/commit/29c563efe5cbf2441061cc23e0be4a972e3d5455
The basic API of the new class will be:
- GridFileBuilder(GridFS *grid) => the constructor takes the GridFS pointer and annotates the chunkSize which couldn't be changed. The GridFileBuilder will need to access GridFS pointer as a friend, because it needs to access to chunkNS and _client properties.
- void appendChunk(const char *data, size_t length) => appends the given string of data, which would splitted in several chunks or annotated in the auxiliary buffer. Auxiliary buffer data will be stored at GridFS when it arrives to chunkSize length.
- BSONObj buildFile(string name, string contentType) => inserts the new file in GridFS using the method insertFile. If the auxiliary buffer contains data, it will be stored before to call insertFile.
I simple use case is when you need to write a large amount of generated data (not stored in your filesystem disk), and you don't want to store it in temporary disk files.
|