-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileHandler.h
More file actions
36 lines (29 loc) · 1.07 KB
/
Copy pathFileHandler.h
File metadata and controls
36 lines (29 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma once
#include <string>
#include <cstdint>
namespace FileHandler {
// Read entire file as raw bytes
std::string readFile(const std::string& path);
// Write raw bytes to file
void writeFile(const std::string& path, const std::string& data);
/*
* Compressed file format (.bin):
*
* [4 bytes] magic: "HUFF"
* [4 bytes] tree_size (uint32, big-endian)
* [tree_size bytes] serialized Huffman tree
* [4 bytes] padding_bits (uint32) — how many trailing bits to ignore
* [4 bytes] original_size (uint32) — original file size in bytes
* [rest] packed bit data (8 bits per byte)
*/
// Pack bit string → bytes and write full compressed file
void writeCompressed(const std::string& path,
const std::string& treeData,
const std::string& bits,
uint32_t originalSize);
// Read compressed file → treeData + bits
void readCompressed(const std::string& path,
std::string& treeData,
std::string& bits,
uint32_t& originalSize);
} // namespace FileHandler