MongoDB C++ Driver current
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 {
31MONGOCXX_INLINE_NAMESPACE_BEGIN
32namespace gridfs {
33
35 std::int32_t chunks_offset = 0;
36 std::int32_t bytes_offset = 0;
37};
38
42class MONGOCXX_API downloader {
43 public:
49 downloader() noexcept;
50
55
59 downloader& operator=(downloader&&) noexcept;
60
61 downloader(const downloader&) = delete;
62
63 downloader& operator=(const downloader&) = delete;
64
69
74 explicit operator bool() const noexcept;
75
96 std::size_t read(std::uint8_t* buffer, std::size_t length);
97
103 void close();
104
111 std::int32_t chunk_size() const;
112
119 std::int64_t file_length() const;
120
127 bsoncxx::document::view files_document() const;
128
129 private:
130 friend class bucket;
131
132 //
133 // Constructs a new downloader stream.
134 //
135 // @param chunks
136 // The cursor to read the chunks of the file from. It must have a value if the length of the
137 // file is non-zero.
138 //
139 // @param start
140 // The offset from which to start reading the chunks of the file.
141 //
142 // @param chunk_size
143 // The expected size of a chunk in bytes.
144 //
145 // @param file_len
146 // The expected size of the file in bytes.
147 //
148 // @param files_doc
149 // The files collection document of the file being downloaded.
150 //
151 MONGOCXX_PRIVATE downloader(stdx::optional<cursor> chunks,
153 std::int32_t chunk_size,
154 std::int64_t file_len,
155 bsoncxx::document::value files_doc);
156
157 MONGOCXX_PRIVATE void fetch_chunk();
158
159 class MONGOCXX_PRIVATE impl;
160
161 MONGOCXX_PRIVATE impl& _get_impl();
162 MONGOCXX_PRIVATE const impl& _get_impl() const;
163
164 std::unique_ptr<impl> _impl;
165};
166
167} // namespace gridfs
168MONGOCXX_INLINE_NAMESPACE_END
169} // namespace mongocxx
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:63
Class used to download a GridFS file.
Definition: downloader.hpp:42
downloader() noexcept
Default constructs a downloader object.
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
Definition: downloader.hpp:34