feat: allow override of buffer size

This commit is contained in:
鲁树人
2024-09-05 02:21:34 +01:00
parent 0f1233b45a
commit 6c5c82ee1c
2 changed files with 15 additions and 11 deletions

View File

@@ -3,6 +3,7 @@ use clap::Args;
use std::fs::File;
use std::io::{Read, Write};
use std::path::PathBuf;
use crate::Cli;
/// Decrypt a QMCv1 file
#[derive(Args)]
@@ -16,16 +17,13 @@ pub struct ArgsQMCv1 {
input: PathBuf,
}
// 4MiB buffer is working well on my machine.
const BUFFER_SIZE: usize = 4 * 1024 * 1024;
impl ArgsQMCv1 {
pub fn run(&self) -> Result<i32> {
pub fn run(&self, cli: &Cli) -> Result<i32> {
let mut file_input = File::open(&self.input)?;
let mut file_output = File::create(&self.output)?;
let mut offset = 0usize;
let mut buffer = vec![0u8; BUFFER_SIZE].into_boxed_slice();
let mut buffer = vec![0u8; cli.buffer_size].into_boxed_slice();
while let Ok(n) = file_input.read(&mut buffer) {
if n == 0 {
break;