-
-
Save andresgutierrez/e3cd207d71d180821e50 to your computer and use it in GitHub Desktop.
This file contains 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 <string.h> | |
#include <blosc.h> | |
#define SIZE 72 | |
#define SHAPE {100,100,100} | |
#define CHUNKSHAPE {1,100,100} | |
int main(){ | |
static char data[SIZE]; | |
static char data_out[SIZE]; | |
static char data_dest[SIZE]; | |
int isize = SIZE*sizeof(char), osize = SIZE*sizeof(char); | |
int dsize = SIZE*sizeof(char), csize; | |
int i; | |
for(i=0; i<SIZE; i++){ | |
data[i] = 'A'; | |
} | |
// Register the filter with the library | |
printf("Blosc version info: %s (%s)\n", | |
BLOSC_VERSION_STRING, BLOSC_VERSION_DATE); | |
// Initialize the Blosc compressor | |
blosc_init(); | |
// Compress with clevel=5 and shuffle active | |
csize = blosc_compress(5, 1, sizeof(char), isize, data, data_out, osize); | |
if (csize < 0) { | |
printf("Compression error. Error code: %d\n", csize); | |
return csize; | |
} | |
printf("Compression: %d -> %d (%.1fx)\n", isize, csize, (1.*isize) / csize); | |
// Decompress | |
dsize = blosc_decompress(data_out, data_dest, dsize); | |
if (dsize < 0) { | |
printf("Decompression error. Error code: %d\n", dsize); | |
return dsize; | |
} | |
printf("Decompression succesful!\n"); | |
// After using it, destroy the Blosc environment | |
blosc_destroy(); | |
for(i=0;i<SIZE;i++){ | |
if(data[i] != data_dest[i]) { | |
printf("Decompressed data differs from original!\n"); | |
return -1; | |
} | |
} | |
printf("Succesful roundtrip!\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment