File: compression.hpp

package info (click to toggle)
tippecanoe 2.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 148,236 kB
  • sloc: cpp: 44,069; ansic: 2,057; makefile: 454; perl: 129; python: 62; sh: 4
file content (58 lines) | stat: -rw-r--r-- 1,524 bytes parent folder | download | duplicates (2)
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
57
58
#ifdef __APPLE__
#define _DARWIN_UNLIMITED_STREAMS
#endif

#include <stdio.h>
#include <string>
#include <atomic>
#include <zlib.h>

struct decompressor {
	FILE *fp = NULL;
	z_stream zs;
	std::string buf;

	// from begin() to receiving end-of-stream
	bool within = false;

	decompressor(FILE *f) {
		fp = f;
		buf.resize(5000);

		zs.next_in = (Bytef *) buf.c_str();
		zs.avail_in = 0;
	}

	decompressor() {
	}

	void begin();
	int fread(void *p, size_t size, size_t nmemb, std::atomic<long long> *geompos);
	void end(std::atomic<long long> *geompos);
	int deserialize_ulong_long(unsigned long long *zigzag, std::atomic<long long> *geompos);
	int deserialize_long_long(long long *n, std::atomic<long long> *geompos);
	int deserialize_int(int *n, std::atomic<long long> *geompos);
	int deserialize_uint(unsigned *n, std::atomic<long long> *geompos);
};

struct compressor {
	FILE *fp = NULL;
	z_stream zs;

	compressor(FILE *f) {
		fp = f;
	}

	compressor() {
	}

	void begin();
	void end(std::atomic<long long> *fpos, const char *fname);
	int fclose();
	void fwrite_check(const char *p, size_t size, size_t nmemb, std::atomic<long long> *fpos, const char *fname);
	void serialize_ulong_long(unsigned long long val, std::atomic<long long> *fpos, const char *fname);

	void serialize_long_long(long long val, std::atomic<long long> *fpos, const char *fname);
	void serialize_int(int val, std::atomic<long long> *fpos, const char *fname);
	void serialize_uint(unsigned val, std::atomic<long long> *fpos, const char *fname);
};