Ditto 4.6.0
Loading...
Searching...
No Matches
Attachment.hpp
1#ifndef _DITTO_ATTACHMENT_
2#define _DITTO_ATTACHMENT_
3
4#include "DiskUsage.hpp"
5#include "json.hpp"
6
7#include <map>
8#include <memory>
9#include <string>
10#include <vector>
11
12struct AttachmentHandle;
13
14namespace ditto {
15class DittoHandleWrapper;
16class AttachmentInner;
17
23 friend class AttachmentFetcher;
24 friend class Collection;
25 friend class Store;
26
27public:
33 std::vector<uint8_t> get_data() const;
34
40 bool copy_to_path(const std::string &dest_path);
41
47 std::map<std::string, std::string> get_metadata() const;
48
54 std::string get_id() const;
55
61 uint64_t get_len() const;
62
69
70 // TODO: Hide these behind some sort of private implementation. They only need
71 // to be public for now because of their usage in the `to_json` function
72 // that's implemented for the `Attachment` type.
73 uint64_t get_type() const;
74 nlohmann::json::binary_t get_id_internal() const;
75
76private:
77 Attachment(std::vector<uint8_t> id, uint64_t len,
78 std::map<std::string, std::string> metadata,
79 struct AttachmentHandle *handle,
80 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper);
81
82 std::map<std::string, std::string> metadata;
83 std::vector<uint8_t> id;
84 uint64_t len;
85 std::shared_ptr<AttachmentInner> handle;
86 std::shared_ptr<DittoHandleWrapper> ditto_handle_wrapper;
87 DiskUsage disk_usage;
88 std::string path;
89 const char *get_path() const;
90 void update_path();
91};
92
93void to_json(nlohmann::json &j, const Attachment &a);
94
95} // namespace ditto
96#endif
These objects are returned by calls to Store::fetch_attachment.
Definition AttachmentFetcher.hpp:28
Represents an attachment and can be used to insert the associated attachment into a document at a spe...
Definition Attachment.hpp:22
DiskUsage & get_disk_usage() const
Provides access to the Attachment's disk usage.
std::string get_id() const
Gets the attachment's ID.
Definition Attachment.cpp:86
std::vector< uint8_t > get_data() const
Returns the attachment's data as a byte array.
Definition Attachment.cpp:40
bool copy_to_path(const std::string &dest_path)
Copies the attachment to the specified file path.
Definition Attachment.cpp:62
std::map< std::string, std::string > get_metadata() const
Gets the attachment's metadata.
Definition Attachment.cpp:93
uint64_t get_len() const
Gets the attachment's size in bytes.
Definition Attachment.cpp:91
A reference to a collection in a Store.
Definition Collection.hpp:27
Provides an interface to be able to monitor local files.
Definition DiskUsage.hpp:65
Provides access to Collections and a write transaction API.
Definition Store.hpp:29
basic_json<> json
default JSON class
Definition json.hpp:2933
Definition Arc.hpp:10