test compression is now working. you can compress a test and decompress it.
needs to be rolled into the test util suite
This commit is contained in:
parent
0f40002053
commit
e45d269828
161
Cargo.lock
generated
161
Cargo.lock
generated
@ -270,12 +270,6 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.98"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487"
|
||||
|
||||
[[package]]
|
||||
name = "arboard"
|
||||
version = "3.5.0"
|
||||
@ -746,7 +740,7 @@ version = "5.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a93c74882fe7e6b16089cc70122af492e16b76016d3ed2af9b0c4b6a8bca0ab0"
|
||||
dependencies = [
|
||||
"egui 0.29.1",
|
||||
"egui",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1313,15 +1307,6 @@ dependencies = [
|
||||
"wio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ecolor"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20930a432bbd57a6d55e07976089708d4893f3d556cf42a0d79e9e321fa73b10"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ecolor"
|
||||
version = "0.29.1"
|
||||
@ -1329,7 +1314,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "775cfde491852059e386c4e1deb4aef381c617dc364184c6f6afee99b87c402b"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"emath 0.29.1",
|
||||
"emath",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1341,10 +1326,10 @@ dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
"document-features",
|
||||
"egui 0.29.1",
|
||||
"egui",
|
||||
"egui-wgpu",
|
||||
"egui-winit",
|
||||
"egui_glow 0.29.1",
|
||||
"egui_glow",
|
||||
"glow 0.14.2",
|
||||
"glutin 0.32.3",
|
||||
"glutin-winit 0.5.0",
|
||||
@ -1367,17 +1352,6 @@ dependencies = [
|
||||
"winit 0.30.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "egui"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "584c5d1bf9a67b25778a3323af222dbe1a1feb532190e103901187f92c7fe29a"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"epaint 0.27.2",
|
||||
"nohash-hasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "egui"
|
||||
version = "0.29.1"
|
||||
@ -1386,8 +1360,8 @@ checksum = "53eafabcce0cb2325a59a98736efe0bf060585b437763f8c476957fb274bb974"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"ahash",
|
||||
"emath 0.29.1",
|
||||
"epaint 0.29.1",
|
||||
"emath",
|
||||
"epaint",
|
||||
"log",
|
||||
"nohash-hasher",
|
||||
]
|
||||
@ -1401,8 +1375,8 @@ dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
"document-features",
|
||||
"egui 0.29.1",
|
||||
"epaint 0.29.1",
|
||||
"egui",
|
||||
"epaint",
|
||||
"log",
|
||||
"thiserror 1.0.69",
|
||||
"type-map",
|
||||
@ -1420,7 +1394,7 @@ dependencies = [
|
||||
"accesskit_winit",
|
||||
"ahash",
|
||||
"arboard",
|
||||
"egui 0.29.1",
|
||||
"egui",
|
||||
"log",
|
||||
"raw-window-handle 0.6.2",
|
||||
"smithay-clipboard 0.7.2",
|
||||
@ -1429,21 +1403,6 @@ dependencies = [
|
||||
"winit 0.30.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "egui_glow"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e0e5d975f3c86edc3d35b1db88bb27c15dde7c55d3b5af164968ab5ede3f44ca"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"egui 0.27.2",
|
||||
"glow 0.13.1",
|
||||
"log",
|
||||
"memoffset 0.9.1",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "egui_glow"
|
||||
version = "0.29.1"
|
||||
@ -1452,7 +1411,7 @@ checksum = "0e39bccc683cd43adab530d8f21a13eb91e80de10bcc38c3f1c16601b6f62b26"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
"egui 0.29.1",
|
||||
"egui",
|
||||
"glow 0.14.2",
|
||||
"log",
|
||||
"memoffset 0.9.1",
|
||||
@ -1461,33 +1420,12 @@ dependencies = [
|
||||
"winit 0.30.11",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "egui_sdl2_platform"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6362d5869954bc50ce3e91cacd36bed234eaa633266a80e886b10413e94e0748"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"egui 0.27.2",
|
||||
"log",
|
||||
"sdl2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "emath"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4c3a552cfca14630702449d35f41c84a0d15963273771c6059175a803620f3f"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "emath"
|
||||
version = "0.29.1"
|
||||
@ -1537,21 +1475,6 @@ dependencies = [
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "epaint"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b381f8b149657a4acf837095351839f32cd5c4aec1817fc4df84e18d76334176"
|
||||
dependencies = [
|
||||
"ab_glyph",
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
"ecolor 0.27.2",
|
||||
"emath 0.27.2",
|
||||
"nohash-hasher",
|
||||
"parking_lot",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "epaint"
|
||||
version = "0.29.1"
|
||||
@ -1561,8 +1484,8 @@ dependencies = [
|
||||
"ab_glyph",
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
"ecolor 0.29.1",
|
||||
"emath 0.29.1",
|
||||
"ecolor",
|
||||
"emath",
|
||||
"epaint_default_fonts",
|
||||
"log",
|
||||
"nohash-hasher",
|
||||
@ -1825,7 +1748,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"catppuccin-egui",
|
||||
"eframe",
|
||||
"egui 0.29.1",
|
||||
"egui",
|
||||
"gemma",
|
||||
]
|
||||
|
||||
@ -1849,19 +1772,6 @@ dependencies = [
|
||||
"winit 0.27.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gemmasdl2"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"egui 0.27.2",
|
||||
"egui_glow 0.27.2",
|
||||
"egui_sdl2_platform",
|
||||
"gemma",
|
||||
"gl",
|
||||
"pollster",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gemmatelnet"
|
||||
version = "0.1.0"
|
||||
@ -1950,15 +1860,6 @@ version = "0.31.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
|
||||
|
||||
[[package]]
|
||||
name = "gl"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a94edab108827d67608095e269cf862e60d920f144a5026d3dbcfd8b877fb404"
|
||||
dependencies = [
|
||||
"gl_generator",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gl_generator"
|
||||
version = "0.14.0"
|
||||
@ -3591,12 +3492,6 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pollster"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5da3b0203fd7ee5720aa0b5e790b591aa5d3f41c3ed2c34a3a393382198af2f7"
|
||||
|
||||
[[package]]
|
||||
name = "potential_utf"
|
||||
version = "0.1.2"
|
||||
@ -3991,30 +3886,6 @@ dependencies = [
|
||||
"tiny-skia 0.11.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sdl2"
|
||||
version = "0.37.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b498da7d14d1ad6c839729bd4ad6fc11d90a57583605f3b4df2cd709a9cd380"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"raw-window-handle 0.6.2",
|
||||
"sdl2-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sdl2-sys"
|
||||
version = "0.37.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "951deab27af08ed9c6068b7b0d05a93c91f0a8eb16b6b816a5e73452a43521d3"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"version-compare",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.219"
|
||||
@ -4606,12 +4477,6 @@ version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version-compare"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
|
||||
@ -4,7 +4,6 @@ members = [
|
||||
"gemmaegui",
|
||||
"gemmaimgui",
|
||||
"gemmatelnet",
|
||||
"gemmasdl2",
|
||||
"gemmautil",
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
@ -1,13 +1,36 @@
|
||||
/// TestCompression
|
||||
///
|
||||
/// Utility for [de]compressing tests for Gemma
|
||||
///
|
||||
/// Usage: testcompression <COMMAND>
|
||||
//
|
||||
// Commands:
|
||||
// compress Compress the input string
|
||||
// decompress Decompress the input string (must be compressed format)
|
||||
// help Print this message or the help of the given subcommand(s)
|
||||
//
|
||||
// Options:
|
||||
// -h, --help Print help
|
||||
// -V, --version Print version
|
||||
///
|
||||
/// Limitations:
|
||||
/// - Uncompressed files must only contain printable ASCII characters
|
||||
/// - Stuff I don't know about yet
|
||||
|
||||
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use clap::{Parser, Subcommand};
|
||||
use flate2::{write::{GzEncoder, GzDecoder}, Compression};
|
||||
use std::path::PathBuf;
|
||||
use std::io::prelude::*;
|
||||
use std::io::Read;
|
||||
use std::io::Write;
|
||||
use flate2::write::ZlibEncoder;
|
||||
use gemma::constants::TEST_ROM_ROOT;
|
||||
use flate2::Compression;
|
||||
use flate2::write::{GzEncoder, ZlibEncoder};
|
||||
use gemma::constants::{TESTS_ROOT, TEST_ROM_ROOT};
|
||||
use flate2::read::{DeflateDecoder, DeflateEncoder, GzDecoder};
|
||||
use std::io::prelude::*;
|
||||
use std::io;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about = "Compress or decompress a string", long_about = None)]
|
||||
@ -19,67 +42,46 @@ struct Cli {
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
/// Compress the input string
|
||||
/// Compress the input file
|
||||
Compress {
|
||||
/// The string to compress
|
||||
/// The string to compress, in plain text
|
||||
input: PathBuf,
|
||||
},
|
||||
/// Decompress the input string (must be compressed format)
|
||||
/// Decompress the input file
|
||||
Decompress {
|
||||
/// The compressed string to decompress, in hex format
|
||||
input: PathBuf,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Compresses raw binary data using Gzip and returns the compressed bytes.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `data` - A `Vec<u8>` containing the uncompressed binary data.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// A `Vec<u8>` with the compressed data. Panics if compression fails.
|
||||
pub fn compress_data(data: Vec<u8>) -> Vec<u8> {
|
||||
let mut encoder = GzEncoder::new(Vec::new(), Compression::default());
|
||||
encoder
|
||||
.write_all(&data)
|
||||
.expect("Failed to write data to encoder");
|
||||
encoder.finish().expect("Failed to finish compression")
|
||||
}
|
||||
|
||||
/// Decompresses Gzip-compressed binary data and returns the uncompressed bytes.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `data` - A `Vec<u8>` containing Gzip-compressed data.
|
||||
///
|
||||
/// # Returns
|
||||
///
|
||||
/// A `Vec<u8>` with the decompressed data. Panics if decompression fails.
|
||||
// pub fn decompress_data(data: Vec<u8>) -> Vec<u8> {
|
||||
// let mut decoder = GzDecoder::new( &data[..]);
|
||||
// let mut decompressed = Vec::new();
|
||||
// decoder.write_all(&mut decompressed)
|
||||
// .expect("Failed to decompress data");
|
||||
// decompressed.clone().to_vec()
|
||||
// }
|
||||
|
||||
fn compress_file(input_path: &PathBuf) {
|
||||
let target_file_name = format!("{}.tflt", input_path.display());
|
||||
println!("TARGET_FILE_NAME: {}", target_file_name);
|
||||
let input_data = fs::read(input_path).expect("Failed to read input file");
|
||||
let file = File::open(&input_path).unwrap();
|
||||
let mut compressed_bytes= Vec::new();
|
||||
|
||||
let compressed_data = compress_data(input_data);
|
||||
let target_file = File::create(target_file_name);
|
||||
target_file.unwrap().write_all(&compressed_data).unwrap()
|
||||
let mut deflater = DeflateEncoder::new(file, Compression::fast());
|
||||
deflater.read_to_end(&mut compressed_bytes).expect("Unable to write compressed data to buffer ");
|
||||
|
||||
let output_filename = format!("{}.deflated", input_path.display());
|
||||
let output_file = File::create(&output_filename);
|
||||
output_file.unwrap().write_all(&compressed_bytes).expect("Unable to write compressed version");
|
||||
}
|
||||
|
||||
fn decompress_file(input_path: &PathBuf) {
|
||||
let target_file_name = format!("{}.uncompressed", input_path.display());
|
||||
let file = File::open(&input_path).unwrap();
|
||||
let mut uncompressed_bytes = Vec::new();
|
||||
|
||||
let mut inflater = DeflateDecoder::new(file);
|
||||
inflater.read_to_end(&mut uncompressed_bytes).expect("Unable to inflate.");
|
||||
|
||||
let target_file_name = format!("{}.inflated", input_path.display());
|
||||
println!("Writing decompressed data to {}", target_file_name);
|
||||
let input_data = fs::read(input_path).expect("Failed to read compressed file.");
|
||||
|
||||
let mut target_file = File::create(&target_file_name)
|
||||
.expect("Unable to create uncompressed output file");
|
||||
target_file
|
||||
.write_all(&uncompressed_bytes)
|
||||
.expect("Unable to write decompressed file");
|
||||
|
||||
// let decompressed_data = decompress_data(input_data);
|
||||
// let mut target_file = File::create(&target_file_name).expect(format!("Unable to create uncompressed file -> {}", target_file_name.clone()).as_str());
|
||||
//target_file.write_all(&decompressed_data).expect(format!("Unable to write uncompressed file -> {}", target_file_name).as_str());
|
||||
@ -87,21 +89,19 @@ fn decompress_file(input_path: &PathBuf) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
|
||||
let filename = format!("{}/gemma/{}/2-ibm-logo.ch8", std::env::current_dir().unwrap().display(), TEST_ROM_ROOT);
|
||||
println!("READING {} from {}", filename, std::env::current_dir().unwrap().display());
|
||||
let mut file = File::open(filename).unwrap();
|
||||
let mut file_data = Vec::new();
|
||||
file.read_to_end(&mut file_data).expect("unable to read rom");
|
||||
let mut e = ZlibEncoder::new(Vec::new(), Compression::default());
|
||||
let raw_file = format!("{}/gemma/{}test_scroll_down_10_hd.asc", std::env::current_dir().unwrap().display(), TESTS_ROOT);
|
||||
let compressed_file = format!("{}.deflated", &raw_file);
|
||||
let uncompressed_file = format!("{}.inflated", &compressed_file);
|
||||
println!("[ + ] Writing compressed file from {}", &raw_file);
|
||||
compress_file(&raw_file.clone().into());
|
||||
|
||||
e.write_all(b"foo");
|
||||
e.write_all(b"bar");
|
||||
let compressed_bytes = e.finish();
|
||||
decompress_file(&compressed_file.into());
|
||||
///////// COMPRESSION COMPLETE. TIME TO DECOMPRESS AND COMPARE
|
||||
|
||||
println!("COMPRESSED: {compressed_bytes:?}");
|
||||
//
|
||||
// let cli = Cli::parse();
|
||||
//
|
||||
//
|
||||
// match cli.command {
|
||||
// Commands::Compress { input } => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user