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
129 typedef CBL_ENUM(uint8_t, CBLSeekBase) {
133 };
134
142 int64_t offset,
143 CBLSeekBase base,
144 CBLError* _cbl_nullable outError) CBLAPI;
145
148
151
153 bool CBLBlob_Equals(CBLBlob* blob, CBLBlob* anotherBlob) CBLAPI;
154
155#ifdef __APPLE__
156#pragma mark - CREATING:
157#endif
158
167
170
179
182
190 const void *data,
191 size_t length,
192 CBLError* _cbl_nullable outError) CBLAPI;
193
204 CBLBlobWriteStream* writer) CBLAPI;
205
206#ifdef __APPLE__
207#pragma mark - FLEECE UTILITIES:
208#endif
209
212 static inline bool FLValue_IsBlob(FLValue _cbl_nullable v) {
213 return FLDict_IsBlob(FLValue_AsDict(v));
214 }
215
221 return FLDict_GetBlob(FLValue_AsDict(value));
222 }
223
225
230 static inline void FLMutableArray_SetBlob(FLMutableArray array, uint32_t index, CBLBlob *blob) {
231 FLSlot_SetBlob(FLMutableArray_Set(array, index), blob);
232 }
233
237 static inline void FLMutableArray_AppendBlob(FLMutableArray array, CBLBlob *blob) {
239 }
240
245 static inline void FLMutableDict_SetBlob(FLMutableDict dict, FLString key, CBLBlob *blob) {
246 FLSlot_SetBlob(FLMutableDict_Set(dict, key), blob);
247 }
248
249
250#ifdef __APPLE__
251#pragma mark - BINDING DEV SUPPORT FOR BLOB:
252#endif
253
272 CBLError* _cbl_nullable outError) CBLAPI;
273
292 CBLError* _cbl_nullable outError) CBLAPI;
293
#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_ENUM(_type, _name)
Definition: CBL_Compat.h:56
#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)
(UNCOMMITTED) Use this API if you are developing Javascript language bindings.
int64_t CBLBlobReader_Seek(CBLBlobReadStream *stream, int64_t offset, CBLSeekBase base, CBLError *_cbl_nullable outError)
Sets the position of a CBLBlobReadStream.
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:212
_cbl_warn_unused CBLBlob * CBLBlob_CreateWithStream(FLString contentType, CBLBlobWriteStream *writer)
Creates a new blob after its data has been written to a CBLBlobWriteStream.
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.
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.
CBLSeekBase
Defines the interpretation of offset in CBLBlobReader_Seek.
Definition: CBLBlob.h:129
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)
(UNCOMMITTED) Use this API if you are developing Javascript language bindings.
static void FLMutableArray_SetBlob(FLMutableArray array, uint32_t index, CBLBlob *blob)
Stores a blob reference into an array.
Definition: CBLBlob.h:230
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:245
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:237
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:169
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:220
bool CBLBlobWriter_Write(CBLBlobWriteStream *writer, const void *data, size_t length, CBLError *_cbl_nullable outError)
Writes data to a new blob.
@ kCBLSeekModeRelative
Offset is relative to the current stream position.
Definition: CBLBlob.h:131
@ kCBLSeekModeFromStart
Offset is an absolute position starting from 0.
Definition: CBLBlob.h:130
@ kCBLSeekModeFromEnd
Offset is relative to the end of the blob.
Definition: CBLBlob.h:132
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