aboutsummaryrefslogtreecommitdiff
path: root/zenstore/basicfile.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-21 20:40:09 +0200
committerStefan Boberg <[email protected]>2021-05-21 20:40:09 +0200
commit83e3c364e6403883cd60e7dda10165b6e84269f3 (patch)
treedc190b846bc73968988690880cdf1f5f8f6aaeb0 /zenstore/basicfile.cpp
parentMerge branch 'jupiter-structured' of https://github.com/EpicGames/zen into ju... (diff)
downloadzen-83e3c364e6403883cd60e7dda10165b6e84269f3.tar.xz
zen-83e3c364e6403883cd60e7dda10165b6e84269f3.zip
Moved CasBlobFile into basicfile.h
Diffstat (limited to 'zenstore/basicfile.cpp')
-rw-r--r--zenstore/basicfile.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp
new file mode 100644
index 000000000..961e43735
--- /dev/null
+++ b/zenstore/basicfile.cpp
@@ -0,0 +1,85 @@
+#include "zenstore/basicfile.h"
+
+#include <zencore/filesystem.h>
+#include <zencore/fmtutils.h>
+
+#include <fmt/format.h>
+#include <gsl/gsl-lite.hpp>
+
+namespace zen {
+
+using namespace fmt::literals;
+
+void
+CasBlobFile::Open(std::filesystem::path FileName, bool isCreate)
+{
+ const DWORD dwCreationDisposition = isCreate ? CREATE_ALWAYS : OPEN_EXISTING;
+
+ HRESULT hRes = m_File.Create(FileName.c_str(), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, dwCreationDisposition);
+
+ if (FAILED(hRes))
+ {
+ throw std::system_error(GetLastError(), std::system_category(), "Failed to open bucket sobs file '{}'"_format(FileName));
+ }
+}
+
+void
+CasBlobFile::Read(void* Data, uint64_t Size, uint64_t Offset)
+{
+ OVERLAPPED Ovl{};
+
+ Ovl.Offset = DWORD(Offset & 0xffff'ffffu);
+ Ovl.OffsetHigh = DWORD(Offset >> 32);
+
+ HRESULT hRes = m_File.Read(Data, gsl::narrow<DWORD>(Size), &Ovl);
+
+ if (FAILED(hRes))
+ {
+ throw std::system_error(GetLastError(),
+ std::system_category(),
+ "Failed to read from file '{}'"_format(zen::PathFromHandle(m_File)));
+ }
+}
+
+IoBuffer
+CasBlobFile::ReadAll()
+{
+ IoBuffer Buffer(FileSize());
+
+ Read((void*)Buffer.Data(), Buffer.Size(), 0);
+
+ return Buffer;
+}
+
+void
+CasBlobFile::Write(const void* Data, uint64_t Size, uint64_t Offset)
+{
+ OVERLAPPED Ovl{};
+
+ Ovl.Offset = DWORD(Offset & 0xffff'ffffu);
+ Ovl.OffsetHigh = DWORD(Offset >> 32);
+
+ HRESULT hRes = m_File.Write(Data, gsl::narrow<DWORD>(Size), &Ovl);
+
+ if (FAILED(hRes))
+ {
+ throw std::system_error(GetLastError(), std::system_category(), "Failed to write to file '{}'"_format(zen::PathFromHandle(m_File)));
+ }
+}
+
+void
+CasBlobFile::Flush()
+{
+ m_File.Flush();
+}
+
+uint64_t
+CasBlobFile::FileSize()
+{
+ ULONGLONG Sz;
+ m_File.GetSize(Sz);
+
+ return uint64_t(Sz);
+}
+
+}