Skip to content

Commit

Permalink
replace try! with ?
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Jul 26, 2018
1 parent 903877f commit cf45702
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/gz/bufread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ fn copy(into: &mut [u8], from: &[u8], pos: &mut usize) -> usize {
*pos += min;
return min;
}
pub fn corrupt() -> io::Error {

pub(crate) fn corrupt() -> io::Error {
io::Error::new(
io::ErrorKind::InvalidInput,
"corrupt gzip stream does not have a matching checksum",
Expand All @@ -34,7 +35,7 @@ fn read_le_u16<R: Read>(r: &mut R) -> io::Result<u16> {
Ok((b[0] as u16) | ((b[1] as u16) << 8))
}

pub fn read_gz_header<R: Read>(r: &mut R) -> io::Result<GzHeader> {
pub(crate) fn read_gz_header<R: Read>(r: &mut R) -> io::Result<GzHeader> {
let mut crc_reader = CrcReader::new(r);
let mut header = [0; 10];
crc_reader.read_exact(&mut header)?;
Expand Down
10 changes: 5 additions & 5 deletions src/gz/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl<W: Write> GzDecoder<W> {
/// This function will perform I/O to finish the stream, returning any
/// errors which happen.
pub fn try_finish(&mut self) -> io::Result<()> {
try!(self.finish_and_check_crc());
self.finish_and_check_crc()?;
Ok(())
}

Expand All @@ -293,12 +293,12 @@ impl<W: Write> GzDecoder<W> {
/// This function will perform I/O to complete this stream, and any I/O
/// errors which occur will be returned from this function.
pub fn finish(mut self) -> io::Result<W> {
try!(self.finish_and_check_crc());
self.finish_and_check_crc()?;
Ok(self.inner.take_inner().into_inner())
}

fn finish_and_check_crc(&mut self) -> io::Result<()> {
try!(self.inner.finish());
self.inner.finish()?;

if self.crc_bytes.len() != 8 {
return Err(corrupt());
Expand All @@ -322,7 +322,7 @@ impl<W: Write> GzDecoder<W> {
}

fn write_buf(&mut self, buf: &[u8]) -> io::Result<usize> {
let (n, status) = try!(self.inner.write_with_status(buf));
let (n, status) = self.inner.write_with_status(buf)?;

if status == Status::StreamEnd {
if n < buf.len() && self.crc_bytes.len() < 8 {
Expand Down Expand Up @@ -403,7 +403,7 @@ impl<W: Write> Write for GzDecoder<W> {
Ok(header) => {
self.header = Some(header);
self.header_buf.truncate(0);
let n = try!(self.write_buf(&buf[pos..]));
let n = self.write_buf(&buf[pos..])?;
Ok(n + pos)
}
}
Expand Down

0 comments on commit cf45702

Please sign in to comment.