Important
Development of this project has been migrated to: https://codeberg.org/GlitchedPolygons/ccrush
This is what you want to use if you just want to compress some stuff in C. Hence, C-Crush. You're crushing data with C. Especially if you're in a rush, when you just want to call 1 function and (de)compress stuff.
It's a wrapper around Zlib, which implements the DEFLATE algorithm as defined in the RFC1951 standard.
git clone --recursive https://codeberg.org/GlitchedPolygons/ccrush.git
Just add CCRUSH as a git submodule to your project (e.g. into some lib/ or deps/ folder inside your project's repo; {repo_root}/lib/ is used here in the following example).
git submodule add https://codeberg.org/GlitchedPolygons/ccrush.git lib/ccrush
git submodule update --init --recursive
If you don't want to use git submodules, you can also start vendoring a specific version of ccrush by copying its full repo content into the folder where you keep your project's external libraries/dependencies.
If you use CMake you can just add_subdirectory(path_to_submodule) and then target_link_libraries(your_project PRIVATE ccrush) inside your CMakeLists.txt file.
If you don't wanna grab the pre-built binaries from the GitHub releases page (and don't want to add ccrush as a subdirectory inside your CMake project), you can also do the following:
bash build.shThis works on Windows too: just use the Git Bash for Windows CLI!
If the build succeeds, you should have a new .tar.gz file inside the build/ directory.
NOTE: If you use the shared library in your project on Windows, remember to #define CCRUSH_DLL 1 before including ccrush.h! Maybe even set it as a pre-processor definition. Otherwise the header won't have the necessary __declspec(dllimport) declarations!
mkdir -p build && cd build
cmake -DBUILD_SHARED_LIBS=Off -Dccrush_PACKAGE=On -DCMAKE_BUILD_TYPE=Release ..
cmake --build . --config Releaseconst uint8_t* data = "Your special string or byte array to compress here!";
const size_t data_length = strlen(data);
uint8_t* compressed_data = NULL;
size_t compressed_data_length = 0;
int r = ccrush_compress(data, data_length, 64, 8, &compressed_data, &compressed_data_length);
if (r != 0)
{
fprintf(stderr, "Compression failed! \"ccrush_compress\" returned: %d", r);
}
ccrush_free(compressed_data);const uint8_t* compressed_data = "{{ These should be your compressed bytes written by the ccrush_compress function }}";
const size_t compressed_data_length = 256; // This should be the exact length of the compressed data array as written by the ccrush_compress function!
uint8_t* data = NULL;
size_t data_length = 0;
int r = ccrush_decompress(compressed_data, compressed_data_length, 64, &data, &data_length);
if (r != 0)
{
fprintf(stderr, "Decompression failed! \"ccrush_decompress\" returned: %d", r);
}
ccrush_free(data);