MCPcopy Create free account
hub / github.com/ddd/gpb / initialize_csv_output

Function initialize_csv_output

src/csv/parser.rs:65–84  ·  view source on GitHub ↗

Initialize CSV output file with header

(file_path: &str)

Source from the content-addressed store, hash-verified

63
64// Initialize CSV output file with header
65pub async fn initialize_csv_output(file_path: &str) -> Result<(), Error> {
66 let file = File::create(file_path).await?;
67 let mut writer = BufWriter::new(file);
68
69 // Create a CSV writer
70 let mut csv_writer = csv::WriterBuilder::new()
71 .from_writer(vec![]);
72
73 // Write header using the CsvHit struct field names
74 csv_writer.write_record(&["identifier", "phone", "firstname", "lastname"])?;
75
76 // Get the CSV content as bytes
77 let csv_content = csv_writer.into_inner()?;
78
79 // Write to file
80 writer.write_all(&csv_content).await?;
81 writer.flush().await?;
82
83 Ok(())
84}
85
86// Append a hit to the CSV output file
87pub async fn append_csv_hit(file_path: &str, hit: &CsvHit) -> Result<(), Error> {

Callers 1

process_csv_modeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected