//! A split racing with stop can leave only a Matroska header, with no footage. use std::{ fs::File, io::{self, Read}, path::Path, }; /// The pinned muxer writes its first Cluster immediately after a small header. /// Inspect only that prefix, so checking a completed segment never reads its footage. pub fn has_cluster(path: &Path) -> io::Result { cluster_in(File::open(path)?) } fn cluster_in(reader: impl Read) -> io::Result { let mut prefix = Vec::new(); reader.take(64 * 1024).read_to_end(&mut prefix)?; Ok(prefix.windows(4).any(|id| id == [0x1f, 0x43, 0xb6, 0x75])) } #[cfg(test)] mod tests { use super::*; #[test] fn distinguishes_a_header_only_tail_from_media() { let header = [0x1a, 0x45, 0xdf, 0xa3, 0x80, 0x18, 0x53, 0x80, 0x67, 0xff]; assert!(!cluster_in(header.as_slice()).unwrap()); let mut media = header.to_vec(); media.extend([0x1f, 0x43, 0xb6, 0x75, 0x84, 0xe7, 0x82, 0, 0]); assert!(cluster_in(media.as_slice()).unwrap()); } }