Read k bytes from the object and return.
(&mut self, bytes: Option<usize>)
| 297 | |
| 298 | //Read k bytes from the object and return. |
| 299 | fn read(&mut self, bytes: Option<usize>) -> Option<Vec<u8>> { |
| 300 | let pos = self.cursor.position().to_usize()?; |
| 301 | let avail_slice = self.cursor.get_ref().get(pos..)?; |
| 302 | // if we don't specify the number of bytes, or it's too big, give the whole rest of the slice |
| 303 | let n = bytes.map_or_else( |
| 304 | || avail_slice.len(), |
| 305 | |n| core::cmp::min(n, avail_slice.len()), |
| 306 | ); |
| 307 | let b = avail_slice[..n].to_vec(); |
| 308 | self.cursor.set_position((pos + n) as u64); |
| 309 | Some(b) |
| 310 | } |
| 311 | |
| 312 | const fn tell(&self) -> u64 { |
| 313 | self.cursor.position() |
no test coverage detected