Created
September 20, 2023 16:07
-
-
Save putraxor/675c215e7c695bed5aac7ce8cafb6b7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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