add set_stream_position/2

This commit is contained in:
Mark Thom
2020-05-09 14:20:32 -06:00
parent 034f5b16bd
commit 6f927b9941
5 changed files with 88 additions and 5 deletions

View File

@@ -27,6 +27,15 @@ impl StreamType {
#[inline]
pub(crate)
fn as_str(&self) -> &'static str {
match self {
StreamType::Binary => "binary_stream",
StreamType::Text => "text_stream",
}
}
#[inline]
pub(crate)
fn as_property_str(&self) -> &'static str {
match self {
StreamType::Binary => "binary",
StreamType::Text => "text",
@@ -296,6 +305,22 @@ impl Stream {
}
}
#[inline]
pub(crate)
fn set_position(&mut self, position: u64) {
match self.stream_inst.0.borrow_mut().deref_mut() {
(past_end_of_stream, StreamInstance::InputFile(_, ref mut file)) => {
file.seek(SeekFrom::Start(position)).unwrap();
if let Ok(metadata) = file.metadata() {
*past_end_of_stream = position > metadata.len();
}
}
_ => {
}
}
}
#[inline]
pub(crate)
fn past_end_of_stream(&self) -> bool {