userver: userver/fs/blocking/c_file.hpp Source File
Loading...
Searching...
No Matches
c_file.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <cstdint>
7#include <cstdio>
8#include <filesystem>
9#include <span>
10#include <string_view>
11
15
16USERVER_NAMESPACE_BEGIN
17
18namespace fs::blocking {
19
25class CFile final {
26public:
29
30 CFile(CFile&&) noexcept;
31 CFile& operator=(CFile&&) noexcept;
32 ~CFile();
33
37 utils::zstring_view path,
38 OpenMode flags,
39 std::filesystem::perms perms = std::filesystem::perms::owner_read | std::filesystem::perms::owner_write
40 );
41
43 explicit CFile(std::FILE* file) noexcept;
44
46 bool IsOpen() const noexcept;
47
49 std::FILE* GetNative() &;
50
52 std::FILE* Release() &&;
53
56 void Close() &&;
57
62 std::size_t Read(std::span<char> buffer);
63
68 void Write(std::string_view data);
69
72 void Flush();
73
77 void FlushLight();
78
81 std::uint64_t GetPosition() const;
82
85 std::uint64_t GetSize() const;
86
87private:
88 struct Impl;
89 utils::FastPimpl<Impl, sizeof(char*), alignof(char*)> impl_;
90};
91
92} // namespace fs::blocking
93
94USERVER_NAMESPACE_END