|
Couchbase Lite C
Couchbase Lite C API
|
A CBLBlob is a binary data blob associated with a document. More...
Typedefs | |
| typedef struct CBLBlob | CBLBlob |
| A binary data value associated with a CBLDocument. | |
| typedef struct CBLBlobReadStream | CBLBlobReadStream |
| A stream for reading a blob's content. | |
| typedef struct CBLBlobWriteStream | CBLBlobWriteStream |
| A stream for writing a new blob to the database. | |
Enumerations | |
| enum | CBLSeekBase : uint8_t { kCBLSeekModeFromStart , kCBLSeekModeRelative , kCBLSeekModeFromEnd } |
Functions | |
| static const CBLBlob * | CBLBlob_Retain (const CBLBlob *_cbl_nullable t) |
| static void | CBLBlob_Release (const CBLBlob *_cbl_nullable t) |
| bool | FLDict_IsBlob (FLDict _cbl_nullable) |
| Returns true if a dictionary in a document is a blob reference. | |
| const CBLBlob *_cbl_nullable | FLDict_GetBlob (FLDict _cbl_nullable blobDict) |
| Returns a CBLBlob object corresponding to a blob dictionary in a document. | |
| uint64_t | CBLBlob_Length (const CBLBlob *) |
| Returns the length in bytes of a blob's content (from its length property). | |
| FLString | CBLBlob_ContentType (const CBLBlob *) |
| Returns a blob's MIME type, if its metadata has a content_type property. | |
| FLString | CBLBlob_Digest (const CBLBlob *) |
| Returns the cryptographic digest of a blob's content (from its digest property). | |
| FLDict | CBLBlob_Properties (const CBLBlob *) |
| Returns a blob's metadata. | |
| _cbl_warn_unused FLStringResult | CBLBlob_CreateJSON (const CBLBlob *blob) |
| Returns a blob's metadata as JSON. | |
| _cbl_warn_unused FLSliceResult | CBLBlob_Content (const CBLBlob *blob, CBLError *_cbl_nullable outError) |
| Reads the blob's content into memory and returns them. | |
| _cbl_warn_unused CBLBlobReadStream *_cbl_nullable | CBLBlob_OpenContentStream (const CBLBlob *blob, CBLError *_cbl_nullable) |
| Opens a stream for reading a blob's content. | |
| int | CBLBlobReader_Read (CBLBlobReadStream *stream, void *dst, size_t maxLength, CBLError *_cbl_nullable outError) |
| Reads data from a blob. | |
| int64_t | CBLBlobReader_Seek (CBLBlobReadStream *stream, int64_t offset, CBLSeekBase base, CBLError *_cbl_nullable outError) |
| Sets the position of a CBLBlobReadStream. | |
| uint64_t | CBLBlobReader_Position (CBLBlobReadStream *stream) |
| Returns the current position of a CBLBlobReadStream. | |
| void | CBLBlobReader_Close (CBLBlobReadStream *_cbl_nullable) |
| Closes a CBLBlobReadStream. | |
| bool | CBLBlob_Equals (CBLBlob *blob, CBLBlob *anotherBlob) |
| Compares whether the two given blobs are equal based on their content. | |
| _cbl_warn_unused CBLBlob * | CBLBlob_CreateWithData (FLString contentType, FLSlice contents) |
| Creates a new blob given its contents as a single block of data. | |
| _cbl_warn_unused CBLBlobWriteStream *_cbl_nullable | CBLBlobWriter_Create (CBLDatabase *db, CBLError *_cbl_nullable) |
| Opens a stream for writing a new blob. | |
| void | CBLBlobWriter_Close (CBLBlobWriteStream *_cbl_nullable) |
| Closes a blob-writing stream, if you need to give up without creating a CBLBlob. | |
| bool | CBLBlobWriter_Write (CBLBlobWriteStream *writer, const void *data, size_t length, CBLError *_cbl_nullable outError) |
| Writes data to a new blob. | |
| _cbl_warn_unused CBLBlob * | CBLBlob_CreateWithStream (FLString contentType, CBLBlobWriteStream *writer) |
| Creates a new blob after its data has been written to a CBLBlobWriteStream. | |
| static bool | FLValue_IsBlob (FLValue _cbl_nullable v) |
| Returns true if a value in a document is a blob reference. | |
| static const CBLBlob *_cbl_nullable | FLValue_GetBlob (FLValue _cbl_nullable value) |
| Instantiates a CBLBlob object corresponding to a blob dictionary in a document. | |
| void | FLSlot_SetBlob (FLSlot slot, CBLBlob *blob) |
| static void | FLMutableArray_SetBlob (FLMutableArray array, uint32_t index, CBLBlob *blob) |
| Stores a blob reference into an array. | |
| static void | FLMutableArray_AppendBlob (FLMutableArray array, CBLBlob *blob) |
| Appends a blob reference to an array. | |
| static void | FLMutableDict_SetBlob (FLMutableDict dict, FLString key, CBLBlob *blob) |
| Stores a blob reference into a Dict. | |
| const CBLBlob *_cbl_nullable | CBLDatabase_GetBlob (CBLDatabase *db, FLDict properties, CBLError *_cbl_nullable outError) |
| Get a CBLBlob object from the database using the CBLBlob properties. | |
| bool | CBLDatabase_SaveBlob (CBLDatabase *db, CBLBlob *blob, CBLError *_cbl_nullable outError) |
| Save a new CBLBlob object into the database without associating it with any documents. | |
Variables | |
| CBL_PUBLIC const FLSlice | kCBLBlobType |
| "blob" | |
| CBL_PUBLIC const FLSlice | kCBLBlobDigestProperty |
| "digest" | |
| CBL_PUBLIC const FLSlice | kCBLBlobLengthProperty |
| "length" | |
| CBL_PUBLIC const FLSlice | kCBLBlobContentTypeProperty |
| "content_type" | |
A CBLBlob is a binary data blob associated with a document.
The content of the blob is not stored in the document, but externally in the database. It is loaded only on demand, and can be streamed. Blobs can be arbitrarily large, although Sync Gateway will only accept blobs under 20MB.
The document contains only a blob reference: a dictionary with the special marker property "@type":"blob", and another property digest whose value is a hex SHA-1 digest of the blob's data. This digest is used as the key to retrieve the blob data. The dictionary usually also has the property length, containing the blob's length in bytes, and it may have the property content_type, containing a MIME type.
A CBLBlob object acts as a proxy for such a dictionary in a CBLDocument. Once you've loaded a document and located the Fleece Dictionaries holding the blob reference, call FLDict_GetBlob on it to create a CBLBlob object you can call. The object has accessors for the blob's metadata and for loading the data itself.
To create a new blob from in-memory data, call CBLBlob_CreateWithData, then call FLSlot_SetBlob to add the CBLBlob to a mutable array or dictionary in the document. For example:
FLSlot_SetBlob(FLMutableDict_Set(properties, key), blob);
To create a new blob from a stream, call CBLBlobWriter_Create to create a CBLBlobWriteStream, then make one or more calls to CBLBlobWriter_Write to write data to the blob, then finally call CBLBlob_CreateWithStream to create the blob. To store the blob into a document, do as in the previous paragraph.
A binary data value associated with a CBLDocument.
| typedef struct CBLBlobReadStream CBLBlobReadStream |
A stream for reading a blob's content.
| typedef struct CBLBlobWriteStream CBLBlobWriteStream |
A stream for writing a new blob to the database.
| enum CBLSeekBase : uint8_t |
| _cbl_warn_unused FLSliceResult CBLBlob_Content | ( | const CBLBlob * | blob, |
| CBLError *_cbl_nullable | outError ) |
Reads the blob's content into memory and returns them.
Returns a blob's MIME type, if its metadata has a content_type property.
| _cbl_warn_unused FLStringResult CBLBlob_CreateJSON | ( | const CBLBlob * | blob | ) |
Returns a blob's metadata as JSON.
| _cbl_warn_unused CBLBlob * CBLBlob_CreateWithData | ( | FLString | contentType, |
| FLSlice | contents ) |
| _cbl_warn_unused CBLBlob * CBLBlob_CreateWithStream | ( | FLString | contentType, |
| CBLBlobWriteStream * | writer ) |
Creates a new blob after its data has been written to a CBLBlobWriteStream.
You should then add the blob to a mutable document as a property – see FLSlot_SetBlob.
| contentType | The MIME type (optional). |
| writer | The blob-writing stream the data was written to. |
Returns the cryptographic digest of a blob's content (from its digest property).
Compares whether the two given blobs are equal based on their content.
| uint64_t CBLBlob_Length | ( | const CBLBlob * | ) |
Returns the length in bytes of a blob's content (from its length property).
| _cbl_warn_unused CBLBlobReadStream *_cbl_nullable CBLBlob_OpenContentStream | ( | const CBLBlob * | blob, |
| CBLError * | _cbl_nullable ) |
Opens a stream for reading a blob's content.
Returns a blob's metadata.
This includes the digest, length, content_type, and @type properties, as well as any custom ones that may have been added.
|
inlinestatic |
|
inlinestatic |
| void CBLBlobReader_Close | ( | CBLBlobReadStream * | _cbl_nullable | ) |
Closes a CBLBlobReadStream.
| uint64_t CBLBlobReader_Position | ( | CBLBlobReadStream * | stream | ) |
Returns the current position of a CBLBlobReadStream.
| int CBLBlobReader_Read | ( | CBLBlobReadStream * | stream, |
| void * | dst, | ||
| size_t | maxLength, | ||
| CBLError *_cbl_nullable | outError ) |
Reads data from a blob.
| stream | The stream to read from. |
| dst | The address to copy the read data to. |
| maxLength | The maximum number of bytes to read. |
| outError | On failure, an error will be stored here if non-NULL. |
| int64_t CBLBlobReader_Seek | ( | CBLBlobReadStream * | stream, |
| int64_t | offset, | ||
| CBLSeekBase | base, | ||
| CBLError *_cbl_nullable | outError ) |
Sets the position of a CBLBlobReadStream.
| stream | The stream to reposition. |
| offset | The byte offset in the stream (relative to the mode). |
| base | The base position from which the offset is calculated. |
| outError | On failure, an error will be stored here if non-NULL. |
| void CBLBlobWriter_Close | ( | CBLBlobWriteStream * | _cbl_nullable | ) |
Closes a blob-writing stream, if you need to give up without creating a CBLBlob.
| _cbl_warn_unused CBLBlobWriteStream *_cbl_nullable CBLBlobWriter_Create | ( | CBLDatabase * | db, |
| CBLError * | _cbl_nullable ) |
Opens a stream for writing a new blob.
You should next call CBLBlobWriter_Write one or more times to write the data, then CBLBlob_CreateWithStream to create the blob.
If for some reason you need to abort, just call CBLBlobWriter_Close.
| bool CBLBlobWriter_Write | ( | CBLBlobWriteStream * | writer, |
| const void * | data, | ||
| size_t | length, | ||
| CBLError *_cbl_nullable | outError ) |
Writes data to a new blob.
| writer | The stream to write to. |
| data | The address of the data to write. |
| length | The length of the data to write. |
| outError | On failure, error info will be written here. |
| const CBLBlob *_cbl_nullable CBLDatabase_GetBlob | ( | CBLDatabase * | db, |
| FLDict | properties, | ||
| CBLError *_cbl_nullable | outError ) |
Get a CBLBlob object from the database using the CBLBlob properties.
The CBLBlob properties is a blob's metadata containing two required fields which are a special marker property "@type":"blob", and property digest whose value is a hex SHA-1 digest of the blob's data. The other optional properties are length and content_type. To obtain the CBLBlob properties from a CBLBlob, call CBLBlob_Properties function.
| db | The database. |
| properties | The properties for getting the CBLBlob object. |
| outError | On failure, error info will be written here if specified. A nonexistent blob is not considered a failure; in that event the error code will be zero. |
| bool CBLDatabase_SaveBlob | ( | CBLDatabase * | db, |
| CBLBlob * | blob, | ||
| CBLError *_cbl_nullable | outError ) |
Save a new CBLBlob object into the database without associating it with any documents.
The properties of the saved CBLBlob object will include information necessary for referencing the CBLBlob object in the properties of the document to be saved into the database.
Normally you do not need to use this function unless you are in the situation (e.g. developing javascript binding) that you cannot retain the CBLBlob object until the document containing the CBLBlob object is successfully saved into the database.
| db | The database. |
| blob | The The CBLBlob to save. |
| outError | On failure, error info will be written here. |
| const CBLBlob *_cbl_nullable FLDict_GetBlob | ( | FLDict _cbl_nullable | blobDict | ) |
| bool FLDict_IsBlob | ( | FLDict | _cbl_nullable | ) |
Returns true if a dictionary in a document is a blob reference.
If so, you can call FLDict_GetBlob to access it.
|
inlinestatic |
Appends a blob reference to an array.
| array | The array to store into. |
| blob | The blob reference to be stored. |
|
inlinestatic |
Stores a blob reference into an array.
| array | The array to store into. |
| Index | The position in the array at which to store the blob reference. |
| blob | The blob reference to be stored. |
|
inlinestatic |
Stores a blob reference into a Dict.
| dict | The Dict to store into. |
| key | The key to associate the blob reference with. |
| blob | The blob reference to be stored. |
|
inlinestatic |
|
inlinestatic |
Returns true if a value in a document is a blob reference.
If so, you can call FLValue_GetBlob to access it.
|
extern |
"content_type"
|
extern |
"digest"
|
extern |
"length"
|
extern |
"blob"