2020-09-12 02:57:23 +00:00
|
|
|
use std::time::Duration;
|
|
|
|
|
2019-10-21 07:18:51 +00:00
|
|
|
use bytes::Bytes;
|
2020-05-09 01:15:18 +00:00
|
|
|
use futures::{Stream, TryStreamExt};
|
2020-05-08 03:14:43 +00:00
|
|
|
use tokio_util::codec::{BytesCodec, FramedRead};
|
2020-09-12 02:57:23 +00:00
|
|
|
use webmetro::error::WebmetroError;
|
2018-04-12 04:14:16 +00:00
|
|
|
|
2018-04-12 01:54:02 +00:00
|
|
|
pub mod dump;
|
2018-04-12 06:03:46 +00:00
|
|
|
pub mod filter;
|
2018-04-11 05:39:28 +00:00
|
|
|
pub mod relay;
|
2018-04-15 05:43:23 +00:00
|
|
|
pub mod send;
|
2018-04-12 04:14:16 +00:00
|
|
|
|
2018-04-14 22:18:50 +00:00
|
|
|
/// An adapter that makes chunks of bytes from stdin available as a Stream;
|
|
|
|
/// is NOT actually async, and just uses blocking read. Don't use more than
|
|
|
|
/// one at once, who knows who gets which bytes.
|
2020-05-09 01:15:18 +00:00
|
|
|
pub fn stdin_stream() -> impl Stream<Item = Result<Bytes, std::io::Error>> + Sized + Unpin {
|
2020-09-12 02:57:23 +00:00
|
|
|
FramedRead::new(tokio::io::stdin(), BytesCodec::new()).map_ok(|bytes| bytes.freeze())
|
|
|
|
}
|
|
|
|
|
2022-05-23 00:37:03 +00:00
|
|
|
pub fn parse_time(arg: &str) -> Result<Duration, WebmetroError> {
|
|
|
|
match arg.parse() {
|
|
|
|
Ok(secs) => Ok(Duration::from_secs(secs)),
|
|
|
|
Err(err) => Err(WebmetroError::ApplicationError {
|
|
|
|
message: err.to_string(),
|
|
|
|
}),
|
2020-09-12 02:57:23 +00:00
|
|
|
}
|
2018-04-12 04:14:16 +00:00
|
|
|
}
|