From 0a90725d4a0fe7e4aed01d8d4ff7e2466e03671b Mon Sep 17 00:00:00 2001 From: spuds <71292624+bananaturtlesandwich@users.noreply.github.com> Date: Sun, 27 Aug 2023 15:17:27 +0100 Subject: [PATCH] new_any should not consume the reader --- repak/src/pak.rs | 4 ++-- repak_cli/src/main.rs | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/repak/src/pak.rs b/repak/src/pak.rs index c482c84..16399cd 100644 --- a/repak/src/pak.rs +++ b/repak/src/pak.rs @@ -84,14 +84,14 @@ fn decrypt(key: &Option, bytes: &mut [u8]) -> Result<(), super::Err impl PakReader { pub fn new_any( - mut reader: R, + reader: &mut R, key: Option, ) -> Result { use std::fmt::Write; let mut log = "\n".to_owned(); for ver in Version::iter() { - match Pak::read(&mut reader, ver, key.clone()) { + match Pak::read(&mut *reader, ver, key.clone()) { Ok(pak) => { return Ok(PakReader { pak, key }); } diff --git a/repak_cli/src/main.rs b/repak_cli/src/main.rs index 11cb8f8..7b68d61 100644 --- a/repak_cli/src/main.rs +++ b/repak_cli/src/main.rs @@ -175,7 +175,7 @@ fn main() -> Result<(), repak::Error> { } fn info(aes_key: Option, action: ActionInfo) -> Result<(), repak::Error> { - let pak = repak::PakReader::new_any(BufReader::new(File::open(action.input)?), aes_key)?; + let pak = repak::PakReader::new_any(&mut BufReader::new(File::open(action.input)?), aes_key)?; println!("mount point: {}", pak.mount_point()); println!("version: {}", pak.version()); println!("version major: {}", pak.version().version_major()); @@ -186,7 +186,7 @@ fn info(aes_key: Option, action: ActionInfo) -> Result<(), repak::E } fn list(aes_key: Option, action: ActionList) -> Result<(), repak::Error> { - let pak = repak::PakReader::new_any(BufReader::new(File::open(action.input)?), aes_key)?; + let pak = repak::PakReader::new_any(&mut BufReader::new(File::open(action.input)?), aes_key)?; let mount_point = PathBuf::from(pak.mount_point()); let prefix = Path::new(&action.strip_prefix); @@ -215,8 +215,7 @@ fn list(aes_key: Option, action: ActionList) -> Result<(), repak::E } fn hash_list(aes_key: Option, action: ActionHashList) -> Result<(), repak::Error> { - let mut reader = BufReader::new(File::open(&action.input)?); - let pak = repak::PakReader::new_any(&mut reader, aes_key)?; + let pak = repak::PakReader::new_any(&mut BufReader::new(File::open(&action.input)?), aes_key)?; let mount_point = PathBuf::from(pak.mount_point()); let prefix = Path::new(&action.strip_prefix); @@ -271,7 +270,7 @@ fn hash_list(aes_key: Option, action: ActionHashList) -> Result<(), const STYLE: &str = "[{elapsed_precise}] [{wide_bar}] {pos}/{len} ({eta})"; fn unpack(aes_key: Option, action: ActionUnpack) -> Result<(), repak::Error> { - let pak = repak::PakReader::new_any(BufReader::new(File::open(&action.input)?), aes_key)?; + let pak = repak::PakReader::new_any(&mut BufReader::new(File::open(&action.input)?), aes_key)?; let output = action .output .map(PathBuf::from)