mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-14 03:30:02 +00:00
feat(core): introduce skip function for UzlibContext
[no changelog]
This commit is contained in:
parent
9575c81bd3
commit
a1165d9326
@ -40,7 +40,7 @@ impl<'a> UzlibContext<'a> {
|
||||
ctx
|
||||
}
|
||||
|
||||
/// returns Ok(true) if DONE
|
||||
/// Returns `Ok(true)` if all data was read.
|
||||
pub fn uncompress(&mut self, dest_buf: &mut [u8]) -> Result<bool, ()> {
|
||||
unsafe {
|
||||
self.uncomp.dest = dest_buf.as_mut_ptr();
|
||||
@ -55,4 +55,18 @@ impl<'a> UzlibContext<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Skips a specified number of bytes (`nbytes`) in the uncompressed stream.
|
||||
///
|
||||
/// Returns `Ok(true)` if all data was read.
|
||||
pub fn skip(&mut self, nbytes: usize) -> Result<bool, ()> {
|
||||
let mut result = false; // false => OK, true => DONE
|
||||
let mut sink = [0u8; 256];
|
||||
for i in (0..nbytes).step_by(sink.len()) {
|
||||
let chunk_len = core::cmp::min(sink.len(), nbytes - i);
|
||||
let chunk = &mut sink[0..chunk_len];
|
||||
result = self.uncompress(chunk)?;
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user