Skip to content

HuffmanCoding is loseless file compression algo use for compressing Text , Image and other file compressioning

Notifications You must be signed in to change notification settings

HarshJainofficial/Huffman-coding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Huffman Coding Python Implementation

This Python implementation of Huffman Coding is based on the explanation provided in the YouTube video: Huffman Coding Python Implementation and the accompanying blog article by Bhrigu Srivastava.

Overview

Huffman Coding is a compression algorithm that assigns variable-length codes to input characters based on their frequencies, with more frequent characters receiving shorter codes. This implementation includes compress and decompress functions.

Demo Video and Blog Article

Getting Started

Follow these steps to test and run the program:

  1. Save or clone this repository.
  2. The repository includes a sample text file of size 715kB.
  3. Run the Python code useHuffman.py to compress and decompress the sample file.
    • Open your terminal and run: python3 useHuffman.py
  4. The above command will perform compression and decompression on the sample.txt file provided. Both the compressed and decompressed files will be present at the same location.
  5. To run the code for compression of any other text file, edit the path variable in the useHuffman.py file.

Note: For now, the decompress() function is to be called from the same object from which the compress() function was called, as the encoding information is stored in the data members of the object only.

Example Usage

# Import the HuffmanCoding class
from huffman_coding import HuffmanCoding

# Create an instance of HuffmanCoding
huffman = HuffmanCoding()

# Compress the input file
huffman.compress("sample.txt")

# Decompress the compressed file
huffman.decompress()





Creadit to @https://github.com/bhrigu123/huffman-coding

About

HuffmanCoding is loseless file compression algo use for compressing Text , Image and other file compressioning

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages