Skip to content

ishan-karmakar/compressor-zig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Compressor in C++

A compressor/decompressor using Huffman coding

How It Works

The compressor follows the following steps:

  • Read the input file(s)
  • Generate frequencies of each character
  • Generate a huffman tree from the frequencies
  • Write huffman tree to output file
  • Read input file(s) again
  • Get corresponding bits from huffman tree
  • Write bits to output file

The decompressor works in a similar way:

  • Read input file (compressed)
  • Read huffman tree from input file
  • Read bits from input file
  • Get corresponding character from huffman tree
  • Write character to output file

Build

Building is extremely easy with Zig.

$ zig build -Doptimize=ReleaseSafe

How to Use

Compressing a Directory

Say you have a directory structure like this:

├── directory_to_compress
│   ├── file1.txt
│   ├── file2.txt
│   ├── file3.txt

Compress the directory like this:

./compressor directory_to_compress/ # Creates a file called directory_to_compress.cmp
./decompressor directory_to_compress.cmp # Recreates the directory_to_compress directory

About

A compressor/decompressor using Huffman coding

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages