This commit is contained in:
2025-09-28 21:18:45 -07:00
parent 1c3c400828
commit f8e53c7dfd

View File

@@ -396,6 +396,8 @@ impl Block{
block.extend_from_reader_exact(data)?;
Ok(block)
}
/// Read a complete data block and append the elements to the timelines in this block.
/// Reserves exactly enough information for the new data.
pub fn extend_from_reader_exact<R:BinReaderExt>(&mut self,mut data:R)->binrw::BinResult<()>{
// well... this looks error prone
while let Ok(event_chunk_header)=data.read_le::<EventChunkHeader>(){
@@ -412,6 +414,7 @@ impl Block{
}
Ok(())
}
/// Read a complete data block and append the elements to the timelines in this block.
pub fn extend_from_reader<R:BinReaderExt>(&mut self,mut data:R)->binrw::BinResult<()>{
// sad code duplication
while let Ok(event_chunk_header)=data.read_le::<EventChunkHeader>(){
@@ -521,12 +524,15 @@ impl BlockInfo{
pub fn length(&self)->u32{
self.length
}
/// Create an adapter which seeks to the block start and reads at most the block length.
pub fn take_seek<R:BinReaderExt>(&self,mut data:R)->Result<TakeSeek<R>,IoError>{
data.seek(SeekFrom::Start(self.start() as u64))?;
Ok(data.take_seek(self.length() as u64))
}
}
/// Read the entire file and combine the timelines into a single Block.
/// Note that this reads the blocks in chronological order, not the order they appear in the file, so there is some seeking involved.
#[cfg(feature="itertools")]
pub fn read_all_to_block<R:BinReaderExt>(mut data:R)->Result<Block,Error>{
let header=FileHeader::from_reader(&mut data).map_err(Error::InvalidData)?;