Google Cloud Storage C++ Client  1.42.0
A C++ Client Library for Google Cloud Storage
download_options.h
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
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 // https://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 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_DOWNLOAD_OPTIONS_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_DOWNLOAD_OPTIONS_H
17 
18 #include "google/cloud/storage/internal/complex_option.h"
19 #include "google/cloud/storage/version.h"
20 #include <cstdint>
21 #include <iostream>
22 
23 namespace google {
24 namespace cloud {
25 namespace storage {
27 struct ReadRangeData {
28  std::int64_t begin;
29  std::int64_t end;
30 };
31 
32 /**
33  * Request only a portion of the GCS object in a ReadObject operation.
34  *
35  * Note that the range is right-open, as it is customary in C++. That is, it
36  * excludes the `end` byte.
37  */
38 struct ReadRange : public internal::ComplexOption<ReadRange, ReadRangeData> {
39  ReadRange() = default;
40  explicit ReadRange(std::int64_t begin, std::int64_t end)
41  : ComplexOption(ReadRangeData{begin, end}) {}
42  static char const* name() { return "read-range"; }
43 };
44 
45 inline std::ostream& operator<<(std::ostream& os, ReadRangeData const& rhs) {
46  return os << "ReadRangeData={begin=" << rhs.begin << ", end=" << rhs.end
47  << "}";
48 }
49 
50 /**
51  * Download all the data from the GCS object starting at the given offset.
52  */
54  : public internal::ComplexOption<ReadFromOffset, std::int64_t> {
55  using ComplexOption::ComplexOption;
56  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
57  // explicitly
58  ReadFromOffset() = default;
59  static char const* name() { return "read-offset"; }
60 };
61 
62 /**
63  * Read last N bytes from the GCS object.
64  */
65 struct ReadLast : public internal::ComplexOption<ReadLast, std::int64_t> {
66  using ComplexOption::ComplexOption;
67  // GCC <= 7.0 does not use the inherited default constructor, redeclare it
68  // explicitly
69  ReadLast() = default;
70  static char const* name() { return "read-last"; }
71 };
72 
74 } // namespace storage
75 } // namespace cloud
76 } // namespace google
77 
78 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_STORAGE_DOWNLOAD_OPTIONS_H