new_any should not consume the reader

This commit is contained in:
spuds 2023-08-27 15:17:27 +01:00 committed by Truman Kilen
parent 524cd11e02
commit 0a90725d4a
2 changed files with 6 additions and 7 deletions

View file

@ -84,14 +84,14 @@ fn decrypt(key: &Option<aes::Aes256>, bytes: &mut [u8]) -> Result<(), super::Err
impl PakReader { impl PakReader {
pub fn new_any<R: Read + Seek>( pub fn new_any<R: Read + Seek>(
mut reader: R, reader: &mut R,
key: Option<aes::Aes256>, key: Option<aes::Aes256>,
) -> Result<Self, super::Error> { ) -> Result<Self, super::Error> {
use std::fmt::Write; use std::fmt::Write;
let mut log = "\n".to_owned(); let mut log = "\n".to_owned();
for ver in Version::iter() { for ver in Version::iter() {
match Pak::read(&mut reader, ver, key.clone()) { match Pak::read(&mut *reader, ver, key.clone()) {
Ok(pak) => { Ok(pak) => {
return Ok(PakReader { pak, key }); return Ok(PakReader { pak, key });
} }

View file

@ -175,7 +175,7 @@ fn main() -> Result<(), repak::Error> {
} }
fn info(aes_key: Option<aes::Aes256>, action: ActionInfo) -> Result<(), repak::Error> { fn info(aes_key: Option<aes::Aes256>, 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!("mount point: {}", pak.mount_point());
println!("version: {}", pak.version()); println!("version: {}", pak.version());
println!("version major: {}", pak.version().version_major()); println!("version major: {}", pak.version().version_major());
@ -186,7 +186,7 @@ fn info(aes_key: Option<aes::Aes256>, action: ActionInfo) -> Result<(), repak::E
} }
fn list(aes_key: Option<aes::Aes256>, action: ActionList) -> Result<(), repak::Error> { fn list(aes_key: Option<aes::Aes256>, 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 mount_point = PathBuf::from(pak.mount_point());
let prefix = Path::new(&action.strip_prefix); let prefix = Path::new(&action.strip_prefix);
@ -215,8 +215,7 @@ fn list(aes_key: Option<aes::Aes256>, action: ActionList) -> Result<(), repak::E
} }
fn hash_list(aes_key: Option<aes::Aes256>, action: ActionHashList) -> Result<(), repak::Error> { fn hash_list(aes_key: Option<aes::Aes256>, action: ActionHashList) -> Result<(), repak::Error> {
let mut reader = BufReader::new(File::open(&action.input)?); let pak = repak::PakReader::new_any(&mut BufReader::new(File::open(&action.input)?), aes_key)?;
let pak = repak::PakReader::new_any(&mut reader, aes_key)?;
let mount_point = PathBuf::from(pak.mount_point()); let mount_point = PathBuf::from(pak.mount_point());
let prefix = Path::new(&action.strip_prefix); let prefix = Path::new(&action.strip_prefix);
@ -271,7 +270,7 @@ fn hash_list(aes_key: Option<aes::Aes256>, action: ActionHashList) -> Result<(),
const STYLE: &str = "[{elapsed_precise}] [{wide_bar}] {pos}/{len} ({eta})"; const STYLE: &str = "[{elapsed_precise}] [{wide_bar}] {pos}/{len} ({eta})";
fn unpack(aes_key: Option<aes::Aes256>, action: ActionUnpack) -> Result<(), repak::Error> { fn unpack(aes_key: Option<aes::Aes256>, 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 let output = action
.output .output
.map(PathBuf::from) .map(PathBuf::from)