SEXP mongo_gridfile_get_chunk(SEXP gfile, SEXP i) { gridfile* _gfile = _checkGridfile(gfile); int _i = asInteger(i); bson chunk = gridfile_get_chunk(_gfile, _i); if (bson_size(&chunk) <= 5) return R_NilValue; SEXP ret = _mongo_bson_create(&chunk); UNPROTECT(3); return ret; }
int mongo_gridfile_get_chunk(struct gridfile_* gf, int i, struct bson_** out) { bson chunk, *b; gridfile_get_chunk((gridfile*)gf, i, &chunk); if (bson_size(&chunk) <= 5) return 0; b = (bson*)malloc(sizeof(bson)); *b = chunk; *out = (struct bson_*)b; return 1; }
gridfs_offset gridfile_write_file( gridfile *gfile, FILE *stream ) { int i; size_t len; bson chunk; bson_iterator it; const char *data; const int num = gridfile_get_numchunks( gfile ); for ( i=0; i<num; i++ ) { chunk = gridfile_get_chunk( gfile, i ); bson_find( &it, &chunk, "data" ); len = bson_iterator_bin_len( &it ); data = bson_iterator_bin_data( &it ); fwrite( data , sizeof( char ), len, stream ); bson_destroy( &chunk ); } return gridfile_get_contentlength( gfile ); }
gridfs_offset gridfile_write_buffer(gridfile* gfile, char * buf) { int i; gridfs_offset len; bson chunk; bson_iterator it; const char* data; const int num = gridfile_get_numchunks( gfile ); for ( i = 0; i < num; i++ ){ chunk = gridfile_get_chunk( gfile, i ); bson_find( &it, &chunk, "data" ); len = bson_iterator_bin_len( &it ); data = bson_iterator_bin_data( &it ); memcpy( buf, data, len); buf += len; } return gridfile_get_contentlength(gfile); }