2016-10-08 06:20:49 +00:00
|
|
|
use std::io::{BufRead, Read, Cursor, BufReader};
|
|
|
|
|
|
|
|
pub struct Data {
|
2016-10-09 04:37:28 +00:00
|
|
|
buffer: Vec<u8>,
|
2016-10-08 06:20:49 +00:00
|
|
|
stream: Cursor<Vec<u8>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Data {
|
2016-10-09 03:53:04 +00:00
|
|
|
pub fn open(self) -> impl BufRead {
|
2016-10-08 06:20:49 +00:00
|
|
|
Cursor::new(self.buffer).chain(BufReader::new(self.stream))
|
|
|
|
}
|
|
|
|
|
2016-10-09 03:53:04 +00:00
|
|
|
pub fn peek(&self) -> &[u8] {
|
2016-10-08 06:20:49 +00:00
|
|
|
&self.buffer
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn new() -> Data {
|
|
|
|
Data {
|
|
|
|
stream: Cursor::new(vec![]),
|
|
|
|
buffer: vec![]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|