file tweaks

This commit is contained in:
Quaternions 2024-07-25 10:48:04 -07:00
parent f0035bcee9
commit b6935b4f5f
2 changed files with 5 additions and 2 deletions

View File

@ -84,6 +84,9 @@ impl<R:BinReaderExt> File<R>{
data:input, data:input,
}) })
} }
pub(crate) fn as_mut(&mut self)->&mut R{
&mut self.data
}
pub(crate) fn block_reader(&mut self,block_id:BlockId)->Result<binrw::io::TakeSeek<&mut R>,Error>{ pub(crate) fn block_reader(&mut self,block_id:BlockId)->Result<binrw::io::TakeSeek<&mut R>,Error>{
if self.header.block_location.len() as u32<=block_id.get(){ if self.header.block_location.len() as u32<=block_id.get(){
return Err(Error::InvalidBlockId(block_id)) return Err(Error::InvalidBlockId(block_id))
@ -91,7 +94,7 @@ impl<R:BinReaderExt> File<R>{
let block_start=self.header.block_location[block_id.get() as usize]; let block_start=self.header.block_location[block_id.get() as usize];
let block_end=self.header.block_location[block_id.get() as usize+1]; let block_end=self.header.block_location[block_id.get() as usize+1];
self.data.seek(std::io::SeekFrom::Start(block_start)).map_err(Error::Seek)?; self.data.seek(std::io::SeekFrom::Start(block_start)).map_err(Error::Seek)?;
Ok((&mut self.data).take_seek(block_end-block_start)) Ok(self.as_mut().take_seek(block_end-block_start))
} }
pub(crate) fn fourcc(&self)->FourCC{ pub(crate) fn fourcc(&self)->FourCC{
self.header.fourcc self.header.fourcc

View File

@ -2,7 +2,7 @@ use binrw::BinReaderExt;
mod newtypes; mod newtypes;
pub mod file; mod file;
pub mod map; pub mod map;
pub mod bot; pub mod bot;
pub mod demo; pub mod demo;