add zip_with_comment for VFolder
This commit is contained in:
parent
d9e3184a0e
commit
7efe73eb80
|
@ -15,7 +15,7 @@ use super::extendable_queue::ExtendableQueue;
|
||||||
pub struct CompileOptions {
|
pub struct CompileOptions {
|
||||||
/// Whether to compile in debug mode.
|
/// Whether to compile in debug mode.
|
||||||
pub(crate) debug: bool,
|
pub(crate) debug: bool,
|
||||||
|
/// Pack format of the datapack.
|
||||||
pub(crate) pack_formats: RangeInclusive<u8>,
|
pub(crate) pack_formats: RangeInclusive<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -177,6 +177,47 @@ impl VFolder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writer.set_comment("Data pack created with Shulkerbox");
|
||||||
|
|
||||||
|
writer.finish()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "zip")]
|
||||||
|
/// Zip the folder and its contents into a zip archive with the given comment.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
/// - If the zip archive cannot be written
|
||||||
|
pub fn zip_with_comment<S>(&self, path: &Path, comment: S) -> io::Result<()>
|
||||||
|
where
|
||||||
|
S: Into<String>,
|
||||||
|
{
|
||||||
|
use io::Write;
|
||||||
|
|
||||||
|
// open target file
|
||||||
|
let file = fs::File::create(path)?;
|
||||||
|
let mut writer = ZipWriter::new(file);
|
||||||
|
let virtual_files = self.flatten();
|
||||||
|
|
||||||
|
// write each file to the zip archive
|
||||||
|
for (path, file) in virtual_files {
|
||||||
|
writer.start_file(path, zip::write::SimpleFileOptions::default())?;
|
||||||
|
match file {
|
||||||
|
VFile::Text(text) => {
|
||||||
|
writer.write_all(text.as_bytes())?;
|
||||||
|
}
|
||||||
|
VFile::Binary(data) => {
|
||||||
|
writer.write_all(data)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let comment: String = comment.into();
|
||||||
|
if !comment.is_empty() {
|
||||||
|
writer.set_comment(comment);
|
||||||
|
}
|
||||||
|
|
||||||
writer.finish()?;
|
writer.finish()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Reference in New Issue