use crate::{
backends::{MmapMosaicBackend, MosaicBackend},
Position,
};
use anyhow::Result;
use std::path::Path;
pub fn ebml_dump(filename: &Path, from: Option<usize>, to: Option<usize>) -> Result<()> {
let mut offset = Position(0);
let backend = MmapMosaicBackend::new(filename)?;
let mut indentation = String::from("");
let mut unindent_offsets = Vec::<Position>::new();
let width = to.unwrap_or(backend.len()).to_string().len();
while let Ok((tag, size, next_offset)) = backend.read_one_tag_and_size(offset) {
if offset >= from.unwrap_or(0) {
println!("{: >w$?} {}{:?}", offset.0, indentation, tag, w = width);
}
if tag.is_master() {
offset = next_offset;
unindent_offsets.push(offset + size);
indentation.push_str(" ");
} else {
offset = next_offset + size;
}
if let Some(o) = unindent_offsets.last() {
if *o == offset {
indentation.truncate(indentation.len() - 4);
}
}
if let Some(maximum) = to {
if offset >= maximum {
break;
}
}
}
Ok(())
}