Huffman Zipper  v-1.0
Data Compression and Decompression using Greedy Huffman Algorithm
Decompressor.h
Go to the documentation of this file.
1 #pragma once
2 #include <iostream>
3 #include <stdexcept>
4 #include <fstream>
5 #include <string>
6 #include <bitset>
7 #include <chrono>
8 #include <filesystem>
9 
10 #include "Queue.h"
11 #include "HashMap.h"
12 #include "BinNode.h"
13 #include "Constants.h"
14 
15 namespace fs = std::filesystem;
16 
23 class Decompressor {
24 private:
25 
33  struct fileInfo {
34  unsigned int fileSize;
35  fs::path filePath;
37  fileInfo() :fileSize(0) {}
38  fileInfo(unsigned const int& fileSize, const fs::path& filePath) :fileSize(fileSize), filePath(filePath) {}
39  };
40 
43 
45  std::ifstream infile;
46 
49 
50 private:
51 
53  void clear();
54 
56  void deleteTree(BinNode* node);
57 
65  void readHeader(const std::string& infileName, std::ifstream& infile);
66 
75  BinNode* readTree(std::ifstream& reader);
76 
87  void writeIntoFile(const std::string& infileName);
88 
89 public:
90  Decompressor();
91  ~Decompressor();
92 
98  void decompressFile(const std::string& infileName);
99 };
This file exports the constants used in throughout the project.
This class models a node structure used for building Huffman Binary Tree.
Definition: BinNode.h:9
This class decompresses compressed(.huf) files to its original form.
Definition: Decompressor.h:23
void clear()
Resets all the attributes for next decompression operation.
Definition: Decompressor.cpp:9
std::ifstream infile
Instance of ifstream class for reading encoded characters from compressed file.
Definition: Decompressor.h:45
Queue< fileInfo > files
Queue of input file(s) to be decompressed.
Definition: Decompressor.h:42
void readHeader(const std::string &infileName, std::ifstream &infile)
Reads the header section from compressed file.
void deleteTree(BinNode *node)
Frees all heap storage associated with the Huffman Tree.
void decompressFile(const std::string &infileName)
Decompresses the compressed(.huf) file to its original form.
BinNode * rootNode
Root node for Huffman tree.
Definition: Decompressor.h:48
void writeIntoFile(const std::string &infileName)
Decodes encoded characters using the tree obtained from header section.
BinNode * readTree(std::ifstream &reader)
Reads the entire Huffman tree in to the file header section using a pre-order traversal algorithm.
This class models a linear structure called a Queue.
Definition: Queue.h:14
Structure to hold file metadata.
Definition: Decompressor.h:33
unsigned int fileSize
number of character in file.
Definition: Decompressor.h:34
fs::path filePath
path of file including filename and extension.
Definition: Decompressor.h:35
fileInfo(unsigned const int &fileSize, const fs::path &filePath)
Definition: Decompressor.h:38