Finished the algorithm for packing and unpacking files

This commit is contained in:
Valentin Popov 2024-01-06 03:48:19 +04:00
parent 58b6314dec
commit cec2ad2c62
2 changed files with 7 additions and 2 deletions

View File

@ -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<u8> = Vec::new();
// Пишем первый тип файла

View File

@ -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];