pub mod checksum;
pub mod destination;
pub mod envelope;
pub mod format;
pub mod ops;
pub mod sink;
pub mod stream;
pub use envelope::{Applied, Envelope, Gap, Row, SCHEMA_VERSION};
pub use ops::{Filter, Pipeline};
pub use sink::write_line;
use std::io::Write;
pub struct Counted<W: Write> {
inner: W,
bytes: u64,
lines: u64,
}
impl<W: Write> Counted<W> {
pub const fn new(inner: W) -> Self {
Self {
inner,
bytes: 0,
lines: 0,
}
}
#[must_use]
pub const fn bytes(&self) -> u64 {
self.bytes
}
#[must_use]
pub const fn lines(&self) -> u64 {
self.lines
}
}
impl<W: Write> Write for Counted<W> {
fn write(&mut self, buffer: &[u8]) -> std::io::Result<usize> {
let written = self.inner.write(buffer)?;
let taken = &buffer[..written];
self.bytes += written as u64;
#[allow(clippy::naive_bytecount)]
{
self.lines += taken
.iter()
.filter(|byte| **byte == format::LINE_ENDING as u8)
.count() as u64;
}
Ok(written)
}
fn flush(&mut self) -> std::io::Result<()> {
self.inner.flush()
}
}