22#define FILEPREFIX "/tmp/lefthookroll_"
23#define BUFFERLIMIT 1024 * 1024
50 void append(
const char* data,
size_t length);
55 void append(
const std::string& data);
73 const std::vector<char>&
getVector()
const;
99 size_t read(
char* buffer,
size_t length);
143 void write_all(
int fd,
const char* data,
size_t length);
148 void copy_fd_contents(
const std::string& srcPath,
int dstFd,
size_t totalBytes);
BufferMode
Indicates where the data is currently being stored.
size_t getReadPosition() const
Gets the current read position.
void copy_fd_contents(const std::string &srcPath, int dstFd, size_t totalBytes)
Copies data directly from one FD to another using a buffer.
std::string _absolutePath
int getFd() const
Returns the file descriptor of the temporary file.
const std::vector< char > & getVector() const
Returns a reference to the RAM buffer.
std::string getFilePath() const
Gets the absolute path of the temporary file.
void _generateTempFileName()
Generates a unique temporary filename (e.g., FILEPREFIX_XXXXXX).
size_t getSize() const
Gets total bytes currently stored (whether in RAM or File).
std::vector< char > _dataBuffer
void append(const char *data, size_t length)
Appends raw byte data to the store. Automatically transitions from RAM to FILE_MODE if _bufferLimit i...
void switchToFileMode()
Handles the transition from RAM to a temporary file on disk. Uses the immediate unlink() trick to ens...
void resetReadPosition()
Resets the internal read position to the beginning of the data.
void write_all(int fd, const char *data, size_t length)
Ensures all data is written to the file descriptor.
size_t read(char *buffer, size_t length)
Reads data from the store starting at the current read position. Advances the internal read position ...
DataStore & operator=(DataStore other)
void clear()
Resets the store, clears the vector, and closes the temp file descriptor.
BufferMode getMode() const
Returns the current storage mode (RAM or FILE_MODE).