Prepare reading in files
This commit is contained in:
parent
a5512085b5
commit
a5cfe87a69
|
@ -7,4 +7,5 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = {version = "*", features = ["derive"]}
|
clap = {version = "*", features = ["derive"]}
|
||||||
|
image = "*"
|
||||||
tool_helper = {path = "../tool_helper"}
|
tool_helper = {path = "../tool_helper"}
|
|
@ -1,4 +1,6 @@
|
||||||
use clap::{Args, ValueEnum};
|
use clap::{Args, ValueEnum};
|
||||||
|
use image::io::Reader as ImageReader;
|
||||||
|
use std::io::Cursor;
|
||||||
use tool_helper::{Error, Input, Output};
|
use tool_helper::{Error, Input, Output};
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
|
||||||
|
@ -14,6 +16,8 @@ pub struct Arguments {
|
||||||
color_depth: ColorDepth
|
color_depth: ColorDepth
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn convert(_args: Arguments, _input: Input, _output: Output) -> Result<(), Error> {
|
pub fn convert(_args: Arguments, input: Input, _output: Output) -> Result<(), Error> {
|
||||||
|
ImageReader::new(Cursor::new(tool_helper::input_to_vec(input)?));
|
||||||
|
|
||||||
Err(Error::new("Convert not implemented yet".to_owned(), Some(-2)))
|
Err(Error::new("Convert not implemented yet".to_owned(), Some(-2)))
|
||||||
}
|
}
|
|
@ -54,3 +54,13 @@ pub fn os_str_to_string(input: &std::ffi::OsStr, name: &str) -> Result<String> {
|
||||||
pub fn get_file_name_from_path_buf(input: &PathBuf, name: &str) -> Result<String> {
|
pub fn get_file_name_from_path_buf(input: &PathBuf, name: &str) -> Result<String> {
|
||||||
os_str_to_string(Error::ok_or_new(input.file_name(), ||format!("No {} file name found", name), None)?, name)
|
os_str_to_string(Error::ok_or_new(input.file_name(), ||format!("No {} file name found", name), None)?, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn input_to_vec(input: Input) -> Result<Vec<u8>> {
|
||||||
|
let mut data = Vec::new();
|
||||||
|
|
||||||
|
for byte in input.bytes() {
|
||||||
|
data.push(Error::try_or_new(byte, None)?);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(data)
|
||||||
|
}
|
Loading…
Reference in New Issue