Pixie
Loading...
Searching...
No Matches
pixie::io::FileOutputSink Class Reference

Move-only seekable sink for a newly created or truncated POSIX file. More...

#include <file_output_sink.h>

Public Member Functions

 FileOutputSink (const std::filesystem::path &path)
 Open path for binary output, creating or truncating it.
 
 FileOutputSink (const FileOutputSink &)=delete
 
FileOutputSinkoperator= (const FileOutputSink &)=delete
 
 FileOutputSink (FileOutputSink &&other) noexcept
 Transfer ownership of an open output file.
 
FileOutputSinkoperator= (FileOutputSink &&other) noexcept
 Close the current file and transfer ownership from other.
 
 ~FileOutputSink ()
 Close the output file without reporting errors.
 
std::size_t size_bytes () const noexcept
 Return the number of bytes appended to the output.
 
void write (std::span< const std::byte > bytes)
 Append all bytes to the file.
 
void write_at (std::size_t position, std::span< const std::byte > bytes)
 Replace already-written bytes beginning at position.
 
void finish ()
 Close the file and report any close error.
 

Detailed Description

Move-only seekable sink for a newly created or truncated POSIX file.

Sequential writes use write(), while backpatches use pwrite() without changing the append position. finish() closes the descriptor and reports close errors, but does not provide durable fsync() semantics.

Constructor & Destructor Documentation

◆ FileOutputSink()

pixie::io::FileOutputSink::FileOutputSink ( const std::filesystem::path & path)
inlineexplicit

Open path for binary output, creating or truncating it.

Exceptions
std::system_errorif the file cannot be opened.

Member Function Documentation

◆ finish()

void pixie::io::FileOutputSink::finish ( )
inline

Close the file and report any close error.

This operation is idempotent after success.

Exceptions
std::system_errorif closing the file fails.

◆ write()

void pixie::io::FileOutputSink::write ( std::span< const std::byte > bytes)
inline

Append all bytes to the file.

Exceptions
std::system_errorfor an operating-system write failure.
std::length_errorif the resulting file offset is unsupported.
std::logic_errorif the sink is already finished.

◆ write_at()

void pixie::io::FileOutputSink::write_at ( std::size_t position,
std::span< const std::byte > bytes )
inline

Replace already-written bytes beginning at position.

Exceptions
std::out_of_rangeif the range is outside the written file.
std::system_errorfor an operating-system write failure.
std::length_errorif the file offset is unsupported.
std::logic_errorif the sink is already finished.

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