aboutsummaryrefslogtreecommitdiff
path: root/core/compress.c
blob: df61123d68fdfe62a2e22b1db37f6cf41b834860 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
void salis_deflate(z_stream *strm, size_t size, Bytef *in, Bytef *out) {
    assert(strm);
    assert(size);
    assert(in);
    assert(out);

    strm->zalloc = NULL;
    strm->zfree = NULL;
    strm->opaque = NULL;

    deflateInit(strm, Z_DEFAULT_COMPRESSION);

    strm->avail_in = size;
    strm->avail_out = size;
    strm->next_in = in;
    strm->next_out = out;

    deflate(strm, Z_FINISH);
}

void salis_deflate_end(z_stream *strm) {
    assert(strm);

    deflateEnd(strm);
}

void salis_inflate(z_stream *strm, size_t avail_in, size_t size, Bytef *in, Bytef *out) {
    assert(strm);
    assert(avail_in);
    assert(size);
    assert(in);
    assert(out);

    strm->next_in = in;
    strm->avail_in = avail_in;
    strm->zalloc = NULL;
    strm->zfree = NULL;
    strm->opaque = NULL;

    inflateInit(strm);

    strm->avail_out = size;
    strm->next_out = out;

#if defined(NDEBUG)
    inflate(strm, Z_FINISH);
#else
    assert(inflate(strm, Z_FINISH));
#endif
}

void salis_inflate_end(z_stream *strm) {
    assert(strm);

    inflateEnd(strm);
}