Skip to content

A Huffman Encoding File Compressor and Decompressor written in Go.

Notifications You must be signed in to change notification settings

soaresfabricio/huffman-encoding-compressor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Compressor and Decompressor written in Go

As part of my explorings with the Go language I decided to write a simple File Compressor, for it is the kind of project in which buffered reading, writing and seeking are staples (otherwise the compressed data may not preserve it's original state). Plus, I had to work with Go's pointers, errors and conditional structures.

I also played around with this neat progress bar package.

A little about Huffman Coding

This entropy encoding technique consists in creating a binary tree representation of the input data that can be stored and rebuilt later on.

  1. A list containing the symbols frequency (in case of files, symbols are bytes) is built.
  2. The list is then sorted. This can be done through a Heap.
  3. The following steps are to be repeated until there's no symbol left:
    1. Get the two symbols of smaller frequency from the list.
    2. Create a tree containing the two elements as children nodes.
    3. Create a parent node storing the sum of two children elements frequency.
    4. Add the parent element to the list, that must, after the addition, still have its order preserved.
    5. Delete the children nodes.
  4. A code word is then assigned to each element based on its path out of the root.
Usage
Compiling
$ go get
$ go build -o app.bin
Running
$ ./app.bin -c uncompressed compressed
$ ./app.bin -x compressed uncompressed

About

A Huffman Encoding File Compressor and Decompressor written in Go.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages