File tree Expand file tree Collapse file tree 9 files changed +30
-31
lines changed
crates/compression-codecs/src Expand file tree Collapse file tree 9 files changed +30
-31
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ impl BrotliDecoder {
4242 let mut input_len = 0 ;
4343 let mut output_len = 0 ;
4444
45- let result = match BrotliDecompressStream (
45+ let status = match BrotliDecompressStream (
4646 & mut in_buf. len ( ) ,
4747 & mut input_len,
4848 in_buf,
@@ -52,14 +52,14 @@ impl BrotliDecoder {
5252 & mut 0 ,
5353 & mut self . state ,
5454 ) {
55- BrotliResult :: ResultFailure => Err ( io:: Error :: other ( "brotli error" ) ) ,
56- status => Ok ( status) ,
55+ BrotliResult :: ResultFailure => return Err ( io:: Error :: other ( "brotli error" ) ) ,
56+ status => status,
5757 } ;
5858
5959 input. advance ( input_len) ;
6060 output. advance ( output_len) ;
6161
62- result
62+ Ok ( status )
6363 }
6464}
6565
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ impl BrotliEncoder {
3131 let mut input_len = 0 ;
3232 let mut output_len = 0 ;
3333
34- let result = if !self . state . compress_stream (
34+ if !self . state . compress_stream (
3535 op,
3636 & mut in_buf. len ( ) ,
3737 in_buf,
@@ -42,15 +42,13 @@ impl BrotliEncoder {
4242 & mut None ,
4343 & mut |_, _, _, _| ( ) ,
4444 ) {
45- Err ( io:: Error :: other ( "brotli error" ) )
46- } else {
47- Ok ( ( ) )
48- } ;
45+ return Err ( io:: Error :: other ( "brotli error" ) ) ;
46+ }
4947
5048 input. advance ( input_len) ;
5149 output. advance ( output_len) ;
5250
53- result
51+ Ok ( ( ) )
5452 }
5553}
5654
Original file line number Diff line number Diff line change @@ -41,11 +41,11 @@ impl BzDecoder {
4141 let prior_in = self . decompress . total_in ( ) ;
4242 let prior_out = self . decompress . total_out ( ) ;
4343
44- let result = self
44+ let status = self
4545 . decompress
4646 // Safety: We **trust** bzip2 to only write initialized data to it
4747 . decompress_uninit ( input. unwritten ( ) , unsafe { output. unwritten_mut ( ) } )
48- . map_err ( io:: Error :: other) ;
48+ . map_err ( io:: Error :: other) ? ;
4949
5050 input. advance ( ( self . decompress . total_in ( ) - prior_in) as usize ) ;
5151 // Safety: We **trust** bzip2 to write bytes properly
@@ -54,11 +54,11 @@ impl BzDecoder {
5454 } ;
5555
5656 // Track when stream has properly ended
57- if matches ! ( result , Ok ( Status :: StreamEnd ) ) {
57+ if status == Status :: StreamEnd {
5858 self . stream_ended = true ;
5959 }
6060
61- result
61+ Ok ( status )
6262 }
6363}
6464
Original file line number Diff line number Diff line change @@ -55,17 +55,17 @@ impl BzEncoder {
5555 let prior_in = self . compress . total_in ( ) ;
5656 let prior_out = self . compress . total_out ( ) ;
5757
58- let result = self
58+ let status = self
5959 . compress
6060 // Safety: We **trust** bzip2 to only write initialized bytes into it
6161 . compress_uninit ( input. unwritten ( ) , unsafe { output. unwritten_mut ( ) } , action)
62- . map_err ( io:: Error :: other) ;
62+ . map_err ( io:: Error :: other) ? ;
6363
6464 input. advance ( ( self . compress . total_in ( ) - prior_in) as usize ) ;
6565 // Safety: We **trust** bzip2 to properly write bytes into it
6666 unsafe { output. assume_init_and_advance ( ( self . compress . total_out ( ) - prior_out) as usize ) } ;
6767
68- result
68+ Ok ( status )
6969 }
7070}
7171
Original file line number Diff line number Diff line change @@ -31,13 +31,13 @@ impl Deflate64Decoder {
3131 // Safety: We **trust** deflate64 to not write uninitialized bytes
3232 . inflate_uninit ( input. unwritten ( ) , unsafe { output. unwritten_mut ( ) } ) ;
3333
34- input. advance ( result. bytes_consumed ) ;
35- // Safety: We **trust** deflate64 to properly write bytes into buffer
36- unsafe { output. assume_init_and_advance ( result. bytes_written ) } ;
37-
3834 if result. data_error {
3935 Err ( Error :: new ( ErrorKind :: InvalidData , "invalid data" ) )
4036 } else {
37+ input. advance ( result. bytes_consumed ) ;
38+ // Safety: We **trust** deflate64 to properly write bytes into buffer
39+ unsafe { output. assume_init_and_advance ( result. bytes_written ) } ;
40+
4141 Ok ( self . inflater . finished ( ) && self . inflater . available_output ( ) == 0 )
4242 }
4343 }
Original file line number Diff line number Diff line change @@ -26,18 +26,18 @@ impl FlateDecoder {
2626 let prior_in = self . decompress . total_in ( ) ;
2727 let prior_out = self . decompress . total_out ( ) ;
2828
29- let result = self
29+ let status = self
3030 . decompress
3131 // Safety: We **trust** flate2 to not write uninitialized bytes into buffer
32- . decompress_uninit ( input. unwritten ( ) , unsafe { output. unwritten_mut ( ) } , flush) ;
32+ . decompress_uninit ( input. unwritten ( ) , unsafe { output. unwritten_mut ( ) } , flush) ? ;
3333
3434 input. advance ( ( self . decompress . total_in ( ) - prior_in) as usize ) ;
3535 // Safety: We **trust** flate2 to write bytes into buffer properly
3636 unsafe {
3737 output. assume_init_and_advance ( ( self . decompress . total_out ( ) - prior_out) as usize )
3838 } ;
3939
40- Ok ( result? )
40+ Ok ( status )
4141 }
4242}
4343
Original file line number Diff line number Diff line change @@ -31,16 +31,16 @@ impl FlateEncoder {
3131 let prior_in = self . compress . total_in ( ) ;
3232 let prior_out = self . compress . total_out ( ) ;
3333
34- let result = self
34+ let status = self
3535 . compress
3636 // Safety: We **trust** flate2 to not write uninitialized bytes into buffer
37- . compress_uninit ( input. unwritten ( ) , unsafe { output. unwritten_mut ( ) } , flush) ;
37+ . compress_uninit ( input. unwritten ( ) , unsafe { output. unwritten_mut ( ) } , flush) ? ;
3838
3939 input. advance ( ( self . compress . total_in ( ) - prior_in) as usize ) ;
4040 // Safety: We **trust** flate2 to write bytes properly into buffer
4141 unsafe { output. assume_init_and_advance ( ( self . compress . total_out ( ) - prior_out) as usize ) } ;
4242
43- Ok ( result? )
43+ Ok ( status )
4444 }
4545}
4646
Original file line number Diff line number Diff line change @@ -77,14 +77,14 @@ impl DecodeV2 for Lz4Decoder {
7777 input. unwritten ( ) . as_ptr ( ) ,
7878 & mut input_size,
7979 core:: ptr:: null ( ) ,
80- ) ) ;
80+ ) ) ? ;
8181 output. assume_init_and_advance ( output_size) ;
8282
8383 result
8484 } ;
8585 input. advance ( input_size) ;
8686
87- let finished = result? == 0 ;
87+ let finished = result == 0 ;
8888 if finished {
8989 self . stream_ended = true ;
9090 }
Original file line number Diff line number Diff line change @@ -24,13 +24,14 @@ fn process_stream(
2424 let previous_out = stream. total_out ( ) as usize ;
2525
2626 // Safety: We **trust** liblzma to not write uninitialized bytes into the buffer
27- let res = stream. process_uninit ( input. unwritten ( ) , unsafe { output. unwritten_mut ( ) } , action) ;
27+ let status =
28+ stream. process_uninit ( input. unwritten ( ) , unsafe { output. unwritten_mut ( ) } , action) ?;
2829
2930 input. advance ( stream. total_in ( ) as usize - previous_in) ;
3031 // Safety: We **trust** liblzma to write bytes into the buffer properly
3132 unsafe { output. assume_init_and_advance ( stream. total_out ( ) as usize - previous_out) } ;
3233
33- match res? {
34+ match status {
3435 Status :: Ok => Ok ( false ) ,
3536 Status :: StreamEnd => Ok ( true ) ,
3637 Status :: GetCheck => Err ( io:: Error :: other ( "Unexpected lzma integrity check" ) ) ,
You can’t perform that action at this time.
0 commit comments