2019-06-06 09:00:13 +00:00
|
|
|
use super::*;
|
|
|
|
use crate::preproc::rga_preproc;
|
2019-06-06 14:48:31 +00:00
|
|
|
use ::zip::read::ZipFile;
|
2019-06-06 09:00:13 +00:00
|
|
|
use failure::*;
|
|
|
|
use lazy_static::lazy_static;
|
2019-06-06 21:43:30 +00:00
|
|
|
|
2019-06-06 23:17:55 +00:00
|
|
|
|
2019-06-06 09:00:13 +00:00
|
|
|
// todo:
|
|
|
|
// maybe todo: read list of extensions from
|
|
|
|
//ffmpeg -demuxers | tail -n+5 | awk '{print $2}' | while read demuxer; do echo MUX=$demuxer; ffmpeg -h demuxer=$demuxer | grep 'Common extensions'; done 2>/dev/null
|
|
|
|
static EXTENSIONS: &[&str] = &["zip"];
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
static ref METADATA: AdapterMeta = AdapterMeta {
|
|
|
|
name: "zip".to_owned(),
|
|
|
|
version: 1,
|
|
|
|
matchers: EXTENSIONS
|
|
|
|
.iter()
|
|
|
|
.map(|s| Matcher::FileExtension(s.to_string()))
|
|
|
|
.collect(),
|
|
|
|
};
|
|
|
|
}
|
2019-06-06 21:43:30 +00:00
|
|
|
#[derive(Default)]
|
2019-06-06 09:00:13 +00:00
|
|
|
pub struct ZipAdapter;
|
|
|
|
|
|
|
|
impl ZipAdapter {
|
|
|
|
pub fn new() -> ZipAdapter {
|
|
|
|
ZipAdapter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl GetMetadata for ZipAdapter {
|
2019-06-06 21:43:30 +00:00
|
|
|
fn metadata(&self) -> &AdapterMeta {
|
2019-06-06 09:00:13 +00:00
|
|
|
&METADATA
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 14:48:31 +00:00
|
|
|
// https://github.com/mvdnes/zip-rs/commit/b9af51e654793931af39f221f143b9dea524f349
|
|
|
|
fn is_dir(f: &ZipFile) -> bool {
|
|
|
|
f.name()
|
|
|
|
.chars()
|
|
|
|
.rev()
|
|
|
|
.next()
|
|
|
|
.map_or(false, |c| c == '/' || c == '\\')
|
|
|
|
}
|
|
|
|
|
2019-06-06 09:00:13 +00:00
|
|
|
impl FileAdapter for ZipAdapter {
|
|
|
|
fn adapt(&self, ai: AdaptInfo) -> Fallible<()> {
|
|
|
|
let AdaptInfo {
|
|
|
|
filepath_hint,
|
|
|
|
mut inp,
|
|
|
|
oup,
|
|
|
|
line_prefix,
|
|
|
|
..
|
|
|
|
} = ai;
|
|
|
|
loop {
|
|
|
|
match ::zip::read::read_zipfile_from_stream(&mut inp) {
|
|
|
|
Ok(None) => break,
|
|
|
|
Ok(Some(mut file)) => {
|
2019-06-06 14:48:31 +00:00
|
|
|
if is_dir(&file) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-06-06 09:00:13 +00:00
|
|
|
eprintln!(
|
|
|
|
"{}|{}: {} bytes ({} bytes packed)",
|
|
|
|
filepath_hint.to_string_lossy(),
|
|
|
|
file.name(),
|
|
|
|
file.size(),
|
|
|
|
file.compressed_size()
|
|
|
|
);
|
2019-06-06 21:43:30 +00:00
|
|
|
let line_prefix = &format!("{}{}: ", line_prefix, file.name());
|
2019-06-06 09:00:13 +00:00
|
|
|
rga_preproc(
|
|
|
|
AdaptInfo {
|
|
|
|
filepath_hint: &file.sanitized_name(),
|
2019-06-06 21:43:30 +00:00
|
|
|
is_real_file: false,
|
2019-06-06 09:00:13 +00:00
|
|
|
inp: &mut file,
|
2019-06-06 21:43:30 +00:00
|
|
|
oup,
|
2019-06-06 09:00:13 +00:00
|
|
|
line_prefix,
|
|
|
|
},
|
|
|
|
None,
|
|
|
|
)?;
|
|
|
|
}
|
|
|
|
Err(e) => return Err(e.into()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|