From cec2ad2c6217dda5ae0b6332ca594930167af8c5 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sat, 6 Jan 2024 03:48:19 +0400 Subject: Finished the algorithm for packing and unpacking files --- packer/src/main.rs | 7 ++++++- unpacker/src/main.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packer/src/main.rs b/packer/src/main.rs index ae4e02a..a5526e3 100644 --- a/packer/src/main.rs +++ b/packer/src/main.rs @@ -53,7 +53,7 @@ fn pack(input: String, output: String) { for (index, item) in list.iter().enumerate() { // Открываем дескриптор файла - let path = format!("{}/{}", input, item.name); + let path = format!("{}/{}.{}", input, item.name, item.index); let file = File::open(path).unwrap(); let metadata = file.metadata().unwrap(); @@ -138,6 +138,11 @@ fn pack(input: String, output: String) { list_buffer.extend(element_buffer); } + // Выравнивание буфера + while content_buffer.len() % 8 != 0 { + content_buffer.push(0); + } + let mut header_buffer: Vec = Vec::new(); // Пишем первый тип файла diff --git a/unpacker/src/main.rs b/unpacker/src/main.rs index 9d27385..2a84688 100644 --- a/unpacker/src/main.rs +++ b/unpacker/src/main.rs @@ -102,7 +102,7 @@ fn unpack(input: String, output: String) { // Распаковываем файлы в директорию for element in &list { - let path = format!("{}/{}", output, element.name); + let path = format!("{}/{}.{}", output, element.name, element.index); let mut file = File::create(path).unwrap(); let mut file_buffer = vec![0u8; element.size as usize]; -- cgit v1.2.3