Bitcoin
Public Member Functions | Private Attributes | List of all members
FlatFileSeq Class Reference

#include <flatfile.h>

Public Member Functions

 FlatFileSeq (fs::path dir, const char *prefix, size_t chunk_size)
 
fs::path FileName (const FlatFilePos &pos) const
 
FILE * Open (const FlatFilePos &pos, bool read_only=false)
 
size_t Allocate (const FlatFilePos &pos, size_t add_size, bool &out_of_space)
 
bool Flush (const FlatFilePos &pos, bool finalize=false)
 

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.

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.

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.

◆ FileName()

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

Get the name of the file at the given position.

◆ 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.

◆ Open()

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

Open a handle to the file at the given position.

Member Data Documentation

◆ m_chunk_size

const size_t FlatFileSeq::m_chunk_size
private

◆ m_dir

const fs::path FlatFileSeq::m_dir
private

◆ m_prefix

const char* const FlatFileSeq::m_prefix
private

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