-
Notifications
You must be signed in to change notification settings - Fork 1
/
Z.cpp
37 lines (30 loc) · 768 Bytes
/
Z.cpp
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
//
// Created by mydayyy on 8/12/18.
//
#include "Z.h"
Z::Z(std::ofstream *output, uInt chunkSize) {
this->output = output;
this->out = new unsigned char[chunkSize];
this->chunkSize = chunkSize;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
inflateInit2(&strm, 31);
}
Z::~Z() {
delete[] this->out;
}
int Z::inf(unsigned char *in, uInt inSize) {
int ret;
strm.avail_in = inSize;
strm.next_in = in;
do {
strm.avail_out = this->chunkSize;
strm.next_out = this->out;
ret = inflate(&strm, Z_SYNC_FLUSH);
output->write((char*) out, this->chunkSize - strm.avail_out);
} while(strm.avail_out == 0);
return ret;
}