Skip to content

Instantly share code, notes, and snippets.

@putraxor
Created September 20, 2023 16:07
Show Gist options
  • Save putraxor/675c215e7c695bed5aac7ce8cafb6b7f to your computer and use it in GitHub Desktop.
Save putraxor/675c215e7c695bed5aac7ce8cafb6b7f to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <snappy-c.h>
// Fungsi C hanya menerima data input
char* compressData(const char* input) {
size_t inputLength = strlen(input);
size_t maxCompressedLength = snappy_max_compressed_length(inputLength);
char* compressedData = (char*)malloc(maxCompressedLength);
snappy_status status = snappy_compress(input, inputLength, compressedData, &maxCompressedLength);
if (status != SNAPPY_OK) {
free(compressedData);
return NULL; // Kembalikan NULL jika terjadi kesalahan kompresi
}
return compressedData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment