MongoDB C++ Driver current
Loading...
Searching...
No Matches
downloader.hpp
1// Copyright 2017 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
21#include <bsoncxx/document/value.hpp>
22#include <bsoncxx/document/view.hpp>
23#include <bsoncxx/stdx/optional.hpp>
24#include <bsoncxx/types/bson_value/view.hpp>
25#include <mongocxx/cursor.hpp>
26#include <mongocxx/stdx.hpp>
27
28#include <mongocxx/config/prelude.hpp>
29
30namespace mongocxx {
31inline namespace v_noabi {
32namespace gridfs {
33
38 std::int32_t chunks_offset = 0;
39 std::int32_t bytes_offset = 0;
40};
41
45class MONGOCXX_API downloader {
46 public:
52 downloader() noexcept;
53
58
62 downloader& operator=(downloader&&) noexcept;
63
64 downloader(const downloader&) = delete;
65
66 downloader& operator=(const downloader&) = delete;
67
72
77 explicit operator bool() const noexcept;
78
99 std::size_t read(std::uint8_t* buffer, std::size_t length);
100
106 void close();
107
114 std::int32_t chunk_size() const;
115
122 std::int64_t file_length() const;
123
130 bsoncxx::document::view files_document() const;
131
132 private:
133 friend class bucket;
134
135 //
136 // Constructs a new downloader stream.
137 //
138 // @param chunks
139 // The cursor to read the chunks of the file from. It must have a value if the length of the
140 // file is non-zero.
141 //
142 // @param start
143 // The offset from which to start reading the chunks of the file.
144 //
145 // @param chunk_size
146 // The expected size of a chunk in bytes.
147 //
148 // @param file_len
149 // The expected size of the file in bytes.
150 //
151 // @param files_doc
152 // The files collection document of the file being downloaded.
153 //
154 MONGOCXX_PRIVATE downloader(stdx::optional<cursor> chunks,
156 std::int32_t chunk_size,
157 std::int64_t file_len,
158 bsoncxx::document::value files_doc);
159
160 MONGOCXX_PRIVATE void fetch_chunk();
161
162 class MONGOCXX_PRIVATE impl;
163
164 MONGOCXX_PRIVATE impl& _get_impl();
165 MONGOCXX_PRIVATE const impl& _get_impl() const;
166
167 std::unique_ptr<impl> _impl;
168};
169
170} // namespace gridfs
171} // namespace v_noabi
172} // namespace mongocxx
173
174// CXX-2770: missing include of postlude header.
175#if defined(MONGOCXX_TEST_MACRO_GUARDS_FIX_MISSING_POSTLUDE)
176#include <mongocxx/config/postlude.hpp>
177#endif
Class representing a pointer to the result set of a query on a MongoDB server.
Definition cursor.hpp:36
Class representing a GridFS bucket.
Definition bucket.hpp:62
Class used to download a GridFS file.
Definition downloader.hpp:45
downloader() noexcept
Default constructs a downloader object.
The top-level namespace for bsoncxx library entities.
Definition element.hpp:24
The top-level namespace for mongocxx library entities.
Definition bulk_write.hpp:24
Class used to specify the offset from which to start reading the chunks of the file.
Definition downloader.hpp:37