33 return currentOffset + offset;
59 int64_t
Read(
void* buffer, int64_t
size)
override
69 : mStreamSize {
size }
71 if (copyData && data !=
nullptr && mStreamSize > 0)
74 std::copy_n(
static_cast<const uint8_t*
>(data),
size, std::back_inserter(mData));
75 mDataPointer = mData.data();
79 mDataPointer =
static_cast<const uint8_t*
>(data);
85 return mDataPointer !=
nullptr && mStreamSize > 0;
95 const auto requestedOffset =
CalculateOffset(mStreamPosition, offset, mStreamSize, direction);
97 if (requestedOffset < 0 || requestedOffset > mStreamSize)
100 mStreamPosition = requestedOffset;
106 const auto bytesToRead =
std::min(
size, mStreamSize - mStreamPosition);
108 if (bytesToRead <= 0)
111 std::copy_n(mDataPointer + mStreamPosition, bytesToRead,
static_cast<uint8_t*
>(buffer));
112 mStreamPosition += bytesToRead;
120 const uint8_t* mDataPointer {};
121 int64_t mStreamSize {};
123 int64_t mStreamPosition {};
131 , mFile { mFilePath }
133 wxStat(mFilePath, &mFileStat);
138 return mFile.IsOpened();
143 return mFileStat.st_size;
148 const auto platformSeekDirection = [&]
152 case SeekDirection::Start:
154 case SeekDirection::Current:
155 return wxFromCurrent;
156 case SeekDirection::End:
163 return mFile.Seek(offset, platformSeekDirection) != wxInvalidOffset;
168 return mFile.Read(buffer,
size);
186 return std::make_shared<MemoryRequestPayloadStream>(data,
size, copyData);
191 return std::make_shared<EmptyRequestPayloadStream>();
196 return std::make_shared<FileRequestPayloadStream>(filePath);
Declare functions to perform UTF-8 to std::wstring conversions.
Declare a class for constructing HTTP requests.
virtual ~RequestPayloadStream()
bool HasData() const override
return true on if stream is not empty
int64_t Read(void *buffer, int64_t size) override
returns number of bytes read
bool Seek(int64_t offset, SeekDirection direction) override
returns true on success
int64_t GetDataSize() const override
May return 0 even if HasData() returns true.
int64_t Read(void *buffer, int64_t size) override
returns number of bytes read
int64_t GetDataSize() const override
May return 0 even if HasData() returns true.
FileRequestPayloadStream(const std::string &filePath)
bool Seek(int64_t offset, SeekDirection direction) override
returns true on success
bool HasData() const override
return true on if stream is not empty
int64_t GetDataSize() const override
May return 0 even if HasData() returns true.
MemoryRequestPayloadStream(const void *data, int64_t size, bool copyData)
int64_t Read(void *buffer, int64_t size) override
returns number of bytes read
bool HasData() const override
return true on if stream is not empty
std::vector< uint8_t > mData
bool Seek(int64_t offset, SeekDirection direction) override
returns true on success
int64_t CalculateOffset(int64_t currentOffset, int64_t offset, int64_t size, RequestPayloadStream::SeekDirection direction)
std::shared_ptr< RequestPayloadStream > RequestPayloadStreamPtr
RequestPayloadStreamPtr CreateRequestPayloadStream(const void *data, int64_t size, bool copyData)
wxString ToWXString(const std::string &str)