intermodal/src/input.rs
Eric Siegel c23b0635ee
Add ability to create single-file torrents from stdin
Torrents may now be created from standard input by passing `--input -`.

Since `--name` and `--output` cannot be deduced, they are required when
`--input -`.

type: added
2020-04-07 19:01:43 -07:00

30 lines
563 B
Rust

use crate::common::*;
pub(crate) struct Input {
source: InputTarget,
data: Vec<u8>,
}
impl Input {
pub(crate) fn new(source: InputTarget, data: Vec<u8>) -> Input {
Self { source, data }
}
pub(crate) fn data(&self) -> &[u8] {
&self.data
}
pub(crate) fn source(&self) -> &InputTarget {
&self.source
}
#[cfg(test)]
pub(crate) fn from_path(path: &Path) -> Result<Input> {
let data = fs::read(path).context(error::Filesystem { path })?;
Ok(Input {
source: InputTarget::Path(path.to_owned()),
data,
})
}
}