add with input stream
parent
ca1dca8414
commit
e96052c286
|
|
@ -0,0 +1,8 @@
|
|||
use std::ops::Deref;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub trait ResourceInputStream: std::io::Read {
|
||||
fn path(&self) -> PathBuf;
|
||||
}
|
||||
|
||||
pub type DynResourceInputStream = Box<dyn ResourceInputStream>;
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
pub mod input_stream;
|
||||
mod input_stream_filesystem;
|
||||
pub mod resource_filesystem;
|
||||
|
||||
use mlua::{MetaMethod, UserData, UserDataFields, UserDataMethods};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,8 @@
|
|||
use crate::resources::input_stream::DynResourceInputStream;
|
||||
|
||||
mod zip_sink;
|
||||
|
||||
pub trait ResourceSink {}
|
||||
pub trait ResourceSink {
|
||||
fn add_file(&mut self, input: DynResourceInputStream);
|
||||
fn add_directory(&mut self);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
use crate::resources::input_stream::DynResourceInputStream;
|
||||
use crate::sinks::ResourceSink;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::ptr::write;
|
||||
use zip::ZipWriter;
|
||||
|
||||
pub struct ZipSink {
|
||||
writer: ZipWriter<File>,
|
||||
}
|
||||
|
||||
impl ResourceSink for ZipSink {
|
||||
fn add(&mut self, mut input: DynResourceInputStream) {
|
||||
self.writer
|
||||
.start_file(input.path(), Default::default())
|
||||
.expect("error writing zip");
|
||||
std::io::copy(&mut input, &mut self.writer).expect("error writing zip");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue