43 void operator()( std::FILE* f )
const { std::fclose( f ); }
47 using FileHandle = std::unique_ptr<std::FILE, details::Close>;
50 class Error :
public std::runtime_error {
52 Error(
const std::filesystem::path&
path, std::string_view what,
int err = 0 );
53 const std::filesystem::path&
path()
const {
return m_path; }
87 const std::filesystem::path&
path()
const {
return m_path; }
91 void write(
const void* data, std::size_t
bytes );
110 explicit Reader( std::filesystem::path
path );
119 bool next( std::span<const char>& record );
125 std::size_t
read(
void* dest, std::size_t bytes );
const std::filesystem::path & path() const
std::filesystem::path m_path
Error(const std::filesystem::path &path, std::string_view what, int err=0)
std::size_t read(void *dest, std::size_t bytes)
std::vector< char > m_stored
const std::string & header() const
Reader & operator=(const Reader &)=delete
Reader(std::filesystem::path path)
Open path and validate the preamble.
bool next(std::span< const char > &record)
Read the next record; false at a clean end of file. A partial block throws.
std::uint64_t entries() const
const std::filesystem::path & path() const
std::vector< char > m_block
Reader(const Reader &)=delete
std::filesystem::path m_path
Writer(std::filesystem::path path, std::string_view header, int zstdLevel=0, std::size_t blockSize=64 *1024)
Create (truncating) path and write the preamble and header.
void write(const void *data, std::size_t bytes)
void append(const void *data, std::size_t bytes)
std::uint64_t storedBytes() const
Bytes written to the file after the header.
std::uint64_t m_pendingBytes
std::size_t m_recordStart
const std::filesystem::path & path() const
std::filesystem::path m_path
std::vector< char > m_buf
std::size_t blockSize() const
Writer & operator=(const Writer &)=delete
void close()
Flush and close; throws on failure. Safe to call twice.
Writer(const Writer &)=delete
std::uint64_t bytes() const
Payload bytes of those records.
std::uint64_t entries() const
Records written to the file; records lost to a failed flush do not count.
Append-only file of length-prefixed records, used to park ntuple rows on disk during the event loop a...
bool zstdAvailable()
Whether this build can write and read compressed blocks.
std::unique_ptr< std::FILE, details::Close > FileHandle
Owns an open file; close() is the checked path, this is the fallback.
std::size_t maxBlockSize()
Largest block size a Writer accepts.
void operator()(std::FILE *f) const