Switchboard SDK
Loading...
Searching...
No Matches
switchboard::FileWriter Class Reference

Writes a file to the file system. More...

#include <FileWriter.hpp>

Public Member Functions

 FileWriter (const std::string &filePath, bool allowOverwrite=true)
 Tries to create FileWriter by opening an output stream. Throws std::runtime_error if could not open file.
 
 ~FileWriter ()
 FileWriter destructor.
 
 FileWriter (const FileWriter &)=delete
 
bool write (const int8 *buffer, const uint64 size) noexcept
 Writes content of buffer in the destination file.
 
bool write (const std::vector< int8 > &buffer) noexcept
 Writes content of buffer in the destination file.
 

Static Public Member Functions

static const bool write (const std::string filePath, const int8 *buffer, const uint64 size)
 Writes contents of input buffer to a file at filePath.
 

Detailed Description

Writes a file to the file system.

FileWriter class for writing raw data to a file.

Resource acquisition happens when constructing FileWriter. Destruction ensures that the file is closed.

Reading from the file can happen after closing it (destructing FileWriter, by scoping it, calling reset on a unique_ptr, etc.).

Constructor & Destructor Documentation

◆ FileWriter()

switchboard::FileWriter::FileWriter ( const std::string & filePath,
bool allowOverwrite = true )

Tries to create FileWriter by opening an output stream. Throws std::runtime_error if could not open file.

Parameters
filePathDestination file path.
allowOverwriteIndicates if only non-existent file should be opened. If this is false and there is already a file at filePath, throw std::runtime_error.

Member Function Documentation

◆ write() [1/3]

bool switchboard::FileWriter::write ( const int8 * buffer,
const uint64 size )
noexcept

Writes content of buffer in the destination file.

Parameters
bufferRaw data buffer.
sizeSize of the raw data buffer.
Returns
True if write is successful, false otherwise.

◆ write() [2/3]

const bool switchboard::FileWriter::write ( const std::string filePath,
const int8 * buffer,
const uint64 size )
static

Writes contents of input buffer to a file at filePath.

Parameters
filePathPath of the file to write to.
bufferBuffer with the input data.
sizeSize of the input buffer in bytes.
Returns
True if the data was written successfully, false otherwise.

◆ write() [3/3]

bool switchboard::FileWriter::write ( const std::vector< int8 > & buffer)
noexcept

Writes content of buffer in the destination file.

Parameters
bufferRaw data vector.
Returns
True if write is successful, false otherwise.