This class decompresses compressed(.huf) files to its original form. More...
#include <Decompressor.h>
Classes | |
struct | fileInfo |
Structure to hold file metadata. More... | |
Public Member Functions | |
Decompressor () | |
~Decompressor () | |
void | decompressFile (const std::string &infileName) |
Decompresses the compressed(.huf) file to its original form. More... | |
Private Member Functions | |
void | clear () |
Resets all the attributes for next decompression operation. More... | |
void | deleteTree (BinNode *node) |
Frees all heap storage associated with the Huffman Tree. More... | |
void | readHeader (const std::string &infileName, std::ifstream &infile) |
Reads the header section from compressed file. More... | |
BinNode * | readTree (std::ifstream &reader) |
Reads the entire Huffman tree in to the file header section using a pre-order traversal algorithm. More... | |
void | writeIntoFile (const std::string &infileName) |
Decodes encoded characters using the tree obtained from header section. More... | |
Private Attributes | |
Queue< fileInfo > | files |
Queue of input file(s) to be decompressed. More... | |
std::ifstream | infile |
Instance of ifstream class for reading encoded characters from compressed file. More... | |
BinNode * | rootNode |
Root node for Huffman tree. More... | |
This class decompresses compressed(.huf) files to its original form.
It decompresses those files and folders which was compressed using Huffman Compression Algorithm.
Definition at line 23 of file Decompressor.h.
Decompressor::Decompressor | ( | ) |
Definition at line 3 of file Decompressor.cpp.
Decompressor::~Decompressor | ( | ) |
Definition at line 5 of file Decompressor.cpp.
|
private |
Resets all the attributes for next decompression operation.
Definition at line 9 of file Decompressor.cpp.
void Decompressor::decompressFile | ( | const std::string & | infileName | ) |
Decompresses the compressed(.huf) file to its original form.
infileName | compressed file path to be decompressed. |
Definition at line 134 of file Decompressor.cpp.
|
private |
Frees all heap storage associated with the Huffman Tree.
Definition at line 15 of file Decompressor.cpp.
|
private |
Reads the header section from compressed file.
Header section of compressed file contains tree and other metaData required during decompression. Meta data includes number of input files, each file size and file path
Read total number of files
Read total number of characters in each file, filename and directories
Definition at line 44 of file Decompressor.cpp.
|
private |
Reads the entire Huffman tree in to the file header section using a pre-order traversal algorithm.
when the program reads a bit 1, it can read the next 8 bits and wrap the char in a binary leaf node. When the program reads a bit 0, it create a new internal node and connect the two nodes as left and right child.
Definition at line 24 of file Decompressor.cpp.
|
private |
Decodes encoded characters using the tree obtained from header section.
Traverses the tree and on reaching the leaf node, write the character present in leaf node to output file till all the characters are decoded.
If output file size becomes equal to the fileSize known from file header section, it flush and closes the file and creates a new output file from the files queue till it becomes empty.
Definition at line 83 of file Decompressor.cpp.
Queue of input file(s) to be decompressed.
Definition at line 42 of file Decompressor.h.
|
private |
Instance of ifstream class for reading encoded characters from compressed file.
Definition at line 45 of file Decompressor.h.
|
private |