[CXX-218] GridFS and GridFile incremental writing Created: 04/May/14  Updated: 13/Jun/14  Resolved: 11/Jun/14

Status: Closed
Project: C++ Driver
Component/s: Implementation
Affects Version/s: legacy-0.8.0
Fix Version/s: legacy-0.10.0

Type: New Feature Priority: Minor - P4
Reporter: Francisco Zamora-Martinez Assignee: Andrew Morrow (Inactive)
Resolution: Done Votes: 0
Labels: legacy-cxx
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Pulling into legacy-0.10.0 so that we get this committed sometime this iteration. We agree on the utility of the feature, and the code as is has gone through and passed code review, but there is one lingering issue over the lifecycle of the chunk inserter to be resolved that may require some refactoring.



 Comments   
Comment by Andrew Morrow (Inactive) [ 06/May/14 ]

https://github.com/mongodb/mongo-cxx-driver/pull/70

Comment by Francisco Zamora-Martinez [ 04/May/14 ]

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.

Generated at Wed Feb 07 21:58:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.