diff options
| author | Stefan Boberg <[email protected]> | 2021-05-13 17:37:32 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-05-13 17:37:32 +0200 |
| commit | 5d46e91942d81f6ca4d12225757e633013408369 (patch) | |
| tree | d14316239f40078a91cba3d867dddc2b6bec6e2b /zencore/iobuffer.cpp | |
| parent | Added string_view variant of WindowsException constructor (diff) | |
| download | zen-5d46e91942d81f6ca4d12225757e633013408369.tar.xz zen-5d46e91942d81f6ca4d12225757e633013408369.zip | |
Implemented move-in-place for large CAS payloads
Diffstat (limited to 'zencore/iobuffer.cpp')
| -rw-r--r-- | zencore/iobuffer.cpp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/zencore/iobuffer.cpp b/zencore/iobuffer.cpp index ec5d599b4..e74287c48 100644 --- a/zencore/iobuffer.cpp +++ b/zencore/iobuffer.cpp @@ -332,6 +332,41 @@ IoBufferBuilder::MakeFromFile(const wchar_t* FileName, uint64_t Offset, uint64_t return {}; } +IoBuffer +IoBufferBuilder::MakeFromTemporaryFile(const wchar_t* FileName, uint64_t Offset, uint64_t Size) +{ + CAtlFile DataFile; + + // We need to open with DELETE since this is used for the case + // when a file has been written to a staging directory, and is going + // to be moved in place. + + HRESULT hRes = DataFile.Create(FileName, GENERIC_READ | DELETE, FILE_SHARE_READ | FILE_SHARE_DELETE, OPEN_EXISTING); + + if (SUCCEEDED(hRes)) + { + ULONGLONG FileSize; + DataFile.GetSize(FileSize); + + if (Size == ~0ull) + { + Size = FileSize; + } + else + { + // Clamp size + if ((Offset + Size) > FileSize) + { + Size = FileSize - Offset; + } + } + + return IoBuffer(IoBuffer::File, DataFile.Detach(), Offset, Size); + } + + return {}; +} + ////////////////////////////////////////////////////////////////////////// void |