-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
afd053c
commit 447b9e0
Showing
9 changed files
with
138 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ mod headers; | |
mod package; | ||
|
||
pub mod signature; | ||
mod skip_reader; | ||
|
||
pub use headers::*; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use std::io; | ||
use std::io::SeekFrom; | ||
|
||
pub struct SkipReader<R> { | ||
reader: R, | ||
start_pos: u64, | ||
} | ||
|
||
impl<R: io::Read + io::Seek> SkipReader<R> { | ||
pub(crate) fn new(mut reader: R) -> io::Result<Self> { | ||
let start_pos = reader.stream_position()?; | ||
Ok(Self { reader, start_pos }) | ||
} | ||
} | ||
|
||
impl<R: io::Seek> io::Seek for SkipReader<R> { | ||
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { | ||
match pos { | ||
SeekFrom::Start(p) => self.reader.seek(SeekFrom::Start(p + self.start_pos)), | ||
SeekFrom::Current(p) => self | ||
.reader | ||
.seek(SeekFrom::Current(p + self.start_pos as i64)), | ||
SeekFrom::End(p) => self | ||
.reader | ||
.seek(SeekFrom::Current(p + self.start_pos as i64)), | ||
} | ||
} | ||
} | ||
|
||
impl<R: io::Read> io::Read for SkipReader<R> { | ||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | ||
self.reader.read(buf) | ||
} | ||
} | ||
|
||
impl<R: io::BufRead> io::BufRead for SkipReader<R> { | ||
fn fill_buf(&mut self) -> io::Result<&[u8]> { | ||
self.reader.fill_buf() | ||
} | ||
|
||
fn consume(&mut self, amt: usize) { | ||
self.reader.consume(amt) | ||
} | ||
} |
Oops, something went wrong.