Go to the documentation of this file.00001
00005
00006
00007
00008
00009
00010 #include "mongo.h"
00011 #include "bson.h"
00012 #include "platform_hacks.h"
00013 #include <stdio.h>
00014 #ifndef GRIDFS_INCLUDED
00015 #define GRIDFS_INCLUDED
00016
00017 enum {DEFAULT_CHUNK_SIZE = 256 * 1024};
00018
00019 typedef uint64_t gridfs_offset;
00020
00021
00022
00023 typedef struct {
00024
00025 mongo_connection* client;
00026
00027 const char* dbname;
00028
00029 const char* prefix;
00030
00031 const char* files_ns;
00032
00033 const char* chunks_ns;
00034
00035 } gridfs;
00036
00037
00038
00039
00040
00041
00042
00043 typedef struct {
00044
00045 gridfs* gfs;
00046
00047 bson* meta;
00048
00049 gridfs_offset pos;
00050
00051 bson_oid_t id;
00052
00053 const char* remote_name;
00054
00055 const char* content_type;
00056
00057 gridfs_offset length;
00058
00059 int chunk_num;
00060
00061 char* pending_data;
00062
00063 int pending_len;
00064
00065 } gridfile;
00066
00067
00068
00076 int gridfs_init(mongo_connection* client, const char* dbname,
00077 const char* prefix, gridfs* gfs);
00078
00081 void gridfs_destroy( gridfs* gfs );
00082
00089 void gridfile_writer_init( gridfile* gfile, gridfs* gfs, const char* remote_name,
00090 const char* content_type );
00091
00098 void gridfile_write_buffer( gridfile* gfile, const char* data,
00099 gridfs_offset length );
00100
00107 bson gridfile_writer_done( gridfile* gfile );
00108
00117 bson gridfs_store_buffer(gridfs* gfs, const char* data, gridfs_offset length,
00118 const char* remotename,
00119 const char * contenttype);
00120
00128 bson gridfs_store_file(gridfs* gfs, const char* filename,
00129 const char* remotename, const char* contenttype);
00130
00135 void gridfs_remove_filename(gridfs* gfs, const char* filename);
00136
00143 int gridfs_find_query(gridfs* gfs, bson* query, gridfile* gfile );
00144
00152 int gridfs_find_filename(gridfs* gfs, const char *filename,
00153 gridfile* gfile);
00154
00155
00156
00157
00164 int gridfile_init(gridfs* gfs, bson* meta, gridfile* gfile);
00165
00169 void gridfile_destroy(gridfile* gfile);
00170
00174 int gridfile_exists(gridfile* gfile);
00175
00180 const char * gridfile_get_filename(gridfile* gfile);
00181
00186 int gridfile_get_chunksize(gridfile* gfile);
00187
00192 gridfs_offset gridfile_get_contentlength(gridfile* gfile);
00193
00199 const char* gridfile_get_contenttype(gridfile* gfile);
00200
00205 bson_date_t gridfile_get_uploaddate(gridfile* gfile);
00206
00211 const char* gridfile_get_md5(gridfile* gfile);
00212
00219 const char *gridfile_get_field(gridfile* gfile,
00220 const char* name);
00221
00228 bson_bool_t gridfile_get_boolean(gridfile* gfile,
00229 const char* name);
00230
00236 bson gridfile_get_metadata(gridfile* gfile);
00237
00242 int gridfile_get_numchunks(gridfile* gfile);
00243
00248 bson gridfile_get_chunk(gridfile* gfile, int n);
00249
00256 mongo_cursor* gridfile_get_chunks(gridfile* gfile, int start, int size);
00257
00262 gridfs_offset gridfile_write_file(gridfile* gfile, FILE* stream);
00263
00273 gridfs_offset gridfile_read(gridfile* gfile, gridfs_offset size, char* buf);
00274
00282 gridfs_offset gridfile_seek(gridfile* gfile, gridfs_offset offset);
00283
00284 #endif