22#include "cbl/CBLBlob.h"
23#include "cbl/CBLDatabase.h"
24#include "fleece/Mutable.hh"
39 class Blob :
protected RefCounted {
102 internal::check(content.buf, error);
119 inline static constexpr adopt_t adopt{};
135 internal::check(_stream, error);
147 size_t read(
void *dst,
size_t maxLength) {
150 internal::check(bytesRead >= 0, error);
151 return size_t(bytesRead);
161 internal::check(ret >= 0, error);
185 internal::check(_writer, error);
197 write(data.buf, data.size);
203 void write(
const void *src,
size_t length) {
206 internal::check(
false, error);
218 writer._writer =
nullptr;
226 internal::check(blob !=
nullptr || error.
code == 0, error);
227 return {
const_cast<CBLBlob*
>(blob), Blob::adopt};
#define CBL_REFCOUNTED_BOILERPLATE(CLASS, SUPER, C_TYPE)
Definition Base.hh:160
#define CBL_ASSUME_NONNULL_END
#define CBL_ASSUME_NONNULL_BEGIN
A reference to a binary data blob associated with a document.
Definition Blob.hh:39
std::string contentType() const
Returns a blob's MIME type, if its metadata has a content_type property.
Definition Blob.hh:77
Blob(std::optional< std::string_view > contentType, slice contents)
Creates a new blob, given its contents as a single block of data.
Definition Blob.hh:51
Blob() noexcept
Constructs a null reference (one that points to no object).
Definition Blob.hh:114
uint64_t length() const
Returns the length in bytes of a blob's content (from its length property).
Definition Blob.hh:74
friend class Database
Definition Blob.hh:117
std::string digest() const
Returns the cryptographic digest of a blob's content (from its digest property).
Definition Blob.hh:80
std::string createJSON() const
Returns the JSON representation of the blob's metadata dictionary.
Definition Blob.hh:87
bool blobEquals(const Blob &other) const
Compares whether this blob and another are equal based on their content.
Definition Blob.hh:71
CBLBlob *_Nullable ref() const
Returns a pointer to the underlying C object (CBLBlob), or NULL if this is a null reference.
Definition Blob.hh:114
static bool isBlob(fleece::Dict d)
Returns true if a dictionary in a document is a blob reference.
Definition Blob.hh:44
Blob(fleece::Dict d)
Creates a Blob instance on an existing blob reference in a document or query result.
Definition Blob.hh:66
BlobReadStream * openContentStream()
Opens a stream for reading a blob's content.
Definition Blob.hh:174
alloc_slice loadContent()
Reads the blob's content into memory and returns it.
Definition Blob.hh:99
fleece::Dict properties() const
Returns a blob's metadata.
Definition Blob.hh:84
A stream for reading a blob's content from the database.
Definition Blob.hh:125
size_t read(void *dst, size_t maxLength)
Reads data from a blob.
Definition Blob.hh:147
~BlobReadStream()
Closes the underlying read stream.
Definition Blob.hh:139
uint64_t position()
Returns the current position of a CBLBlobReadStream.
Definition Blob.hh:166
int64_t seek(int64_t offset, SeekBase base)
Sets the position of a CBLBlobReadStream.
Definition Blob.hh:158
CBLSeekBase SeekBase
Alias for the C CBLSeekBase enum describing the reference point used by seek.
Definition Blob.hh:128
BlobReadStream(Blob *blob)
Opens a stream for reading a blob's content.
Definition Blob.hh:132
A stream for writing a new blob to the database.
Definition Blob.hh:179
void write(fleece::slice data)
Writes data to a new blob.
Definition Blob.hh:196
BlobWriteStream(Database db)
Create a stream to write a new blob to the database.
Definition Blob.hh:182
void write(const void *src, size_t length)
Writes data to a new blob.
Definition Blob.hh:203
~BlobWriteStream()
Closes the blob-writing stream if it has not been handed off to a Blob constructor.
Definition Blob.hh:190
friend class Blob
Definition Blob.hh:210
A Couchbase Lite database, which is a container for collections of documents.
Definition Database.hh:147
void saveBlob(const Blob &blob)
Save a new Blob object into the database without associating it with any documents.
Definition Blob.hh:230
Blob getBlob(fleece::Dict properties) const
Get a Blob from the database using the Blob properties.
Definition Blob.hh:221
CBLDatabase *_Nullable ref() const
Returns a pointer to the underlying C object (CBLDatabase), or NULL if this is a null reference.
Definition Database.hh:411
_cbl_warn_unused CBLBlob * CBLBlob_CreateWithData(FLString contentType, FLSlice contents)
bool CBLBlob_Equals(CBLBlob *blob, CBLBlob *anotherBlob)
bool CBLDatabase_SaveBlob(CBLDatabase *db, CBLBlob *blob, CBLError *_cbl_nullable outError)
int64_t CBLBlobReader_Seek(CBLBlobReadStream *stream, int64_t offset, CBLSeekBase base, CBLError *_cbl_nullable outError)
bool FLDict_IsBlob(FLDict _cbl_nullable)
_cbl_warn_unused CBLBlob * CBLBlob_CreateWithStream(FLString contentType, CBLBlobWriteStream *writer)
uint64_t CBLBlobReader_Position(CBLBlobReadStream *stream)
int CBLBlobReader_Read(CBLBlobReadStream *stream, void *dst, size_t maxLength, CBLError *_cbl_nullable outError)
FLString CBLBlob_Digest(const CBLBlob *)
_cbl_warn_unused FLStringResult CBLBlob_CreateJSON(const CBLBlob *blob)
FLString CBLBlob_ContentType(const CBLBlob *)
void CBLBlobWriter_Close(CBLBlobWriteStream *_cbl_nullable)
const CBLBlob *_cbl_nullable CBLDatabase_GetBlob(CBLDatabase *db, FLDict properties, CBLError *_cbl_nullable outError)
struct CBLBlobReadStream CBLBlobReadStream
FLDict CBLBlob_Properties(const CBLBlob *)
struct CBLBlobWriteStream CBLBlobWriteStream
_cbl_warn_unused CBLBlobReadStream *_cbl_nullable CBLBlob_OpenContentStream(const CBLBlob *blob, CBLError *_cbl_nullable)
const CBLBlob *_cbl_nullable FLDict_GetBlob(FLDict _cbl_nullable blobDict)
_cbl_warn_unused CBLBlobWriteStream *_cbl_nullable CBLBlobWriter_Create(CBLDatabase *db, CBLError *_cbl_nullable)
_cbl_warn_unused FLSliceResult CBLBlob_Content(const CBLBlob *blob, CBLError *_cbl_nullable outError)
uint64_t CBLBlob_Length(const CBLBlob *)
void CBLBlobReader_Close(CBLBlobReadStream *_cbl_nullable)
bool CBLBlobWriter_Write(CBLBlobWriteStream *writer, const void *data, size_t length, CBLError *_cbl_nullable outError)
struct CBLRefCounted CBLRefCounted
fleece::slice slice
Convenience alias for fleece::slice, a non-owning view of a byte range.
Definition Base.hh:49
fleece::alloc_slice alloc_slice
Convenience alias for fleece::alloc_slice, an owning byte buffer.
Definition Base.hh:51