azure-core: Azure::Core::IO::BodyStream Class Reference
Andrew White
Published Feb 16, 2026
Used to read data to/from a service. More...
#include <body_stream.hpp>
Used to read data to/from a service.
| pure virtual |
Read portion of data into a buffer.
- Parameters
-
buffer Pointer to a first byte of the byte buffer to read the data into. count Size of the buffer to read the data into. context Azure::Core::Context so that operation can be cancelled.
- Returns
- Number of bytes read.
91 {
92 context.ThrowIfCancelled();
93 return OnRead(buffer, count, context);
94 };
◆ ReadToCount()
Read Azure::Core::IO::BodyStream into a buffer until the buffer is filled, or until the stream is read to end.
- Parameters
-
buffer Pointer to a first byte of the byte buffer to read the data into. count Size of the buffer to read the data into. context Azure::Core::Context so that operation can be cancelled.
- Returns
- Number of bytes read.
38 {
39 int64_t totalRead = 0;
40
41 for (;;)
42 {
43 int64_t readBytes = this->Read(buffer + totalRead, count - totalRead, context);44 totalRead += readBytes;
45
46 if (totalRead == count || readBytes == 0)
47 {
48 return totalRead;
49 }
50 }
51 }
◆ ReadToEnd()
Read Azure::Core::IO::BodyStream until the stream is read to end, allocating memory for the entirety of contents.
- Parameters
- Returns
- A vector of bytes containing the entirety of data read from the
body.
54 {
55 constexpr int64_t chunkSize = 1024 * 8;
56 auto buffer = std::vector<uint8_t>();
57
58 for (auto chunkNumber = 0;; chunkNumber++)
59 {
60 buffer.resize((static_cast<decltype(buffer)::size_type>(chunkNumber) + 1) * chunkSize);
61 int64_t readBytes
62 = this->ReadToCount(buffer.data() + (chunkNumber * chunkSize), chunkSize, context);63
64 if (readBytes < chunkSize)
65 {
66 buffer.resize(static_cast<size_t>((chunkNumber * chunkSize) + readBytes));
67 return buffer;
68 }
69 }
70 }
The documentation for this class was generated from the following files:
int64_t ReadToCount(uint8_t *buffer, int64_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:37
int64_t Read(uint8_t *buffer, int64_t count, Azure::Core::Context const &context=Azure::Core::Context())
Read portion of data into a buffer.
Definition: body_stream.hpp:87