Skip to content

Commit

Permalink
fix: Remove EOFNormalizer (#59)
Browse files Browse the repository at this point in the history
Closes #57
  • Loading branch information
fasterthanlime authored Jan 31, 2024
1 parent e211875 commit bb7a4c3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 43 deletions.
40 changes: 0 additions & 40 deletions src/reader/sync/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,43 +98,3 @@ impl io::Read for RawEntryReader {
res
}
}

/// Normalize EOF behavior for std::fs::File on Windows
/// (ie. makes it return Ok(0), not an OS-level I/O error)
/// Works for non-file Read impls, on non-Windows OSes too.
pub struct EOFNormalizer<R>
where
R: io::Read,
{
inner: R,
}

impl<R> EOFNormalizer<R>
where
R: io::Read,
{
pub fn new(inner: R) -> Self {
Self { inner }
}
}

impl<R> io::Read for EOFNormalizer<R>
where
R: io::Read,
{
#[inline]
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
#[cfg(windows)]
match self.inner.read(buf) {
Err(e) => match e.raw_os_error() {
// Windows error 38 = Reached end of file
Some(38) => Ok(0),
_ => Err(e),
},
x => x,
}

#[cfg(not(windows))]
self.inner.read(buf)
}
}
6 changes: 3 additions & 3 deletions src/reader/sync/entry_reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{
error::*,
format::*,
reader::sync::decoder::{Decoder, EOFNormalizer, RawEntryReader, StoreDecoder},
reader::sync::decoder::{Decoder, RawEntryReader, StoreDecoder},
transition,
};

Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct EntryReader<R>
where
R: io::Read,
{
rd: EOFNormalizer<R>,
rd: R,
eof: bool,
state: State,
inner: StoredEntryInner,
Expand Down Expand Up @@ -260,7 +260,7 @@ where
F: Fn(u64) -> R,
{
Self {
rd: EOFNormalizer::new(get_reader(entry.header_offset)),
rd: get_reader(entry.header_offset),
eof: false,
state: State::ReadLocalHeader {
buffer: Buffer::with_capacity(Self::DEFAULT_BUFFER_SIZE),
Expand Down

0 comments on commit bb7a4c3

Please sign in to comment.