* FlatFileSeq represents a sequence of numbered files storing raw data. This class facilitates * access to and efficient management of these files. */
| 44 | * access to and efficient management of these files. |
| 45 | */ |
| 46 | class FlatFileSeq |
| 47 | { |
| 48 | private: |
| 49 | const fs::path m_dir; |
| 50 | const char* const m_prefix; |
| 51 | const size_t m_chunk_size; |
| 52 | |
| 53 | public: |
| 54 | /** |
| 55 | * Constructor |
| 56 | * |
| 57 | * @param dir The base directory that all files live in. |
| 58 | * @param prefix A short prefix given to all file names. |
| 59 | * @param chunk_size Disk space is pre-allocated in multiples of this amount. |
| 60 | */ |
| 61 | FlatFileSeq(fs::path dir, const char* prefix, size_t chunk_size); |
| 62 | |
| 63 | /** Get the name of the file at the given position. */ |
| 64 | fs::path FileName(const FlatFilePos& pos) const; |
| 65 | |
| 66 | /** Open a handle to the file at the given position. */ |
| 67 | FILE* Open(const FlatFilePos& pos, bool read_only = false); |
| 68 | |
| 69 | /** |
| 70 | * Allocate additional space in a file after the given starting position. The amount allocated |
| 71 | * will be the minimum multiple of the sequence chunk size greater than add_size. |
| 72 | * |
| 73 | * @param[in] pos The starting position that bytes will be allocated after. |
| 74 | * @param[in] add_size The minimum number of bytes to be allocated. |
| 75 | * @param[out] out_of_space Whether the allocation failed due to insufficient disk space. |
| 76 | * @return The number of bytes successfully allocated. |
| 77 | */ |
| 78 | size_t Allocate(const FlatFilePos& pos, size_t add_size, bool& out_of_space); |
| 79 | |
| 80 | /** |
| 81 | * Commit a file to disk, and optionally truncate off extra pre-allocated bytes if final. |
| 82 | * |
| 83 | * @param[in] pos The first unwritten position in the file to be flushed. |
| 84 | * @param[in] finalize True if no more data will be written to this file. |
| 85 | * @return true on success, false on failure. |
| 86 | */ |
| 87 | bool Flush(const FlatFilePos& pos, bool finalize = false); |
| 88 | }; |
| 89 | |
| 90 | #endif // BITCOIN_FLATFILE_H |
no outgoing calls
no test coverage detected