Skip to content

bridgetbroyles/huffman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 

Repository files navigation

Huffman Compressor/Decompressor

This project implements a bit-level file compression and decompression system using Huffman coding in Java. Huffman coding is a lossless compression algorithm that assigns shorter binary codes to more frequent bytes and longer codes to less frequent ones. This implementation has achieved up to 60% size reduction on test files.

Features

  • Huffman tree construction based on input byte frequency
  • Efficient compression using binary encoding of characters
  • Accurate decompression by reconstructing the original tree
  • Custom bit-level input/output classes for compact storage

How It Works

Compression

  1. Read the input file and calculate the frequency of each byte.
  2. Construct a Huffman tree using a priority queue.
  3. Generate a map of characters to their corresponding binary codes.
  4. Write a header that stores the Huffman tree structure.
  5. Encode the input data using the generated codes and write it as a stream of bits.

Decompression

  1. Read the file header and reconstruct the Huffman tree.
  2. Use the tree to decode the compressed bit stream.
  3. Write the decoded bytes to an output file.

Project Structure

HuffmanCompressor/
│
├── HuffmanCompressor.java       // Compression logic
├── HuffmanDecompressor.java     // Decompression logic
├── HuffmanNode.java             // Tree node structure
├── BitInputStream.java          // Bit-level file input
├── BitOutputStream.java         // Bit-level file output
└── README.md

Compilation

javac *.java

Usage

Compress a file

java HuffmanCompressor input.txt compressed.huff

Decompress a file

java HuffmanDecompressor compressed.huff output.txt

Results

  • Achieved up to 60% reduction in file size depending on content redundancy
  • Effective on plain text and other compressible file types

Requirements

  • Java SE 8 or higher
  • No external libraries required

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages