diff options
| author | Stefan Boberg <[email protected]> | 2021-09-19 23:17:44 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-19 23:17:44 +0200 |
| commit | fe068c76e0f38dabf80bff2730ff9c713763d707 (patch) | |
| tree | 03b0d149306691e8b69ecf322ead4290e9605ec7 /zenstore/basicfile.cpp | |
| parent | Changed so Windows also uses the portable std::mutex implementation and rewor... (diff) | |
| download | zen-fe068c76e0f38dabf80bff2730ff9c713763d707.tar.xz zen-fe068c76e0f38dabf80bff2730ff9c713763d707.zip | |
Added BasicFile::StreamFile helper function to support reading large files in a chunked fashion (will be using memory-mapped strategy in the future where it makes sense)
Diffstat (limited to 'zenstore/basicfile.cpp')
| -rw-r--r-- | zenstore/basicfile.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp index 75de638cf..126f2a8b3 100644 --- a/zenstore/basicfile.cpp +++ b/zenstore/basicfile.cpp @@ -96,6 +96,29 @@ BasicFile::ReadAll() } void +BasicFile::StreamFile(std::function<void(const void* Data, uint64_t Size)>&& ChunkFun) +{ + const uint64_t ChunkSize = 128 * 1024; + IoBuffer ReadBuffer{ChunkSize}; + void* BufferPtr = ReadBuffer.MutableData(); + + uint64_t RemainBytes = FileSize(); + uint64_t CurrentOffset = 0; + + while (RemainBytes) + { + const uint64_t ThisChunkBytes = zen::Min(ChunkSize, RemainBytes); + + Read(BufferPtr, ThisChunkBytes, CurrentOffset); + + ChunkFun(BufferPtr, ThisChunkBytes); + + CurrentOffset += ThisChunkBytes; + RemainBytes -= ThisChunkBytes; + } +} + +void BasicFile::Write(const void* Data, uint64_t Size, uint64_t Offset) { OVERLAPPED Ovl{}; |