Last active
April 27, 2023 20:56
-
-
Save adsr/cc09d1438bc089befc665559a7091aa9 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
// gcc -g -O0 -Ilib -Llib test.c lib/libzstd.a -o test && ./test aaaaaaaaaaaa | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <zstd.h> | |
int main(int argc, char **argv) { | |
char *payload = argc > 1 ? argv[1] : "compress me"; | |
size_t payload_len = strlen(payload); | |
size_t compressed_size = ZSTD_compressBound(payload_len); | |
char *compressed = malloc(compressed_size); | |
size_t compressed_size_rv = ZSTD_compress((void*)compressed, compressed_size, (void *)payload, payload_len, 1); | |
size_t decompressed_size = 1; // ZSTD_getFrameContentSize(compressed, compressed_size); | |
if (decompressed_size == ZSTD_CONTENTSIZE_ERROR | |
|| decompressed_size == ZSTD_CONTENTSIZE_UNKNOWN) { | |
printf("ZSTD_CONTENTSIZE_ERROR or ZSTD_CONTENTSIZE_UNKNOWN\n"); | |
free(compressed); | |
return 0; | |
} | |
char *decompressed = malloc(decompressed_size); | |
size_t decompressed_size_rv = ZSTD_decompress((void*)decompressed, decompressed_size, (void*)compressed, compressed_size_rv); | |
if (decompressed_size_rv != payload_len) { | |
printf("ERR\n"); | |
} else { | |
printf("OK\n"); | |
} | |
free(compressed); | |
free(decompressed); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment