From 3f778cd3ab5e6265640822ff2b7c234b0d18b923 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sat, 10 Jul 2021 14:28:46 +1000 Subject: [PATCH] compressor for handmade test files --- src/bin/compressor.rs | 17 + src/lib.rs | 11 + test_conversion/Utility11.xml | 824 ++++++++++++++++++++++++++++++++++ 3 files changed, 852 insertions(+) create mode 100644 src/bin/compressor.rs create mode 100644 test_conversion/Utility11.xml diff --git a/src/bin/compressor.rs b/src/bin/compressor.rs new file mode 100644 index 0000000..64ae115 --- /dev/null +++ b/src/bin/compressor.rs @@ -0,0 +1,17 @@ +use ableton_rack_converter; +use std::{fs, path::PathBuf}; + +fn main() { + let paths = fs::read_dir(".\\test_conversion\\").unwrap(); + for path in paths { + let loadpath = path.unwrap().path(); + if loadpath.extension().expect("couldn't get extension") == "xml" { + let mut path_str = String::from(".\\exported_files\\"); + path_str.push_str(loadpath.file_stem().unwrap().to_str().unwrap()); + path_str.push_str("-compressed.adg"); + let savepath = PathBuf::from(path_str); + println!("{:?}", savepath); + ableton_rack_converter::compress_file(loadpath, savepath); + } + } +} diff --git a/src/lib.rs b/src/lib.rs index a4b6352..e84770b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ use flate2::{read::GzDecoder, write::GzEncoder, Compression}; use std::{ fs::{self, File}, io::{Read, Write}, + path::PathBuf, str, }; use xml_dom::{level2::RefNode, parser}; @@ -38,6 +39,16 @@ pub fn save_uncompressed(dom: &RefNode, filename: &str) { fs::write(filename, xml.as_bytes()).expect("could not write file"); } +pub fn compress_file(loadpath: PathBuf, savepath: PathBuf) { + let mut contents = File::open(loadpath).expect("failed to load file"); + let mut loaded = String::new(); + contents + .read_to_string(&mut loaded) + .expect("failed to read file to string"); + let compressed = compress(&loaded); + fs::write(savepath, compressed).expect("failed to write compressed file"); +} + fn compress(xml: &str) -> Vec { let mut encoder = GzEncoder::new(Vec::new(), Compression::default()); encoder diff --git a/test_conversion/Utility11.xml b/test_conversion/Utility11.xml new file mode 100644 index 0000000..7249106 --- /dev/null +++ b/test_conversion/Utility11.xml @@ -0,0 +1,824 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +