2020-03-18 10:48:57 +01:00
|
|
|
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 {
|
2020-04-03 05:04:12 +02:00
|
|
|
source: InputTarget::Path(path.to_owned()),
|
2020-03-18 10:48:57 +01:00
|
|
|
data,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|