use std::io::{self, Write};
use super::AnnotationFileChecksumOverrides;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum AnnotationFileProgressStage {
Sorting,
Compressing,
BuildingIndex,
}
pub struct AnnotationFileAddOptions<'a> {
pub checksum_overrides: AnnotationFileChecksumOverrides,
pub progress: Option<&'a mut dyn FnMut(AnnotationFileProgressStage)>,
}
pub(super) fn report_annotation_file_progress(
progress: &mut Option<&mut dyn FnMut(AnnotationFileProgressStage)>,
stage: AnnotationFileProgressStage,
) {
if let Some(callback) = progress.as_mut() {
callback(stage);
}
}
pub(super) struct ReportCompressionOnFirstWrite<W, F> {
writer: W,
on_first_write: Option<F>,
}
impl<W, F> ReportCompressionOnFirstWrite<W, F> {
pub(super) fn new(writer: W, on_first_write: F) -> Self {
Self {
writer,
on_first_write: Some(on_first_write),
}
}
}
impl<W: Write, F: FnMut()> Write for ReportCompressionOnFirstWrite<W, F> {
fn write(&mut self, buffer: &[u8]) -> io::Result<usize> {
if !buffer.is_empty()
&& let Some(mut on_first_write) = self.on_first_write.take()
{
on_first_write();
}
self.writer.write(buffer)
}
fn flush(&mut self) -> io::Result<()> {
self.writer.flush()
}
}