MongoDB C++ Driver  mongocxx-3.6.2
All Classes Namespaces Functions Typedefs Enumerations Enumerator Friends Pages
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 
30 namespace mongocxx {
31 MONGOCXX_INLINE_NAMESPACE_BEGIN
32 namespace gridfs {
33 
37 class MONGOCXX_API downloader {
38  public:
44  downloader() noexcept;
45 
49  downloader(downloader&&) noexcept;
50 
54  downloader& operator=(downloader&&) noexcept;
55 
56  downloader(const downloader&) = delete;
57 
58  downloader& operator=(const downloader&) = delete;
59 
64 
69  explicit operator bool() const noexcept;
70 
91  std::size_t read(std::uint8_t* buffer, std::size_t length);
92 
98  void close();
99 
106  std::int32_t chunk_size() const;
107 
114  std::int64_t file_length() const;
115 
122  bsoncxx::document::view files_document() const;
123 
124  private:
125  friend class bucket;
126 
127  //
128  // Constructs a new downloader stream.
129  //
130  // @param chunks
131  // The cursor to read the chunks of the file from. It must have a value if the length of the
132  // file is non-zero.
133  //
134  // @param files_doc
135  // The files collection document of the file being downloaded.
136  //
137  MONGOCXX_PRIVATE downloader(stdx::optional<cursor> chunks, bsoncxx::document::value files_doc);
138 
139  MONGOCXX_PRIVATE void fetch_chunk();
140 
141  class MONGOCXX_PRIVATE impl;
142 
143  MONGOCXX_PRIVATE impl& _get_impl();
144  MONGOCXX_PRIVATE const impl& _get_impl() const;
145 
146  std::unique_ptr<impl> _impl;
147 };
148 
149 } // namespace gridfs
150 MONGOCXX_INLINE_NAMESPACE_END
151 } // namespace mongocxx
mongocxx
Top level namespace for the MongoDB C++ driver.
Definition: bulk_write.hpp:24
bsoncxx
Top level namespace for MongoDB C++ BSON functionality.
Definition: element.hpp:24
mongocxx::gridfs::bucket
Class representing a GridFS bucket.
Definition: bucket.hpp:62
mongocxx::gridfs::downloader::downloader
downloader() noexcept
Default constructs a downloader object.
mongocxx::gridfs::downloader
Class used to download a GridFS file.
Definition: downloader.hpp:37
mongocxx::cursor
Class representing a pointer to the result set of a query on a MongoDB server.
Definition: cursor.hpp:36