on the way to a usable version

This commit is contained in:
2024-02-14 22:23:57 +01:00
parent 668e726c21
commit ad03e176c3
7 changed files with 437 additions and 201 deletions
+16 -4
View File
@@ -1,13 +1,25 @@
// SPDX-License-Identifier: GPL-3.0-only
use crate::reader::AheadReader;
use std::io::BufReader;
use std::{
fs::File,
io::{self, Read, Write},
io::{self, Write},
};
pub(crate) fn read_from_file_or_stdin<S: AsRef<str>>(input_file: Option<S>) -> Box<dyn Read> {
pub const BUFSIZE: usize = 64 * 1024; // 64 KiB
pub(crate) fn read_from_file_or_stdin<S: AsRef<str>>(
input_file: Option<S>,
bufsz: usize,
) -> AheadReader {
match input_file {
Some(f) => Box::new(File::open(f.as_ref()).unwrap()),
None => Box::new(io::stdin()),
Some(f) => AheadReader::from(
Box::new(BufReader::new(File::open(f.as_ref()).unwrap())),
bufsz,
),
None => AheadReader::from(Box::new(io::stdin().lock()), bufsz),
}
}