diff --git a/nod/src/io/wia.rs b/nod/src/io/wia.rs index 865be63..d85d53c 100644 --- a/nod/src/io/wia.rs +++ b/nod/src/io/wia.rs @@ -19,7 +19,6 @@ use crate::{ }, static_assert, util::{ - compress::{lzma2_props_decode, lzma_props_decode, new_lzma2_decoder, new_lzma_decoder}, lfg::LaggedFibonacci, read::{read_box_slice, read_from, read_u16_be, read_vec}, take_seek::TakeSeekExt, @@ -459,15 +458,15 @@ pub enum Decompressor { impl Decompressor { pub fn new(disc: &WIADisc) -> Result { - let data = &disc.compr_data[..disc.compr_data_len as usize]; + let _data = &disc.compr_data[..disc.compr_data_len as usize]; match disc.compression() { WIACompression::None => Ok(Self::None), #[cfg(feature = "compress-bzip2")] WIACompression::Bzip2 => Ok(Self::Bzip2), #[cfg(feature = "compress-lzma")] - WIACompression::Lzma => Ok(Self::Lzma(Box::from(data))), + WIACompression::Lzma => Ok(Self::Lzma(Box::from(_data))), #[cfg(feature = "compress-lzma")] - WIACompression::Lzma2 => Ok(Self::Lzma2(Box::from(data))), + WIACompression::Lzma2 => Ok(Self::Lzma2(Box::from(_data))), #[cfg(feature = "compress-zstd")] WIACompression::Zstandard => Ok(Self::Zstandard), comp => Err(Error::DiscFormat(format!("Unsupported WIA/RVZ compression: {:?}", comp))), @@ -482,11 +481,13 @@ impl Decompressor { Decompressor::Bzip2 => Box::new(bzip2::read::BzDecoder::new(reader)), #[cfg(feature = "compress-lzma")] Decompressor::Lzma(data) => { + use crate::util::compress::{lzma_props_decode, new_lzma_decoder}; let options = lzma_props_decode(data)?; Box::new(new_lzma_decoder(reader, &options)?) } #[cfg(feature = "compress-lzma")] Decompressor::Lzma2(data) => { + use crate::util::compress::{lzma2_props_decode, new_lzma2_decoder}; let options = lzma2_props_decode(data)?; Box::new(new_lzma2_decoder(reader, &options)?) } diff --git a/nod/src/util/compress.rs b/nod/src/util/compress.rs index e0d990c..e081f42 100644 --- a/nod/src/util/compress.rs +++ b/nod/src/util/compress.rs @@ -1,13 +1,14 @@ -use std::{io, io::Read}; - /// Decodes the LZMA Properties byte (lc/lp/pb). /// See `lzma_lzma_lclppb_decode` in `liblzma/lzma/lzma_decoder.c`. #[cfg(feature = "compress-lzma")] -pub fn lzma_lclppb_decode(options: &mut liblzma::stream::LzmaOptions, byte: u8) -> io::Result<()> { +pub fn lzma_lclppb_decode( + options: &mut liblzma::stream::LzmaOptions, + byte: u8, +) -> std::io::Result<()> { let mut d = byte as u32; if d >= (9 * 5 * 5) { - return Err(io::Error::new( - io::ErrorKind::InvalidData, + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, format!("Invalid LZMA props byte: {}", d), )); } @@ -21,11 +22,11 @@ pub fn lzma_lclppb_decode(options: &mut liblzma::stream::LzmaOptions, byte: u8) /// Decodes LZMA properties. /// See `lzma_lzma_props_decode` in `liblzma/lzma/lzma_decoder.c`. #[cfg(feature = "compress-lzma")] -pub fn lzma_props_decode(props: &[u8]) -> io::Result { +pub fn lzma_props_decode(props: &[u8]) -> std::io::Result { use crate::array_ref; if props.len() != 5 { - return Err(io::Error::new( - io::ErrorKind::InvalidData, + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, format!("Invalid LZMA props length: {}", props.len()), )); } @@ -38,11 +39,11 @@ pub fn lzma_props_decode(props: &[u8]) -> io::Result io::Result { +pub fn lzma2_props_decode(props: &[u8]) -> std::io::Result { use std::cmp::Ordering; if props.len() != 1 { - return Err(io::Error::new( - io::ErrorKind::InvalidData, + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, format!("Invalid LZMA2 props length: {}", props.len()), )); } @@ -50,8 +51,8 @@ pub fn lzma2_props_decode(props: &[u8]) -> io::Result { - return Err(io::Error::new( - io::ErrorKind::InvalidData, + return Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, format!("Invalid LZMA2 props byte: {}", d), )); } @@ -66,13 +67,14 @@ pub fn lzma2_props_decode(props: &[u8]) -> io::Result( reader: R, options: &liblzma::stream::LzmaOptions, -) -> io::Result> +) -> std::io::Result> where - R: Read, + R: std::io::Read, { let mut filters = liblzma::stream::Filters::new(); filters.lzma1(options); - let stream = liblzma::stream::Stream::new_raw_decoder(&filters).map_err(io::Error::from)?; + let stream = + liblzma::stream::Stream::new_raw_decoder(&filters).map_err(std::io::Error::from)?; Ok(liblzma::read::XzDecoder::new_stream(reader, stream)) } @@ -81,12 +83,13 @@ where pub fn new_lzma2_decoder( reader: R, options: &liblzma::stream::LzmaOptions, -) -> io::Result> +) -> std::io::Result> where - R: Read, + R: std::io::Read, { let mut filters = liblzma::stream::Filters::new(); filters.lzma2(options); - let stream = liblzma::stream::Stream::new_raw_decoder(&filters).map_err(io::Error::from)?; + let stream = + liblzma::stream::Stream::new_raw_decoder(&filters).map_err(std::io::Error::from)?; Ok(liblzma::read::XzDecoder::new_stream(reader, stream)) }