1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use std::{fs::File, io::BufWriter, path::PathBuf};

use csv::Writer;

use crate::CsvZipError;

/// This is a csv maker.
pub struct CsvMaker {
    pub(crate) writer: Writer<BufWriter<File>>,
    pub(crate) file_name: String,
    pub(crate) file_path: PathBuf,
}

impl CsvMaker {
    pub fn write<I>(&mut self, line: I) -> Result<(), CsvZipError>
    where
        I: IntoIterator,
        I::Item: AsRef<[u8]>,
    {
        self.writer.write_record(line).map_err(|e| e.into())
    }

    pub(crate) fn flush(&mut self) -> Result<(), CsvZipError> {
        self.writer.flush().map_err(|e| e.into())
    }
}