|
|
@@ -1,5 +1,6 @@
|
|
|
use anyhow::{anyhow, Ok, Result};
|
|
|
use crossbeam_channel::{unbounded, Receiver, Sender};
|
|
|
+use flate2::{read::GzDecoder, write::GzEncoder, Compression};
|
|
|
use indicatif::MultiProgress;
|
|
|
use log::{info, warn};
|
|
|
use num_format::{CustomFormat, Grouping, ToFormattedString};
|
|
|
@@ -444,17 +445,36 @@ pub fn spawn_phase(
|
|
|
(s, rr)
|
|
|
}
|
|
|
|
|
|
+// pub fn save_phases(phases: &Vec<Phase>, filename: &str) -> anyhow::Result<()> {
|
|
|
+// let bytes = postcard::to_allocvec(phases)?;
|
|
|
+// let mut file = File::create(filename)?;
|
|
|
+// file.write_all(&bytes)?;
|
|
|
+// Ok(())
|
|
|
+// }
|
|
|
+//
|
|
|
+// pub fn load_phases(filename: &str) -> anyhow::Result<Vec<Phase>> {
|
|
|
+// let mut file = File::open(filename)?;
|
|
|
+// let mut bytes = Vec::new();
|
|
|
+// file.read_to_end(&mut bytes)?;
|
|
|
+// let phases: Vec<Phase> = postcard::from_bytes(&bytes)?;
|
|
|
+// Ok(phases)
|
|
|
+// }
|
|
|
+
|
|
|
pub fn save_phases(phases: &Vec<Phase>, filename: &str) -> anyhow::Result<()> {
|
|
|
- let bytes = postcard::to_allocvec(phases)?;
|
|
|
- let mut file = File::create(filename)?;
|
|
|
- file.write_all(&bytes)?;
|
|
|
+ let bytes = postcard::to_allocvec(phases).expect("Serialization failed");
|
|
|
+ let file = File::create(filename)?;
|
|
|
+ let mut encoder = GzEncoder::new(file, Compression::default());
|
|
|
+ encoder.write_all(&bytes)?;
|
|
|
+ encoder.finish()?;
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
pub fn load_phases(filename: &str) -> anyhow::Result<Vec<Phase>> {
|
|
|
- let mut file = File::open(filename)?;
|
|
|
+ let file = File::open(filename)?;
|
|
|
+ let mut decoder = GzDecoder::new(file);
|
|
|
let mut bytes = Vec::new();
|
|
|
- file.read_to_end(&mut bytes)?;
|
|
|
- let phases: Vec<Phase> = postcard::from_bytes(&bytes)?;
|
|
|
+ decoder.read_to_end(&mut bytes)?;
|
|
|
+ let phases: Vec<Phase> = postcard::from_bytes(&bytes).expect("Deserialization failed");
|
|
|
Ok(phases)
|
|
|
}
|
|
|
+
|