MongoDB C++ Driver mongocxx-3.11.0
Loading...
Searching...
No Matches
downloader.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <cstddef>
18#include <cstdint>
19#include <memory>
20
23
28
29#include <mongocxx/cursor.hpp>
30#include <mongocxx/stdx.hpp>
31
33
34namespace mongocxx {
35namespace v_noabi {
36namespace gridfs {
37
42 std::int32_t chunks_offset = 0;
43 std::int32_t bytes_offset = 0;
44};
45
50 public:
57
62
67
68 downloader(const downloader&) = delete;
69
70 downloader& operator=(const downloader&) = delete;
71
76
81 explicit MONGOCXX_ABI_EXPORT_CDECL() operator bool() const noexcept;
82
103 MONGOCXX_ABI_EXPORT_CDECL(std::size_t) read(std::uint8_t* buffer, std::size_t length);
104
111
119
127
134 MONGOCXX_ABI_EXPORT_CDECL(bsoncxx::v_noabi::document::view) files_document() const;
135
136 private:
137 friend ::mongocxx::v_noabi::gridfs::bucket;
138
139 //
140 // Constructs a new downloader stream.
141 //
142 // @param chunks
143 // The cursor to read the chunks of the file from. It must have a value if the length of the
144 // file is non-zero.
145 //
146 // @param start
147 // The offset from which to start reading the chunks of the file.
148 //
149 // @param chunk_size
150 // The expected size of a chunk in bytes.
151 //
152 // @param file_len
153 // The expected size of the file in bytes.
154 //
155 // @param files_doc
156 // The files collection document of the file being downloaded.
157 //
158 downloader(stdx::optional<cursor> chunks,
160 std::int32_t chunk_size,
161 std::int64_t file_len,
162 bsoncxx::v_noabi::document::value files_doc);
163
164 void fetch_chunk();
165
166 class impl;
167
168 impl& _get_impl();
169 const impl& _get_impl() const;
170
171 std::unique_ptr<impl> _impl;
172};
173
174} // namespace gridfs
175} // namespace v_noabi
176} // namespace mongocxx
177
178// CXX-2770: missing include of postlude header.
179#if defined(MONGOCXX_TEST_MACRO_GUARDS_FIX_MISSING_POSTLUDE)
181#endif
182
Class representing a pointer to the result set of a query on a MongoDB server.
Definition cursor.hpp:42
Class representing a GridFS bucket.
Definition bucket.hpp:67
Class used to download a GridFS file.
Definition downloader.hpp:49
bsoncxx::v_noabi::document::view files_document() const
Gets the files collection document of the file being downloaded.
std::int32_t chunk_size() const
Gets the chunk size of the file being downloaded.
void close()
Closes the downloader stream.
std::size_t read(std::uint8_t *buffer, std::size_t length)
Reads a specified number of bytes from the GridFS file being downloaded.
std::int64_t file_length() const
Gets the length of the file being downloaded.
Provides mongocxx::v_noabi::cursor.
Provides bsoncxx::v_noabi::document::value.
Provides bsoncxx::v_noabi::document::view.
Declares utilities to download GridFS files.
Declares mongocxx::v_noabi::gridfs::bucket.
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition fwd.hpp:222
The mongocxx macro guard postlude header.
The mongocxx macro guard prelude header.
The top-level namespace within which all bsoncxx library entities are declared.
The top-level namespace within which all mongocxx library entities are declared.
The top-level namespace reserved for the C++ standard library.
Provides std::optional-related polyfills for library API usage.
Redeclares bsoncxx::v_noabi::stdx in mongocxx::v_noabi::stdx for internal use.
Class used to specify the offset from which to start reading the chunks of the file.
Definition downloader.hpp:41
Provides bsoncxx::v_noabi::types::bson_value::view.