Google Cloud Storage C++ Client
1.42.0
A C++ Client Library for Google Cloud Storage
|
Defines a std::basic_ostream<char>
to write to a GCS object.
More...
#include <google/cloud/storage/object_write_stream.h>
Public Member Functions | |
ObjectWriteStream () | |
Creates a stream not associated with any buffer. More... | |
ObjectWriteStream (std::unique_ptr< internal::ObjectWriteStreambuf > buf) | |
Creates a stream associated with the give request. More... | |
ObjectWriteStream (ObjectWriteStream &&rhs) noexcept | |
ObjectWriteStream & | operator= (ObjectWriteStream &&rhs) noexcept |
void | swap (ObjectWriteStream &rhs) |
ObjectWriteStream (ObjectWriteStream const &)=delete | |
ObjectWriteStream & | operator= (ObjectWriteStream const &)=delete |
~ObjectWriteStream () override | |
Closes the stream (if necessary). More... | |
bool | IsOpen () const |
Return true if the stream is open to write more data. More... | |
void | Close () |
Close the stream, finalizing the upload. More... | |
StatusOr< ObjectMetadata > const & | metadata () const & |
Access the upload results. More... | |
StatusOr< ObjectMetadata > && | metadata () && |
std::string const & | received_hash () const |
The received CRC32C checksum and the MD5 hash values as reported by GCS. More... | |
std::string const & | computed_hash () const |
The locally computed checksum and hashes, as a string. More... | |
HeadersMap const & | headers () const |
The headers (if any) returned by the service. More... | |
std::string const & | payload () const |
The returned payload as a raw string, for debugging only. More... | |
std::string const & | resumable_session_id () const |
Returns the resumable upload session id for this upload. More... | |
std::uint64_t | next_expected_byte () const |
Returns the next expected byte. More... | |
void | Suspend () && |
Suspends an upload. More... | |
Status | last_status () const |
Returns the status of partial errors. More... | |
Defines a std::basic_ostream<char>
to write to a GCS object.
This class is used to upload objects to GCS. It can handle objects of any size, but keep the following considerations in mind:
storage::Client::InsertObject()
, it is simpler and faster in most cases.operator<<
APIs. Note that formatted I/O typically implies some form of buffering and data copying. For best performance, consider using the .write() member function..write()
call this class attempts to send the data immediately, this this the unbuffered API after all. If any previously buffered data and the data provided in the .write()
call are larger than an upload quantum the class sends data immediately. Any data in excess of a multiple of the upload quantum are buffered for the next upload.These examples may clarify how this works:
ObjectWriteStream
that receives a .write()
call with 257 KiB of data. The first 256 KiB are immediately sent and the remaining 1 KiB is buffered for a future upload..write()
call with 256 KiB then it will send the buffered 1 KiB of data and the first 255 KiB from the new buffer. The last 1 KiB is buffered for a future upload.ObjectWriteStream
that receives a .write()
call with 4 MiB of data. This data is sent immediately, and no data is buffered..write()
call with 1024 KiB then both the 256 KiB and the 1024 KiB of data are uploaded immediately.operator<<
, this class will buffer data based on theClientOptions::upload_buffer_size()
setting. Note that this setting is expressed in bytes, but it is always rounded (up) to an upload quantum..write()
. Larger buffers result in better performance. Note that our empirical results show that these improvements tapper off around 32MiB or so.Suspend()
function.Definition at line 103 of file object_write_stream.h.
google::cloud::storage::ObjectWriteStream::ObjectWriteStream | ( | ) |
Creates a stream not associated with any buffer.
Attempts to use this stream will result in failures.
|
explicit |
Creates a stream associated with the give request.
Reading from the stream will result in http requests to get more data from the GCS object.
buf | an initialized ObjectWriteStreambuf to upload the data. |
|
noexcept |
|
delete |
|
override |
Closes the stream (if necessary).
void google::cloud::storage::ObjectWriteStream::Close | ( | ) |
Close the stream, finalizing the upload.
Closing a stream completes an upload and creates the uploaded object. On failure it sets the badbit
of the stream.
The metadata of the uploaded object, or a detailed error status, is accessible via the metadata()
member function. Note that the metadata may be empty if the application creates a stream with the Fields("")
parameter, applications cannot assume that all fields in the metadata are filled on success.
If | the application has enabled the exception mask this function may throw std::ios_base::failure . |
|
inline |
The locally computed checksum and hashes, as a string.
This object computes the CRC32C checksum and MD5 hash of the uploaded data. There are several cases where these values may be empty or irrelevant, for example:
The string has the same format as the value returned by received_hash()
. Note that the format of this string is also subject to change without notice.
Definition at line 228 of file object_write_stream.h.
|
inline |
The headers (if any) returned by the service.
For debugging only.
Definition at line 242 of file object_write_stream.h.
|
inline |
Return true if the stream is open to write more data.
Definition at line 164 of file object_write_stream.h.
|
inline |
Returns the status of partial errors.
Application may write multiple times before closing the stream, this function gives the capability to find out status even before stream closure.
This function is different than metadata()
as calling metadata()
before Close() is undefined.
Definition at line 292 of file object_write_stream.h.
|
inline |
Definition at line 191 of file object_write_stream.h.
|
inline |
Access the upload results.
Note that calling these member functions before Close()
is undefined behavior.
Definition at line 190 of file object_write_stream.h.
|
inline |
Returns the next expected byte.
For non-resumable uploads this is always zero. Applications that use resumable uploads can use this value to resend any data not committed in the GCS.
Definition at line 266 of file object_write_stream.h.
|
inlinenoexcept |
Definition at line 125 of file object_write_stream.h.
|
delete |
|
inline |
The returned payload as a raw string, for debugging only.
Definition at line 245 of file object_write_stream.h.
|
inline |
The received CRC32C checksum and the MD5 hash values as reported by GCS.
When the upload is finalized (via Close()
) the GCS server reports the CRC32C checksum and, if the object is not a composite object, the MDF hash of the uploaded data. This class compares the reported hashes against locally computed hash values, and reports an error if they do not match.
The values are reported as comma separated tag=value
pairs, e.g. crc32c=AAAAAA==,md5=1B2M2Y8AsgTpgAmY7PhCfg==
. The format of this string is subject to change without notice, they are provided for informational purposes only.
Definition at line 209 of file object_write_stream.h.
|
inline |
Returns the resumable upload session id for this upload.
Note that this is an empty string for uploads that do not use resumable upload session ids. Client::WriteObject()
enables resumable uploads based on the options set by the application.
Definition at line 255 of file object_write_stream.h.
void google::cloud::storage::ObjectWriteStream::Suspend | ( | ) | && |
Suspends an upload.
This is a destructive operation. Using this object after calling this function results in undefined behavior. Applications should copy any necessary state (such as the value resumable_session_id()
) before calling this function.
|
inline |
Definition at line 131 of file object_write_stream.h.