Coder Social home page Coder Social logo

lucadillenburg / file-compression Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 21.58 MB

File compression algorithms: Huffman Compression Algorithm and Lempel-Ziv-Welch Compression Algorithm.

License: BSD 3-Clause "New" or "Revised" License

Java 68.60% Kotlin 6.21% Makefile 1.47% C 23.16% Shell 0.56%
file-compression huffman-compression-algorithm lzw-compression

file-compression's Introduction

File Compression

Set of file compression algorithms.

Algorithms

  1. Huffman Compression Algorithm
  2. Lempel-Ziv-Welch Compression Algorithm

Huffman Compression Algorithm

This is algorithm is based uppon having the most common bytes in a file being represented using less than 8 bits. In this case, this is achieved using a binary tree that has to be written to the compressed file. Check out a visual representation of the algorithm below: Huffman Compression For more information you can access: https://www.geeksforgeeks.org/huffman-coding-greedy-algo-3/.

Run

cd huffman
./compile #compile
./huffman compress file #run compress
./huffman decompress compressedFile #run decompress

Example

You can find some examples in the examples directory:

  • Book (examples/book)

    The ls -l commands shows as follows:

     -rw-r--r-- your_user_name your_group 25.6KB Jun 25 22:44 compressed.huff
     -rw-r--r-- your_user_name your_group 46.3KB Jun 25 22:44 original_file.txt
    

    This represents a 44.7% percent compression rate.


Lempel-Ziv-Welch-Compression-Algorithm

This algorithm is based a group of bits that can store more than one or more bytes. An entry table is generated with the bytes that have already been read so when the same sequence is read again it will be substituted to the associated code in the entry table. A really important thing is that the entry table doesn't have to be written in the compressed file since it can be generated again by the decompressor.

For more info you can access: https://www.geeksforgeeks.org/lzw-lempel-ziv-welch-compression-technique/ .

Run

cd lzw
make
./lzw compress file #run compress
./lzw decompress compressedFile #run decompress

Example

You can find some examples in the examples directory:

  • Book (examples/book)

    The ls -l commands shows as follows:

     -rw-r--r-- your_user_name your_group 24.7KB Jun 25 22:44 compressed_lzw
     -rw-r--r-- your_user_name your_group 46.3KB Jun 25 22:44 original_file.txt
    

    This represents a 46.7% percent compression rate.

Implementation Limitations

  • Size

    Since in this implementation the number of bits per code is fixed in 16 bits, the maximum number of elements in the entry table is 32767. Therefore, the algorithm may not work with files that are larger than 50kB (this will depend on the number of elements in the dictionary). However, the LZW algorithm can be implemented to support a larger range of files (from the smallest to the largest ones).

  • Extension

    In this implementation, the compressed file doesn't contain the extension of the original file. However, this can be achieved rather easily by adding the extension string as the first bytes of the file.

file-compression's People

Contributors

lucadillenburg avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.