webmetro/src/commands/mod.rs

26 lines
747 B
Rust
Raw Normal View History

use std::io::Cursor;
2018-04-12 04:14:16 +00:00
use bytes::Bytes;
use futures::{TryStream, TryStreamExt};
use tokio_util::codec::{BytesCodec, FramedRead};
use webmetro::error::WebmetroError;
2018-04-12 04:14:16 +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
/// 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.
pub fn stdin_stream() -> impl TryStream<
Item = Result<Cursor<Bytes>, WebmetroError>,
Ok = Cursor<Bytes>,
Error = WebmetroError,
> + Sized
+ Unpin {
FramedRead::new(tokio::io::stdin(), BytesCodec::new())
.map_ok(|bytes| Cursor::new(bytes.freeze()))
.map_err(WebmetroError::from)
2018-04-12 04:14:16 +00:00
}