Bitcoin Core  27.99.0
P2P Digital Currency
Public Member Functions | Private Attributes | List of all members
FlatFileSeq Class Reference

FlatFileSeq represents a sequence of numbered files storing raw data. More...

#include <flatfile.h>

Collaboration diagram for FlatFileSeq:
[legend]

Public Member Functions

 FlatFileSeq (fs::path dir, const char *prefix, size_t chunk_size)
 Constructor. More...
 
fs::path FileName (const FlatFilePos &pos) const
 Get the name of the file at the given position. More...
 
FILE * Open (const FlatFilePos &pos, bool read_only=false)
 Open a handle to the file at the given position. More...
 
size_t Allocate (const FlatFilePos &pos, size_t add_size, bool &out_of_space)
 Allocate additional space in a file after the given starting position. More...
 
bool Flush (const FlatFilePos &pos, bool finalize=false)
 Commit a file to disk, and optionally truncate off extra pre-allocated bytes if final. More...
 

Private Attributes

const fs::path m_dir
 
const char *const m_prefix
 
const size_t m_chunk_size
 

Detailed Description

FlatFileSeq represents a sequence of numbered files storing raw data.

This class facilitates access to and efficient management of these files.

Definition at line 45 of file flatfile.h.

Constructor & Destructor Documentation

◆ FlatFileSeq()

FlatFileSeq::FlatFileSeq ( fs::path  dir,
const char *  prefix,
size_t  chunk_size 
)

Constructor.

Parameters
dirThe base directory that all files live in.
prefixA short prefix given to all file names.
chunk_sizeDisk space is pre-allocated in multiples of this amount.

Definition at line 13 of file flatfile.cpp.

Member Function Documentation

◆ Allocate()

size_t FlatFileSeq::Allocate ( const FlatFilePos pos,
size_t  add_size,
bool &  out_of_space 
)

Allocate additional space in a file after the given starting position.

The amount allocated will be the minimum multiple of the sequence chunk size greater than add_size.

Parameters
[in]posThe starting position that bytes will be allocated after.
[in]add_sizeThe minimum number of bytes to be allocated.
[out]out_of_spaceWhether the allocation failed due to insufficient disk space.
Returns
The number of bytes successfully allocated.

Definition at line 55 of file flatfile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FileName()

fs::path FlatFileSeq::FileName ( const FlatFilePos pos) const

Get the name of the file at the given position.

Definition at line 28 of file flatfile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Flush()

bool FlatFileSeq::Flush ( const FlatFilePos pos,
bool  finalize = false 
)

Commit a file to disk, and optionally truncate off extra pre-allocated bytes if final.

Parameters
[in]posThe first unwritten position in the file to be flushed.
[in]finalizeTrue if no more data will be written to this file.
Returns
true on success, false on failure.

Definition at line 81 of file flatfile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Open()

FILE * FlatFileSeq::Open ( const FlatFilePos pos,
bool  read_only = false 
)

Open a handle to the file at the given position.

Definition at line 33 of file flatfile.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_chunk_size

const size_t FlatFileSeq::m_chunk_size
private

Definition at line 50 of file flatfile.h.

◆ m_dir

const fs::path FlatFileSeq::m_dir
private

Definition at line 48 of file flatfile.h.

◆ m_prefix

const char* const FlatFileSeq::m_prefix
private

Definition at line 49 of file flatfile.h.


The documentation for this class was generated from the following files: