diff --git a/src/read_until_any.rs b/src/read_until_any.rs index d9fbddb..d186883 100644 --- a/src/read_until_any.rs +++ b/src/read_until_any.rs @@ -36,8 +36,6 @@ pub fn read_until_any( .position(|&b| delims.iter().any(|&d| d == b)) .map(|i| i + start_delims); - // println!("start_delims: {start_delims}, first_delim_index: {first_delim_index:?}"); - match first_delim_index { Some(i) => { buf.extend_from_slice(&available[..=i]); @@ -51,7 +49,17 @@ pub fn read_until_any( }; r.consume(used); read += used; - if done || used == 0 { + + if done { + return Ok(read); + } + + // Catch final trailing delimiters + if used == 0 && buf.iter().all(|&b| delims.iter().any(|&d| d == b)) { + return Ok(0); + } + + if used == 0 { return Ok(read); } } diff --git a/src/test.rs b/src/test.rs index 2e95ecf..fa5d201 100644 --- a/src/test.rs +++ b/src/test.rs @@ -676,3 +676,22 @@ fn test_stdout_interleaved_frames_fallback() -> anyhow::Result<()> { Ok(()) } + +/// Make sure consectuive new lines in logs don't result in empty events. +#[test] +fn test_no_empty_events() -> anyhow::Result<()> { + let empty_events = FfmpegCommand::new() + .testsrc() + .rawvideo() + .spawn()? + .iter()? + .filter(|event| match event { + FfmpegEvent::Log(_, msg) if msg.is_empty() => true, + _ => false, + }) + .count(); + + assert!(empty_events == 0); + + Ok(()) +}