1use std::fs::{self, File};
2use std::io::{self, Write};
3use std::path::PathBuf;
4use std::sync::mpsc;
5
6pub fn process_files(
8 rx: mpsc::Receiver<PathBuf>,
9 output_file_path: &PathBuf,
10) -> anyhow::Result<()> {
11 let mut output_file = File::create(output_file_path)?;
12
13 for path in rx {
14 match fs::read(&path) {
15 Ok(contents) => {
16 if contents.contains(&0) {
18 println!("Skipping binary file: {}", path.display());
19 continue;
20 }
21
22 writeln!(output_file, "// FILE: {}", path.display())?;
24 output_file.write_all(&contents)?;
25 writeln!(output_file)?;
26 }
27 Err(e) => {
28 if e.kind() != io::ErrorKind::InvalidData {
30 eprintln!("Failed to read file {}: {}", path.display(), e);
31 }
32 }
33 }
34 }
35
36 Ok(())
37}