Loading...
Searching...
No Matches
Mongo GridFS Chunk API
Mongo Sync API » Mongo GridFS API

This submodule provides chunk-based access to GridFS files. More...

Collaboration diagram for Mongo GridFS Chunk API:

## Functions

mongo_sync_gridfs_chunked_file * | mongo_sync_gridfs_chunked_find (mongo_sync_gridfs *gfs, const bson *query)
| Find a file on GridFS.
mongo_sync_gridfs_chunked_file * | mongo_sync_gridfs_chunked_file_new_from_buffer (mongo_sync_gridfs *gfs, const bson *metadata, const guint8 *data, gint64 size)
| Upload a file to GridFS from a buffer.
void | mongo_sync_gridfs_chunked_file_free (mongo_sync_gridfs_chunked_file *gfile)
| Free a GridFS chunked file object.
mongo_sync_cursor * | mongo_sync_gridfs_chunked_file_cursor_new (mongo_sync_gridfs_chunked_file *gfile, gint start, gint num)
| Create a cursor for a GridFS chunked file.
guint8 * | mongo_sync_gridfs_chunked_file_cursor_get_chunk (mongo_sync_cursor *cursor, gint32 *size)
| Get the data of a GridFS file chunk, via a cursor.

## Detailed Description

This submodule provides chunk-based access to GridFS files.

Chunk-based access has the advantage of being reasonably lightweight and fast, and the disadvantage of making it harder to do arbitrary reads or multi-part writes.

It's best used when the whole file needs to be retrieved, or when uploading files that either fit in a buffer, or can be mmapped.

## Function Documentation

## mongo_sync_gridfs_chunked_file_cursor_get_chunk()

guint8 * mongo_sync_gridfs_chunked_file_cursor_get_chunk | ( | mongo_sync_cursor * | cursor,
|  | gint32 * | size )

Get the data of a GridFS file chunk, via a cursor.

Once we have a cursor, it can be iterated over with mongo_sync_cursor_next(), and its data can be conveniently accessed with this function.

Parameters

  cursor | is the cursor object to work with.
  size | is a pointer to a variable where the chunk's actual size can be stored.

Returns
  A pointer to newly allocated memory that holds the current chunk's data, or NULL on error. It is the responsibility of the caller to free this once it is no longer needed.

## mongo_sync_gridfs_chunked_file_cursor_new()

mongo_sync_cursor * mongo_sync_gridfs_chunked_file_cursor_new | ( | mongo_sync_gridfs_chunked_file * | gfile,
|  | gint | start,
|  | gint | num )

Create a cursor for a GridFS chunked file.

The cursor can be used (via mongo_sync_gridfs_file_cursor_get_chunk()) to retrieve a GridFS file chunk by chunk.

Parameters

  gfile | is the GridFS chunked file to work with.
  start | is the starting chunk.
  num | is the total number of chunks to make a cursor for.

Returns
  A newly allocated cursor object, or NULL on error. It is the responsibility of the caller to free the cursor once it is no longer needed.

## mongo_sync_gridfs_chunked_file_free()

void mongo_sync_gridfs_chunked_file_free | ( | mongo_sync_gridfs_chunked_file * | gfile | ) |

Free a GridFS chunked file object.

Parameters

  gfile | is the file object to free.

## mongo_sync_gridfs_chunked_file_new_from_buffer()

mongo_sync_gridfs_chunked_file * mongo_sync_gridfs_chunked_file_new_from_buffer | ( | mongo_sync_gridfs * | gfs,
|  | const bson * | metadata,
|  | const guint8 * | data,
|  | gint64 | size )

Upload a file to GridFS from a buffer.

Create a new file on GridFS from a buffer, using custom meta-data.

Parameters

  gfs | is the GridFS to create the file on.
  metadata | is the (optional) file metadata.
  data | is the data to store on GridFS.
  size | is the size of the data.

Returns
  A newly allocated file object, or NULL on error. It is the responsibility of the caller to free the returned object once it is no longer needed.

Note
  The metadata MUST NOT contain any of the required GridFS metadata fields (_id, length, chunkSize, uploadDate, md5), otherwise a conflict will occurr, against which the function does not guard by design.

## mongo_sync_gridfs_chunked_find()

mongo_sync_gridfs_chunked_file * mongo_sync_gridfs_chunked_find | ( | mongo_sync_gridfs * | gfs,
|  | const bson * | query )

Find a file on GridFS.

Finds a file on GridFS, based on a custom query.

Parameters

  gfs | is the GridFS to find the file in.
  query | is the custom query based on which the file shall be sought.

Returns
  A newly allocated chunked file object, or NULL on error. It is the responsibility of the caller to free the returned object once it is no longer needed.