My Project
 
Loading...
Searching...
No Matches
HuffmanDecoder Class Reference

Handles reading a binary-encoded file, reconstructing the Huffman codes, and decoding the data. More...

#include <HuffmanDecoder.hpp>

Collaboration diagram for HuffmanDecoder:
Collaboration graph

Public Member Functions

vector< uint8_t > decodeFile (const string &filenameIn, const string &filenameOut)
 Decodes a file and writes the decoded output to another file.
 
vector< uint8_t > decodeFile (const string &filenameIn)
 Decodes an input file and returns the decoded contents.
 
vector< uint8_t > decodeVector (const vector< uint8_t > &vector)
 Decodes a Huffman-encoded byte vector in memory.
 

Private Member Functions

void readCodes ()
 Reads the Huffman header and code mappings from the encoded file.
 
vector< uint8_t > readMessage ()
 Reads and decodes the Huffman-encoded message from the input file.
 
vector< uint8_t > decodeVec (const vector< uint8_t > &buffer)
 Decodes a buffer of raw Huffman-encoded bytes into original data.
 

Private Attributes

ifstream inFile
 Input file stream from which the encoded data is read.
 
unordered_map< uint32_t, uint8_t > code
 Maps Huffman codes (represented as integers) to original byte values.
 
uint64_t current_position
 Tracks the current byte position in the input file for reading code maps and data.
 
uint8_t last_bit_to_read
 Specifies how many bits in the last byte are valid and should be read.
 

Detailed Description

Handles reading a binary-encoded file, reconstructing the Huffman codes, and decoding the data.

Member Function Documentation

◆ decodeFile() [1/2]

vector< uint8_t > HuffmanDecoder::decodeFile ( const string & filenameIn)

Decodes an input file and returns the decoded contents.

Parameters
filenameInThe name of the input file to decode.
Returns
The decoded data as a byte vector.
Here is the call graph for this function:

◆ decodeFile() [2/2]

vector< uint8_t > HuffmanDecoder::decodeFile ( const string & filenameIn,
const string & filenameOut )

Decodes a file and writes the decoded output to another file.

Parameters
filenameInThe name of the encoded input file.
filenameOutThe name of the output file to write the decoded data.
Returns
The decoded data as a byte vector.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ decodeVec()

vector< uint8_t > HuffmanDecoder::decodeVec ( const vector< uint8_t > & buffer)
private

Decodes a buffer of raw Huffman-encoded bytes into original data.

Parameters
bufferThe encoded data buffer.
Returns
A vector of decoded bytes.
Here is the caller graph for this function:

◆ decodeVector()

vector< uint8_t > HuffmanDecoder::decodeVector ( const vector< uint8_t > & vector)

Decodes a Huffman-encoded byte vector in memory.

Parameters
vectorThe encoded byte vector.
Returns
The decoded byte vector.
Here is the call graph for this function:

◆ readCodes()

void HuffmanDecoder::readCodes ( )
private

Reads the Huffman header and code mappings from the encoded file.

Here is the caller graph for this function:

◆ readMessage()

vector< uint8_t > HuffmanDecoder::readMessage ( )
private

Reads and decodes the Huffman-encoded message from the input file.

Returns
A vector of decoded bytes.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ code

unordered_map<uint32_t, uint8_t> HuffmanDecoder::code
private

Maps Huffman codes (represented as integers) to original byte values.

◆ current_position

uint64_t HuffmanDecoder::current_position
private

Tracks the current byte position in the input file for reading code maps and data.

◆ inFile

ifstream HuffmanDecoder::inFile
private

Input file stream from which the encoded data is read.

◆ last_bit_to_read

uint8_t HuffmanDecoder::last_bit_to_read
private

Specifies how many bits in the last byte are valid and should be read.


The documentation for this class was generated from the following files: