LiteCore
Couchbase Lite cross-platform core implementation
Loading...
Searching...
No Matches
c4BlobStore.h
Go to the documentation of this file.
1//
2// c4BlobStore.h
3//
4// Copyright 2016-Present Couchbase, Inc.
5//
6// Use of this software is governed by the Business Source License included
7// in the file licenses/BSL-Couchbase.txt. As of the Change Date specified
8// in that file, in accordance with the Business Source License, use of this
9// software will be governed by the Apache License, Version 2.0, included in
10// the file licenses/APL2.txt.
11//
12
13#pragma once
14#include "c4BlobStoreTypes.h"
15#include "c4DatabaseTypes.h"
16#ifdef __cplusplus
17# include <cstdio>
18#else
19# include <stdio.h>
20#endif
21
24
35
39
44
54
66 const C4EncryptionKey* C4NULLABLE encryptionKey,
67 C4Error* C4NULLABLE outError) C4API;
68
74
80
87/* NOTE: Every function in this section is thread-safe, as long as the C4BlobStore
88 reference remains valid while the function executes, i.e. there are no concurrent calls
89 to c4blob_freeStore, c4blob_deleteStore or c4db_close. */
90
95
98
107
110
116
119
124
131
139NODISCARD CBL_CORE_API size_t c4stream_read(C4ReadStream* stream, void* buffer, size_t maxBytesToRead,
140 C4Error* C4NULLABLE error) C4API;
141
145
150
162
165NODISCARD CBL_CORE_API bool c4stream_write(C4WriteStream*, const void* bytes, size_t length, C4Error* C4NULLABLE) C4API;
166
170
175
184
185
#define NODISCARD
Definition CompilerSupport.h:59
#define CBL_CORE_API
Definition c4Compat.h:134
#define C4NULLABLE
Definition c4Compat.h:38
#define C4API
Definition c4Compat.h:114
#define C4_ASSUME_NONNULL_BEGIN
Definition c4Compat.h:36
#define C4API_END_DECLS
Definition c4Compat.h:116
#define C4API_BEGIN_DECLS
Definition c4Compat.h:115
#define C4_ASSUME_NONNULL_END
Definition c4Compat.h:37
struct C4ReadStream C4ReadStream
An open stream for reading data from a blob.
Definition c4Base.h:172
struct C4BlobStore C4BlobStore
Opaque handle for an object that manages storage of blobs.
Definition c4Base.h:120
struct C4WriteStream C4WriteStream
An open stream for writing data to a blob.
Definition c4Base.h:184
struct C4Database C4Database
Opaque handle to an opened database.
Definition c4Base.h:136
CBL_CORE_API int64_t c4stream_getLength(C4ReadStream *, C4Error *)
Returns the exact length in bytes of the stream.
NODISCARD CBL_CORE_API C4ReadStream * c4blob_openReadStream(C4BlobStore *, C4BlobKey, C4Error *)
Opens a blob for reading, as a random-access byte stream.
CBL_CORE_API bool c4blob_keyFromString(C4String str, C4BlobKey *)
Decodes a string of the form "sha1-"+base64 into a raw key.
NODISCARD CBL_CORE_API size_t c4stream_read(C4ReadStream *stream, void *buffer, size_t maxBytesToRead, C4Error *error)
Reads from an open stream.
CBL_CORE_API void c4blob_freeStore(C4BlobStore *)
Closes/frees a BlobStore.
CBL_CORE_API C4StringResult c4blob_keyToString(C4BlobKey)
Encodes a blob key to a string of the form "sha1-"+base64.
NODISCARD CBL_CORE_API bool c4blob_delete(C4BlobStore *, C4BlobKey, C4Error *)
Deletes a blob from the store given its key.
CBL_CORE_API C4SliceResult c4blob_getContents(C4BlobStore *, C4BlobKey, C4Error *)
Reads the entire contents of a blob into memory.
CBL_CORE_API C4BlobStore * c4db_getBlobStore(C4Database *db, C4Error *outError)
Returns the BlobStore associated with a bundled database.
CBL_CORE_API int64_t c4blob_getSize(C4BlobStore *, C4BlobKey)
Gets the content size of a blob given its key.
NODISCARD CBL_CORE_API C4WriteStream * c4blob_openWriteStream(C4BlobStore *, C4Error *)
Opens a write stream for creating a new blob.
NODISCARD CBL_CORE_API bool c4blob_create(C4BlobStore *store, C4Slice contents, const C4BlobKey *expectedKey, C4BlobKey *outKey, C4Error *error)
Stores a blob.
CBL_CORE_API uint64_t c4stream_bytesWritten(C4WriteStream *)
Returns the number of bytes written to the stream.
NODISCARD CBL_CORE_API bool c4stream_install(C4WriteStream *, const C4BlobKey *expectedKey, C4Error *)
Adds the data written to the stream as a finished blob to the store.
NODISCARD CBL_CORE_API C4BlobKey c4blob_computeKey(C4Slice contents)
Derives the key of the given data, without storing it.
NODISCARD CBL_CORE_API C4BlobKey c4stream_computeBlobKey(C4WriteStream *)
Computes the blob-key (digest) of the data written to the stream.
CBL_CORE_API bool c4blob_deleteStore(C4BlobStore *, C4Error *)
Deletes the BlobStore's blobs and directory, and (if successful) frees the object.
CBL_CORE_API C4StringResult c4blob_getFilePath(C4BlobStore *, C4BlobKey, C4Error *)
Returns the path of the file that stores the blob, if possible.
NODISCARD CBL_CORE_API C4BlobStore * c4blob_openStore(C4String dirPath, C4DatabaseFlags flags, const C4EncryptionKey *encryptionKey, C4Error *outError)
Opens a BlobStore in a directory.
NODISCARD CBL_CORE_API bool c4stream_seek(C4ReadStream *, uint64_t position, C4Error *)
Moves to a random location in the stream; the next c4stream_read call will read from that location.
NODISCARD CBL_CORE_API bool c4stream_write(C4WriteStream *, const void *bytes, size_t length, C4Error *)
Writes data to a stream.
C4DatabaseFlags
Definition c4DatabaseTypes.h:33
A unique identifier of a blob based on a SHA-1 digest of its contents.
Definition c4BlobStoreTypes.h:33
Encryption key specified in a C4DatabaseConfig.
Definition c4DatabaseTypes.h:57
An error value.
Definition c4Error.h:133
A simple reference to a block of memory.
Definition FLSlice.h:45
A heap-allocated block of memory returned from an API call.
Definition FLSlice.h:63