/Shafa-CD

File Compressor written in C using both Shannon Fano and RLE algorithms

Primary LanguageCApache License 2.0Apache-2.0

GitHub top language

What is Shafa?

Shafa is a free and open-source program made for Lossless files' compression written in C (2020/21).
It is OS independent and some modules are multithread executed if running on Windows or POSIX-compliant (allowing pthreads).

Uses two algorithms for compression:

  • RLE
  • Shannon Fano with blocks of length 1 (K=1).

For RLE's decompression a .freq file is needed along with the .rle file.
For Shannon Fano's decompression a .cod file is needed along with .shaf.
(All these files are generated by the program)

Modules:

  • F ( RLE compression and Frequencies calculation )
  • T ( Codes calculation using Shannon-Fano's algorithm )
  • C ( Shannon-Fano compression )
  • D ( RLE and Shannon-Fano decompression )

SETUP - *NIX

gcc -o shafa $(find ./src -name '*.c' -or -name '*.h') -O3 -Wno-format -pthread

SETUP - WINDOWS

gcc -o shafa src/*.c src/*.h src/*/*.c src/*/*.h src/*/*/*.c src/*/*/*.h -O3 -Wno-format

How to execute?

Open terminal where the created executable shafa is located and type the following:

Windows:

  • shafa.exe <file> <options>

*NIX:

  • ./shafa <file> <options>

CLI Options:

-m <module>      :  Executes respective module (Can be executed more than one module if possible)
-b <K/m/M>       :  Blocks size for compression (default: K)
-c <r/f>         :  Forces execution (r -> RLE's compress | f -> Original file's frequencies)
-d <s/r>         :  Only executes a specific decompression (s -> Shannon-Fano's algorithm | r -> RLE's algorithm)
--no-multithread :  Disables multithread 

Blocks Size:

  • K = 640 KiB
  • m = 8 MiB
  • M = 64 MiB

Note: Multithread was only implemented in modules C and D (the ones that cost the most)