working version

This commit is contained in:
2026-07-05 18:23:01 +03:00
parent b655e450c2
commit d9ea4356de
3 changed files with 51 additions and 62 deletions
Generated
+1 -42
View File
@@ -2,12 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 version = 4
[[package]]
name = "adler2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]] [[package]]
name = "anstream" name = "anstream"
version = "1.0.0" version = "1.0.0"
@@ -129,31 +123,12 @@ dependencies = [
"windows-sys 0.59.0", "windows-sys 0.59.0",
] ]
[[package]]
name = "crc32fast"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511"
dependencies = [
"cfg-if",
]
[[package]] [[package]]
name = "encode_unicode" name = "encode_unicode"
version = "1.0.0" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
[[package]]
name = "flate2"
version = "1.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c"
dependencies = [
"crc32fast",
"miniz_oxide",
]
[[package]] [[package]]
name = "futures-core" name = "futures-core"
version = "0.3.32" version = "0.3.32"
@@ -188,7 +163,7 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
name = "imploder" name = "imploder"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"flate2", "clap",
"pklib", "pklib",
"rawzip", "rawzip",
] ]
@@ -229,16 +204,6 @@ version = "0.2.186"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
[[package]]
name = "miniz_oxide"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
dependencies = [
"adler2",
"simd-adler32",
]
[[package]] [[package]]
name = "number_prefix" name = "number_prefix"
version = "0.4.0" version = "0.4.0"
@@ -310,12 +275,6 @@ version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
[[package]]
name = "simd-adler32"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "703d5c7ef118737c72f1af64ad2f6f8c5e1921f818cdcb97b8fe6fc69bf66214"
[[package]] [[package]]
name = "slab" name = "slab"
version = "0.4.12" version = "0.4.12"
+8 -1
View File
@@ -4,6 +4,13 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
flate2 = "1.1.9" clap = "4.6.1"
pklib = "0.2.0" pklib = "0.2.0"
rawzip = "0.4.4" rawzip = "0.4.4"
[profile.release]
codegen-units = 1
lto = true
strip = true
panic = 'abort'
opt-level = 'z'
+42 -19
View File
@@ -1,41 +1,61 @@
use std::{fs::File, io::{Read, Write}}; use std::{fs::{self, File}, io::{Read, Seek, Write}, time::UNIX_EPOCH};
use flate2;
use pklib; use pklib;
use rawzip::{ZipArchiveWriter, time::ZipDateTime}; use rawzip::{ZipArchiveWriter, time::ZipDateTime};
use clap::{Parser, Subcommand};
fn implode_test() -> Result<(), Box<dyn std::error::Error>> { const AFTER_TEST: &str = "
let data = b"Hello, world!"; Examples:
let modification_time = ZipDateTime::from_unix(1783257786); imploder directory/ out.zip
please note that the contents of the \"directory\" will be at the root of the archive
";
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[clap(after_help = AFTER_TEST)]
struct Args {
directory: String,
output_archive: String
}
fn implode_test(input_dir: String, output_archive: String) -> Result<(), Box<dyn std::error::Error>> {
let mut output = Vec::new(); let mut output = Vec::new();
let mut archive = rawzip::ZipArchiveWriter::new(&mut output); let mut archive = rawzip::ZipArchiveWriter::new(&mut output);
let (mut entry, config) = archive.new_file("test.txt") let mut file_list = Vec::new();
.last_modified(modification_time) let dir_heh = std::fs::read_dir(input_dir)?;
.compression_method(rawzip::CompressionMethod::Terse)
.start()?;
let encoder = pklib::implode::ImplodeWriter::new(&mut entry, pklib::CompressionMode::Binary, pklib::DictionarySize::Size2K)?; for file_path in dir_heh {
let shit = file_path.unwrap().path().display().to_string();
file_list.push(shit);
}
let mut writer = config.wrap(encoder); for mut file in file_list {
let mut curr_file = File::open(&file)?;
let mut buf: Vec<u8> = Vec::new();
let byte_count = curr_file.read_to_end(&mut buf)?;
std::io::copy(&mut &data[..], &mut writer)?; file = String::from(file.split('\\').last().unwrap());
//println!("{}: {}", file, byte_count);
let mod_time_unix = curr_file.metadata()?.modified()?.duration_since(UNIX_EPOCH)?.as_secs();
let mod_time2 = ZipDateTime::from_unix(mod_time_unix.cast_signed());
println!("processing {}...", file);
process_file(&mut archive, &file.as_str(), mod_time2, &buf)?;
}
let (_, descriptor) = writer.finish()?;
let compressed = entry.finish(descriptor)?;
archive.finish()?; archive.finish()?;
println!("{:?}", output);
{ {
let mut file = File::create("output.zip")?; let mut file = File::create(output_archive)?;
file.write_all(output.as_slice())?; file.write_all(output.as_slice())?;
} }
Ok::<(), Box<dyn std::error::Error>>(()) Ok::<(), Box<dyn std::error::Error>>(())
} }
fn process_file(mut archive: ZipArchiveWriter<&mut Vec<u8>>, filename: &str, modification_time: ZipDateTime, data) -> Result<(), Box<dyn std::error::Error>> fn process_file(archive: &mut ZipArchiveWriter<&mut Vec<u8>>, filename: &str, modification_time: ZipDateTime, data: &[u8]) -> Result<(), Box<dyn std::error::Error>>
{ {
let (mut entry, config) = archive.new_file(filename) let (mut entry, config) = archive.new_file(filename)
.last_modified(modification_time) .last_modified(modification_time)
@@ -49,12 +69,15 @@ fn process_file(mut archive: ZipArchiveWriter<&mut Vec<u8>>, filename: &str, mod
std::io::copy(&mut &data[..], &mut writer)?; std::io::copy(&mut &data[..], &mut writer)?;
let (_, descriptor) = writer.finish()?; let (_, descriptor) = writer.finish()?;
let compressed = entry.finish(descriptor)?;
Ok::<(), Box<dyn std::error::Error>>(()) Ok::<(), Box<dyn std::error::Error>>(())
} }
fn main() -> Result<(), Box<dyn std::error::Error>> { fn main() -> Result<(), Box<dyn std::error::Error>> {
implode_test(); let args = Args::parse();
implode_test(args.directory, args.output_archive);
Ok::<(), Box<dyn std::error::Error>>(()) Ok::<(), Box<dyn std::error::Error>>(())
} }