From 293a4d89654c67ef140aa588c92fcc634215a800 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Wed, 10 Jun 2026 12:18:48 +0300 Subject: Skip placeholder for binary files by default --- src/renderer.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/renderer.rs b/src/renderer.rs index f492f1e..c747df5 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -17,6 +17,7 @@ pub struct Renderer { output: W, max_file_size: u64, logger: Logger, + placeholder_for_binary_files: bool, } impl Renderer { @@ -25,6 +26,7 @@ impl Renderer { output, max_file_size: DEFAULT_MAX_FILE_SIZE, logger: Logger::default(), + placeholder_for_binary_files: false, } } @@ -38,6 +40,11 @@ impl Renderer { self } + pub fn with_binary_file_placeholder(mut self, placeholder_for_binary_files: bool) -> Self { + self.placeholder_for_binary_files = placeholder_for_binary_files; + self + } + pub fn render_header(&mut self, project_title: &str) -> std::io::Result<()> { writeln!(self.output, "# {}", project_title) } @@ -85,6 +92,9 @@ impl Renderer { } fn render_binary_file(&mut self, filename: &Path) -> std::io::Result<()> { + if !self.placeholder_for_binary_files { + return Ok(()); + } let name = display_path(filename); writeln!(self.output)?; writeln!(self.output, "## File: {}", name)?; @@ -184,10 +194,22 @@ mod tests { } #[test] - fn renderer_places_a_placeholder_for_binary_files_by_default() { + fn binary_files_are_not_included_in_output_at_all_by_default() { let mut output = Vec::new(); let mut renderer = Renderer::new(&mut output); + let input = Cursor::new(&[0x00, 0x01, 0x02, 0xc3]); + renderer.render_file(Path::new("image.png"), input).unwrap(); + let expected = ""; + + assert_eq!(String::from_utf8(output).unwrap(), expected); + } + + #[test] + fn renderer_can_place_a_placeholder_for_binary_files() { + let mut output = Vec::new(); + let mut renderer = Renderer::new(&mut output).with_binary_file_placeholder(true); + let input = Cursor::new(&[0x00, 0x01, 0x02, 0xc3]); renderer.render_file(Path::new("image.png"), input).unwrap(); let expected = "\n## File: image.png\n[BINARY FILE]\n"; -- cgit v1.3.1