1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#include <assert.h>
#include <libdeflate.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
int main(int argc, char **argv)
{
struct libdeflate_decompressor *d;
struct libdeflate_compressor *c;
int ret;
int fd = open(argv[1], O_RDONLY);
struct stat stbuf;
assert(fd >= 0);
ret = fstat(fd, &stbuf);
assert(!ret);
char in[stbuf.st_size];
ret = read(fd, in, sizeof in);
assert(ret == sizeof in);
c = libdeflate_alloc_compressor(6);
d = libdeflate_alloc_decompressor();
char out[sizeof(in)];
char checkarray[sizeof(in)];
size_t csize = libdeflate_deflate_compress(c, in,sizeof in, out, sizeof out);
if (csize) {
enum libdeflate_result res;
res = libdeflate_deflate_decompress(d, out, csize, checkarray, sizeof in, NULL);
assert(!res);
assert(!memcmp(in, checkarray, sizeof in));
}
libdeflate_free_compressor(c);
libdeflate_free_decompressor(d);
return 0;
}
|