MongoDBCDriver  0.7.1
gridfs.h
Go to the documentation of this file.
00001 
00007 /*    Copyright 2009-2012 10gen Inc.
00008  *
00009  *    Licensed under the Apache License, Version 2.0 (the "License");
00010  *    you may not use this file except in compliance with the License.
00011  *    You may obtain a copy of the License at
00012  *
00013  *    http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  *    Unless required by applicable law or agreed to in writing, software
00016  *    distributed under the License is distributed on an "AS IS" BASIS,
00017  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018  *    See the License for the specific language governing permissions and
00019  *    limitations under the License.
00020  */
00021 
00022 #include "mongo.h"
00023 
00024 #ifndef MONGO_GRIDFS_H_
00025 #define MONGO_GRIDFS_H_
00026 
00027 enum {DEFAULT_CHUNK_SIZE = 256 * 1024};
00028 
00029 typedef uint64_t gridfs_offset;
00030 
00031 /* A GridFS represents a single collection of GridFS files in the database. */
00032 typedef struct {
00033     mongo *client; 
00034     const char *dbname; 
00035     const char *prefix; 
00036     const char *files_ns; 
00037     const char *chunks_ns; 
00038 } gridfs;
00039 
00040 /* A GridFile is a single GridFS file. */
00041 typedef struct {
00042     gridfs *gfs;        
00043     bson *meta;         
00044     gridfs_offset pos;  
00045     bson_oid_t id;      
00046     char *remote_name;  
00047     char *content_type; 
00048     gridfs_offset length; 
00049     int chunk_num;      
00050     char *pending_data; 
00051     int pending_len;    
00052 } gridfile;
00053 
00054 MONGO_EXPORT gridfs* gridfs_create( void );
00055 MONGO_EXPORT void gridfs_dispose(gridfs* gfs);
00056 MONGO_EXPORT gridfile* gridfile_create( void );
00057 MONGO_EXPORT void gridfile_dispose(gridfile* gf);
00058 MONGO_EXPORT void gridfile_get_descriptor(gridfile* gf, bson* out);
00059 
00069 MONGO_EXPORT int gridfs_init( mongo *client, const char *dbname,
00070                               const char *prefix, gridfs *gfs );
00071 
00078 MONGO_EXPORT void gridfs_destroy( gridfs *gfs );
00079 
00086 MONGO_EXPORT void gridfile_writer_init( gridfile *gfile, gridfs *gfs, const char *remote_name,
00087                                         const char *content_type );
00088 
00095 MONGO_EXPORT void gridfile_write_buffer( gridfile *gfile, const char *data,
00096         gridfs_offset length );
00097 
00105 MONGO_EXPORT int gridfile_writer_done( gridfile *gfile );
00106 
00117 MONGO_EXPORT int gridfs_store_buffer( gridfs *gfs, const char *data, gridfs_offset length,
00118                                       const char *remotename,
00119                                       const char *contenttype );
00120 
00130 MONGO_EXPORT int gridfs_store_file( gridfs *gfs, const char *filename,
00131                                     const char *remotename, const char *contenttype );
00132 
00138 MONGO_EXPORT void gridfs_remove_filename( gridfs *gfs, const char *filename );
00139 
00150 MONGO_EXPORT int gridfs_find_query( gridfs *gfs, bson *query, gridfile *gfile );
00151 
00161 MONGO_EXPORT int gridfs_find_filename( gridfs *gfs, const char *filename, gridfile *gfile );
00162 
00171 MONGO_EXPORT int gridfile_init( gridfs *gfs, bson *meta, gridfile *gfile );
00172 
00178 MONGO_EXPORT void gridfile_destroy( gridfile *gfile );
00179 
00184 MONGO_EXPORT bson_bool_t gridfile_exists( gridfile *gfile );
00185 
00192 MONGO_EXPORT const char *gridfile_get_filename( gridfile *gfile );
00193 
00200 MONGO_EXPORT int gridfile_get_chunksize( gridfile *gfile );
00201 
00209 MONGO_EXPORT gridfs_offset gridfile_get_contentlength( gridfile *gfile );
00210 
00219 MONGO_EXPORT const char *gridfile_get_contenttype( gridfile *gfile );
00220 
00228 MONGO_EXPORT bson_date_t gridfile_get_uploaddate( gridfile *gfile );
00229 
00237 MONGO_EXPORT const char *gridfile_get_md5( gridfile *gfile );
00238 
00248 const char *gridfile_get_field( gridfile *gfile,
00249                                 const char *name );
00250 
00259 bson_bool_t gridfile_get_boolean( gridfile *gfile,
00260                                   const char *name );
00261 
00269 MONGO_EXPORT void gridfile_get_metadata( gridfile *gfile, bson* out );
00270 
00277 MONGO_EXPORT int gridfile_get_numchunks( gridfile *gfile );
00278 
00285 MONGO_EXPORT void gridfile_get_chunk( gridfile *gfile, int n, bson* out );
00286 
00296 MONGO_EXPORT mongo_cursor *gridfile_get_chunks( gridfile *gfile, int start, int size );
00297 
00304 MONGO_EXPORT gridfs_offset gridfile_write_file( gridfile *gfile, FILE *stream );
00305 
00318 MONGO_EXPORT gridfs_offset gridfile_read( gridfile *gfile, gridfs_offset size, char *buf );
00319 
00330 MONGO_EXPORT gridfs_offset gridfile_seek( gridfile *gfile, gridfs_offset offset );
00331 
00332 #endif