diff options
| author | Stefan Boberg <[email protected]> | 2023-06-30 10:36:27 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2023-06-30 10:36:27 +0200 |
| commit | 5a0f7888f368330fa80e5cd648a576c0a4eb04f7 (patch) | |
| tree | 6903c287d39bdf6e57ce03d89a2c85fa0c2e0b73 /src/zenutil/include | |
| parent | README.md update - merge from sb/proto (diff) | |
| download | zen-5a0f7888f368330fa80e5cd648a576c0a4eb04f7.tar.xz zen-5a0f7888f368330fa80e5cd648a576c0a4eb04f7.zip | |
* added file sharing control to BasicFile (required to implement lockfiles)
* added delete-on-close support to BasicFile
* added BasicFile::ReadRange()
Diffstat (limited to 'src/zenutil/include')
| -rw-r--r-- | src/zenutil/include/zenutil/basicfile.h | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/zenutil/include/zenutil/basicfile.h b/src/zenutil/include/zenutil/basicfile.h index 877df0f92..1c5a31c5c 100644 --- a/src/zenutil/include/zenutil/basicfile.h +++ b/src/zenutil/include/zenutil/basicfile.h @@ -2,6 +2,10 @@ #pragma once +#include <zencore/zencore.h> + +#include <zencore/compositebuffer.h> +#include <zencore/enumflags.h> #include <zencore/iobuffer.h> #include <filesystem> @@ -36,25 +40,31 @@ public: kTruncate = 2, // Opens (or creates) a file for read and write and sets the size to zero kDelete = 3, // Opens (or creates) a file for read and write allowing .DeleteFile file disposition to be set kTruncateDelete = - 4 // Opens (or creates) a file for read and write and sets the size to zero allowing .DeleteFile file disposition to be set + 4, // Opens (or creates) a file for read and write and sets the size to zero allowing .DeleteFile file disposition to be set + kModeMask = 0x0007, + kPreventDelete = 0x1000'0000, // Do not open with delete sharing mode (prevent other processes from deleting file while open) + kPreventWrite = 0x2000'0000, // Do not open with write sharing mode (prevent other processes from writing to file while open) + kDeleteOnClose = 0x4000'0000, // File should be deleted when the last handle is closed }; void Open(const std::filesystem::path& FileName, Mode Mode); void Open(const std::filesystem::path& FileName, Mode Mode, std::error_code& Ec); void Close(); void Read(void* Data, uint64_t Size, uint64_t FileOffset); + IoBuffer ReadRange(uint64_t FileOffset, uint64_t ByteCount); void StreamFile(std::function<void(const void* Data, uint64_t Size)>&& ChunkFun); void StreamByteRange(uint64_t FileOffset, uint64_t Size, std::function<void(const void* Data, uint64_t Size)>&& ChunkFun); void Write(MemoryView Data, uint64_t FileOffset); void Write(MemoryView Data, uint64_t FileOffset, std::error_code& Ec); + uint64_t Write(CompositeBuffer Data, uint64_t FileOffset, std::error_code& Ec); void Write(const void* Data, uint64_t Size, uint64_t FileOffset); void Write(const void* Data, uint64_t Size, uint64_t FileOffset, std::error_code& Ec); void Flush(); - uint64_t FileSize(); - void SetFileSize(uint64_t FileSize); - IoBuffer ReadAll(); - void WriteAll(IoBuffer Data, std::error_code& Ec); - void* Detach(); + [[nodiscard]] uint64_t FileSize(); + void SetFileSize(uint64_t FileSize); + IoBuffer ReadAll(); + void WriteAll(IoBuffer Data, std::error_code& Ec); + void* Detach(); inline void* Handle() { return m_FileHandle; } @@ -63,6 +73,8 @@ protected: private: }; +ENUM_CLASS_FLAGS(BasicFile::Mode); + /** * Simple abstraction for a temporary file * |