Go to the documentation of this file.
13 #if defined(AZ_PLATFORM_POSIX)
27 namespace Azure {
namespace Core {
namespace IO {
69 "The specified BodyStream doesn't support Rewind which is required to guarantee fault "
70 "tolerance when retrying any operation. Consider creating a MemoryBodyStream or "
71 "FileBodyStream, which are rewindable.");
89 AZURE_ASSERT(buffer || count == 0);
92 return OnRead(buffer, count, context);
126 const uint8_t* m_data;
153 explicit MemoryBodyStream(
const uint8_t* data,
size_t length) : m_data(data), m_length(length)
155 AZURE_ASSERT(data || length == 0);
158 int64_t
Length()
const override {
return this->m_length; }
160 void Rewind()
override { m_offset = 0; }
163 namespace _internal {
168 class RandomAccessFileBodyStream final :
public BodyStream {
171 #if defined(AZ_PLATFORM_POSIX)
172 int m_fileDescriptor;
173 #elif defined(AZ_PLATFORM_WINDOWS)
176 int64_t m_baseOffset;
184 #if defined(AZ_PLATFORM_POSIX)
199 RandomAccessFileBodyStream(
int fileDescriptor, int64_t offset, int64_t length)
200 : m_fileDescriptor(fileDescriptor), m_baseOffset(offset), m_length(length), m_offset(0)
202 AZURE_ASSERT(fileDescriptor >= 0 && offset >= 0 && length >= 0);
205 RandomAccessFileBodyStream() : m_fileDescriptor(0), m_baseOffset(0), m_length(0), m_offset(0)
209 #elif defined(AZ_PLATFORM_WINDOWS)
224 RandomAccessFileBodyStream(
void* fileHandle, int64_t offset, int64_t length)
225 : m_filehandle(fileHandle), m_baseOffset(offset), m_length(length), m_offset(0)
227 AZURE_ASSERT(fileHandle && offset >= 0 && length >= 0);
230 RandomAccessFileBodyStream() : m_filehandle(NULL), m_baseOffset(0), m_length(0), m_offset(0)
236 void Rewind()
override { this->m_offset = 0; }
238 int64_t
Length()
const override {
return this->m_length; }
250 #if defined(AZ_PLATFORM_WINDOWS)
252 #elif defined(AZ_PLATFORM_POSIX)
253 int m_fileDescriptor;
256 std::unique_ptr<_internal::RandomAccessFileBodyStream> m_randomAccessFileBodyStream;
281 void Rewind()
override;
283 int64_t
Length()
const override;
293 int64_t m_bytesTransferred;
294 std::function<void(int64_t bytesTransferred)> m_callback;
312 std::function<
void(int64_t bytesTransferred)> callback);
314 void Rewind()
override;
316 int64_t
Length()
const override;
int64_t Length() const override
Get the length of the data.
Definition: body_stream.cpp:221
A concrete implementation of Azure::Core::IO::BodyStream that wraps another stream and reports progre...
Definition: body_stream.hpp:290
void ThrowIfCancelled() const
Checks if the context is cancelled.
Definition: context.hpp:248
int64_t Length() const override
Get the length of the data.
Definition: body_stream.cpp:193
Context for canceling long running operations.
Used to read data to/from a service.
Definition: body_stream.hpp:32
ProgressBodyStream(BodyStream &bodyStream, std::function< void(int64_t bytesTransferred)> callback)
Constructs ProgressBodyStream from a BodyStream.
Definition: body_stream.cpp:195
std::vector< uint8_t > ReadToEnd(Azure::Core::Context const &context=Azure::Core::Context())
Read Azure::Core::IO::BodyStream until the stream is read to end, allocating memory for the entirety ...
Definition: body_stream.cpp:62
Azure::Core::IO::BodyStream providing data from an initialized memory buffer.
Definition: body_stream.hpp:124
int64_t Length() const override
Get the length of the data.
Definition: body_stream.hpp:158
~FileBodyStream()
Closes the file and cleans up any resources.
Definition: body_stream.cpp:169
MemoryBodyStream(const uint8_t *data, size_t length)
Construct using buffer pointer and its size.
Definition: body_stream.hpp:153
MemoryBodyStream(std::vector< uint8_t > const &buffer)
Construct using vector of bytes.
Definition: body_stream.hpp:141
A concrete implementation of Azure::Core::IO::BodyStream used for reading data from a file.
Definition: body_stream.hpp:247
size_t Read(uint8_t *buffer, size_t count, Azure::Core::Context const &context=Azure::Core::Context())
Read portion of data into a buffer.
Definition: body_stream.hpp:84
Azure SDK abstractions.
Definition: azure_assert.hpp:55
virtual ~BodyStream()=default
Destructs BodyStream.
size_t ReadToCount(uint8_t *buffer, size_t count, Azure::Core::Context const &context=Azure::Core::Context())
Read Azure::Core::IO::BodyStream into a buffer until the buffer is filled, or until the stream is rea...
Definition: body_stream.cpp:44
virtual int64_t Length() const =0
Get the length of the data.
A context is a node within a tree that represents deadlines and key/value pairs.
Definition: context.hpp:45
FileBodyStream(const std::string &filename)
Constructs FileBodyStream from a file name.
Definition: body_stream.cpp:93