bufstreamreader

This struct provides a buffered access to a Read object with a limited Seek implementation.

Seeking is limited by the following constraints:

Seeking backward as possible as far as there are data in the current buffer

```rust use std::io::{Cursor, Read, Seek, SeekFrom}; use bufstreamreader::BufStreamReader; let cursor = Cursor::new(&arr); // points to array with values from \x00 .. \xff let mut reader = BufStreamReader::new(cursor, 16).unwrap();

let mut buffer: [u8; 7] = [0; 7];

/* straightly reading 7 bytes works */ asserteq!(reader.read(&mut buffer).unwrap(), buffer.len()); asserteq!(&buffer, &arr[0..7]);

/* seeking backwards inside the current buffer */ assert!(reader.seek(SeekFrom::Current(-4)).isok()); asserteq!(reader.read(&mut buffer).unwrap(), 7); assert_eq!(&buffer, &arr[3..10]); ```

Seeking backwards is not possible if the destination is not within of behind the current buffer

```rust let cursor = Cursor::new(&arr); // points to array with values from \x00 .. \xff let mut reader = BufStreamReader::new(cursor, 16).unwrap();

let mut buffer: [u8; 7] = [0; 7]; assert!(reader.seek(SeekFrom::Start(96)).isok()); assert!(reader.seek(SeekFrom::Start(95)).iserr()); assert!(reader.seek(SeekFrom::Current(-1)).is_err()); ```

Seeking forward is not limited, as well as reading beyond buffer limits (as far as data is available, of course)

```rust let cursor = Cursor::new(&arr); // points to array with values from \x00 .. \xff let mut reader = BufStreamReader::new(cursor, 16).unwrap();

let mut buffer: [u8; 7] = [0; 7]; assert!(reader.seek(SeekFrom::Start(10)).isok()); asserteq!(reader.read(&mut buffer).unwrap(), buffer.len()); assert_eq!(&buffer, &arr[10..17]);

assert!(reader.seek(SeekFrom::Current(122)).isok()); asserteq!(reader.read(&mut buffer).unwrap(), buffer.len()); assert_eq!(&buffer, &arr[139..146]); ```