pub struct FileSink<W: Write> { /* private fields */ }std only.Expand description
Append-only file-backed Sink.
Wraps any W: io::Write and serialises records through the stable
crate::codec. The format header is written exactly once, by
FileSink::open_or_create when the target file is empty.
Writes are not auto-flushed. Call FileSink::flush (or wrap the
inner writer in a BufWriter and rely on Drop) at appropriate
checkpoints — a typical pattern is flushing after every append or
after every batch.
Implementations§
Source§impl FileSink<BufWriter<File>>
impl FileSink<BufWriter<File>>
Sourcepub fn open_or_create(path: impl AsRef<Path>) -> Result<Self>
Available on crate feature alloc only.
pub fn open_or_create(path: impl AsRef<Path>) -> Result<Self>
alloc only.Open path for append-only audit writes, creating it if absent.
On a freshly-created file this writes the format header. On an
existing file this validates the header and positions the writer
at end-of-file. The underlying File is wrapped in a
BufWriter.
§Errors
Surface I/O errors from opening, validating, or seeking the file.
A bad existing header is reported as
io::ErrorKind::InvalidData.
Source§impl<W: Write> FileSink<W>
impl<W: Write> FileSink<W>
Sourcepub fn new(writer: W) -> Self
Available on crate feature alloc only.
pub fn new(writer: W) -> Self
alloc only.Wrap an existing writer that is already positioned correctly (header already written, ready to append records).
Most callers want FileSink::open_or_create instead.
Sourcepub fn into_writer(self) -> W
Available on crate feature alloc only.
pub fn into_writer(self) -> W
alloc only.Consume the sink and return the underlying writer.