Skip to content

Latest commit

 

History

History
66 lines (38 loc) · 1.52 KB

File metadata and controls

66 lines (38 loc) · 1.52 KB

File Compressor in C

A minimal command-line file compressor / decompressor written in C using Raylib’s CompressData() and DecompressData() utilities.

The program reads a file into memory, compresses or decompresses the raw bytes, and writes the result to a new file.

This project focuses on learning low-level file I/O, memory management, and command-line argument handling in C.

Tutorial: Video Tutorial Available (by Daniel Hirsch)


Features

  • Compress files into .compressed format
  • Decompress files using the -d flag
  • Simple CLI interface
  • Works on raw binary data
  • Uses Raylib’s built-in compression utilities

How It Works

  1. Reads command-line arguments to determine compression or decompression mode
  2. Opens the input file using fopen()
  3. Determines file size using fseek() and ftell()
  4. Loads the entire file into memory using malloc()
  5. Uses Raylib’s CompressData() or DecompressData()
  6. Writes processed bytes to a new output file using fputc()

Build

Make sure Raylib is installed.

Compile using:

gcc compressor.c -o compress $(pkg-config --cflags --libs raylib)

Compress a file:

./compress file.txt

This creates:

file.txt.compressed

Decompress a file:

./compress -d file.txt.compressed

This creates:

file.txt.compressed.decompressed

Notes

  • The entire file is loaded into memory before compression

  • Output files are generated by appending a suffix to the original filename