Couchbase Lite C
Couchbase Lite C API
CBLBlob.h
Go to the documentation of this file.
1//
2// CBLBlob.h
3//
4// Copyright (c) 2018 Couchbase, Inc All rights reserved.
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//
18
19#pragma once
20#include "CBLBase.h"
21#include "fleece/Fleece.h"
22
24
58 CBL_PUBLIC extern const FLSlice kCBLBlobType;
62
63
65
66
72
77
78#ifdef __APPLE__
79#pragma mark - BLOB METADATA:
80#endif
81
83 uint64_t CBLBlob_Length(const CBLBlob*) CBLAPI;
84
87
90
94
98
99#ifdef __APPLE__
100#pragma mark - READING:
101#endif
102
107 CBLError* _cbl_nullable outError) CBLAPI;
108
111
116
124 void *dst,
125 size_t maxLength,
126 CBLError* _cbl_nullable outError) CBLAPI;
127
130
132 bool CBLBlob_Equals(CBLBlob* blob, CBLBlob* anotherBlob) CBLAPI;
133
134#ifdef __APPLE__
135#pragma mark - CREATING:
136#endif
137
146
149
158
161
169 const void *data,
170 size_t length,
171 CBLError* _cbl_nullable outError) CBLAPI;
172
183 CBLBlobWriteStream* writer) CBLAPI;
184
185#ifdef __APPLE__
186#pragma mark - FLEECE UTILITIES:
187#endif
188
191 static inline bool FLValue_IsBlob(FLValue _cbl_nullable v) {
192 return FLDict_IsBlob(FLValue_AsDict(v));
193 }
194
200 return FLDict_GetBlob(FLValue_AsDict(value));
201 }
202
204
209 static inline void FLMutableArray_SetBlob(FLMutableArray array, uint32_t index, CBLBlob *blob) {
210 FLSlot_SetBlob(FLMutableArray_Set(array, index), blob);
211 }
212
216 static inline void FLMutableArray_AppendBlob(FLMutableArray array, CBLBlob *blob) {
218 }
219
224 static inline void FLMutableDict_SetBlob(FLMutableDict dict, FLString key, CBLBlob *blob) {
225 FLSlot_SetBlob(FLMutableDict_Set(dict, key), blob);
226 }
227
228
229#ifdef __APPLE__
230#pragma mark - BINDING DEV SUPPORT FOR BLOB:
231#endif
232
248 CBLError* _cbl_nullable outError) CBLAPI;
249
265 CBLError* _cbl_nullable outError) CBLAPI;
266
#define CBLAPI
Definition: CBL_Compat.h:98
#define _cbl_nullable
Definition: CBL_Compat.h:86
#define CBL_CAPI_BEGIN
Definition: CBL_Compat.h:99
#define CBL_CAPI_END
Definition: CBL_Compat.h:100
#define CBL_PUBLIC
Definition: CBL_Compat.h:117
#define _cbl_warn_unused
Definition: CBL_Compat.h:41
FLDict FLValue_AsDict(FLValue) FLPURE
If a FLValue represents a dictionary, returns it as an FLDict, else NULL.
MUST_USE_RESULT FLSlot FLMutableArray_Set(FLMutableArray, uint32_t index)
Returns an FLSlot that refers to the given index of the given array.
MUST_USE_RESULT FLSlot FLMutableDict_Set(FLMutableDict FL_NONNULL, FLString key)
Returns an FLSlot that refers to the given key/value pair of the given dictionary.
MUST_USE_RESULT FLSlot FLMutableArray_Append(FLMutableArray)
Appends a null value to the array and returns an FLSlot that refers to that position.
_cbl_warn_unused CBLBlob * CBLBlob_CreateWithData(FLString contentType, FLSlice contents)
Creates a new blob given its contents as a single block of data.
CBL_PUBLIC const FLSlice kCBLBlobContentTypeProperty
"content_type"
bool CBLBlob_Equals(CBLBlob *blob, CBLBlob *anotherBlob)
Compares whether the two given blobs are equal based on their content.
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.
bool FLDict_IsBlob(FLDict _cbl_nullable)
Returns true if a dictionary in a document is a blob reference.
static bool FLValue_IsBlob(FLValue _cbl_nullable v)
Returns true if a value in a document is a blob reference.
Definition: CBLBlob.h:191
_cbl_warn_unused CBLBlob * CBLBlob_CreateWithStream(FLString contentType, CBLBlobWriteStream *writer)
Creates a new blob after its data has been written to a CBLBlobWriteStream.
int CBLBlobReader_Read(CBLBlobReadStream *stream, void *dst, size_t maxLength, CBLError *_cbl_nullable outError)
Reads data from a blob.
FLString CBLBlob_Digest(const CBLBlob *)
Returns the cryptographic digest of a blob's content (from its digest property).
_cbl_warn_unused FLStringResult CBLBlob_CreateJSON(const CBLBlob *blob)
Returns a blob's metadata as JSON.
FLString CBLBlob_ContentType(const CBLBlob *)
Returns a blob's MIME type, if its metadata has a content_type property.
void CBLBlobWriter_Close(CBLBlobWriteStream *_cbl_nullable)
Closes a blob-writing stream, if you need to give up without creating a CBLBlob.
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.
static void FLMutableArray_SetBlob(FLMutableArray array, uint32_t index, CBLBlob *blob)
Stores a blob reference into an array.
Definition: CBLBlob.h:209
void FLSlot_SetBlob(FLSlot slot, CBLBlob *blob)
static void FLMutableDict_SetBlob(FLMutableDict dict, FLString key, CBLBlob *blob)
Stores a blob reference into a Dict.
Definition: CBLBlob.h:224
struct CBLBlobReadStream CBLBlobReadStream
A stream for reading a blob's content.
Definition: CBLBlob.h:110
static void FLMutableArray_AppendBlob(FLMutableArray array, CBLBlob *blob)
Appends a blob reference to an array.
Definition: CBLBlob.h:216
FLDict CBLBlob_Properties(const CBLBlob *)
Returns a blob's metadata.
CBL_PUBLIC const FLSlice kCBLBlobLengthProperty
"length"
struct CBLBlobWriteStream CBLBlobWriteStream
A stream for writing a new blob to the database.
Definition: CBLBlob.h:148
CBL_PUBLIC const FLSlice kCBLBlobType
"blob"
_cbl_warn_unused CBLBlobReadStream *_cbl_nullable CBLBlob_OpenContentStream(const CBLBlob *blob, CBLError *_cbl_nullable)
Opens a stream for reading a blob's content.
CBL_PUBLIC const FLSlice kCBLBlobDigestProperty
"digest"
const CBLBlob *_cbl_nullable FLDict_GetBlob(FLDict _cbl_nullable blobDict)
Returns a CBLBlob object corresponding to a blob dictionary in a document.
_cbl_warn_unused CBLBlobWriteStream *_cbl_nullable CBLBlobWriter_Create(CBLDatabase *db, CBLError *_cbl_nullable)
Opens a stream for writing a new blob.
struct CBLBlob CBLBlob
A binary data value associated with a CBLDocument.
Definition: CBLBase.h:197
_cbl_warn_unused FLSliceResult CBLBlob_Content(const CBLBlob *blob, CBLError *_cbl_nullable outError)
Reads the blob's contents into memory and returns them.
uint64_t CBLBlob_Length(const CBLBlob *)
Returns the length in bytes of a blob's content (from its length property).
void CBLBlobReader_Close(CBLBlobReadStream *_cbl_nullable)
Closes a CBLBlobReadStream.
static const CBLBlob *_cbl_nullable FLValue_GetBlob(FLValue _cbl_nullable value)
Instantiates a CBLBlob object corresponding to a blob dictionary in a document.
Definition: CBLBlob.h:199
bool CBLBlobWriter_Write(CBLBlobWriteStream *writer, const void *data, size_t length, CBLError *_cbl_nullable outError)
Writes data to a new blob.
struct CBLDatabase CBLDatabase
A connection to an open database.
Definition: CBLBase.h:182
#define CBL_REFCOUNTED(TYPE, NAME)
Definition: CBLBase.h:170
struct _FLDict * FLMutableDict
A reference to a mutable dictionary.
Definition: Fleece.h:54
const struct _FLDict * FLDict
A reference to a dictionary (map) value.
Definition: Fleece.h:51
struct _FLSlot * FLSlot
A reference to a mutable array/dict item.
Definition: Fleece.h:52
struct _FLArray * FLMutableArray
A reference to a mutable array.
Definition: Fleece.h:53
const struct _FLValue * FLValue
A reference to a value of any type.
Definition: Fleece.h:49
A struct holding information about an error.
Definition: CBLBase.h:104
A simple reference to a block of memory.
Definition: FLSlice.h:46
A heap-allocated block of memory returned from an API call.
Definition: FLSlice.h:64