Oops from previous commit
[lsnes.git] / include / library / zlibstream.hpp
blobc447f8c0e37ccfcd04fa013320810250eb50c7c4
1 #ifndef _library__zlibstream__hpp__included__
2 #define _library__zlibstream__hpp__included__
4 #include <vector>
5 #include <list>
6 #include <cstdint>
7 #include <zlib.h>
8 #define ZLIB_PAGE_STORAGE 65500
10 /**
11 * Zlib stream.
13 struct zlibstream
15 /**
16 * Create new zlib stream.
18 * Parameter compression: The compression level.
20 zlibstream(unsigned compression);
21 /**
22 * Destroy zlib stream.
24 ~zlibstream();
25 /**
26 * Reset the stream, adding some initial data.
28 * Parameter data: The data to write (may be NULL if datalen=0).
29 * Parameter datalen: The length of data.
31 void reset(uint8_t* data, size_t datalen);
32 /**
33 * Write data into stream.
35 * Parameter data: The data to write.
36 * Parameter datalen: The length of data.
38 void write(uint8_t* data, size_t datalen);
39 /**
40 * Read the data as buffer.
42 * Parameter out: The buffer to write to.
44 void read(std::vector<char>& out);
45 /**
46 * Read the data so far as buffer and empty compressed data.
48 * This performs a sync flush.
50 * Parameter out: The buffer to write to.
52 void readsync(std::vector<char>& out);
53 /**
54 * Clear the output stream and add some uncompressed data.
56 * This is useful after doing readsync().
58 * Parameter data: The data to write (may be NULL if datalen=0).
59 * Parameter datalen: The length of data.
61 void adddata(uint8_t* data, size_t datalen);
62 /**
63 * Set flag.
65 * Parameter f: New flag value.
67 void set_flag(bool f);
68 /**
69 * Get flag.
71 * Returns: Flag value.
73 bool get_flag();
74 private:
75 struct page
77 uint8_t data[ZLIB_PAGE_STORAGE];
78 size_t used;
81 void _read(std::vector<char>& out, int mode);
82 void _reset(uint8_t* data, size_t datalen, bool doactually);
83 void flushpage(uint8_t* data, size_t datalen, int mode);
84 zlibstream(zlibstream&);
85 zlibstream& operator=(zlibstream&);
86 z_stream z;
87 size_t streamsize;
88 std::list<page> storage;
89 bool flag;
92 #endif