-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Starke
committed
Sep 21, 2023
1 parent
6d24e80
commit d2f3f87
Showing
6 changed files
with
141 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use std::io::{BufRead, BufReader, Read}; | ||
|
||
use clio::Input; | ||
use flate2::bufread::GzDecoder; | ||
|
||
pub struct FileInput { | ||
stream: Box<dyn BufRead>, | ||
input: Input | ||
} | ||
|
||
impl From<Input> for FileInput { | ||
fn from(value: Input) -> Self { | ||
let cloned_input = value.clone(); | ||
if let Some(extension) = value.path().extension() { | ||
if extension == "gz" { | ||
return Self { | ||
stream: Box::new(BufReader::new(GzDecoder::new(BufReader::new(value)))), | ||
input: cloned_input | ||
}; | ||
} | ||
} | ||
|
||
Self { | ||
stream: Box::new(BufReader::new(value)), | ||
input: cloned_input | ||
} | ||
} | ||
} | ||
|
||
impl From<&Input> for FileInput { | ||
fn from(value: &Input) -> Self { | ||
Self::from(value.clone()) | ||
} | ||
} | ||
|
||
|
||
impl From<&mut Input> for FileInput { | ||
fn from(value: &mut Input) -> Self { | ||
Self::from(value.clone()) | ||
} | ||
} | ||
|
||
impl Clone for FileInput { | ||
fn clone(&self) -> Self { | ||
self.input.clone().into() | ||
} | ||
} | ||
|
||
impl Read for FileInput { | ||
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> { | ||
self.stream.read(buf) | ||
} | ||
} | ||
|
||
impl BufRead for FileInput { | ||
fn fill_buf(&mut self) -> std::io::Result<&[u8]> { | ||
self.stream.fill_buf() | ||
} | ||
|
||
fn consume(&mut self, amt: usize) { | ||
self.stream.consume(amt) | ||
} | ||
} | ||
|
||
impl<'a> TryFrom<&'a str> for FileInput { | ||
type Error = <Input as TryFrom<&'a str>>::Error; | ||
|
||
fn try_from(value: &'a str) -> Result<Self, Self::Error> { | ||
let res = Input::try_from(value)?; | ||
Ok(res.into()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
mod rfc3339_datetime; | ||
pub mod bodyfile; | ||
mod parse_cli; | ||
mod file_input; | ||
|
||
pub use rfc3339_datetime::*; | ||
pub use parse_cli::*; | ||
pub use parse_cli::*; | ||
pub use file_input::*; |