intermodal/src/mode.rs
Casey Rodarmor 3739a92857
Support creating multi-file torrents
type: added
2020-04-07 19:01:04 -07:00

18 lines
450 B
Rust

use crate::common::*;
#[derive(Deserialize, Serialize, Debug, PartialEq)]
#[serde(untagged)]
pub(crate) enum Mode {
Single { length: u64, md5sum: Option<String> },
Multiple { files: Vec<FileInfo> },
}
impl Mode {
pub(crate) fn total_size(&self) -> Bytes {
match self {
Self::Single { length, .. } => Bytes::from(*length),
Self::Multiple { files } => Bytes::from(files.iter().map(|file| file.length).sum::<u64>()),
}
}
}