341
|
1 // Simplifies use of zlib for deflating data
|
|
2
|
|
3 // File_Extractor 0.4.0
|
|
4 #ifndef ZLIB_INFLATER_H
|
|
5 #define ZLIB_INFLATER_H
|
|
6
|
|
7 #include "blargg_common.h"
|
|
8 #include "zlib.h"
|
|
9
|
|
10 class Zlib_Inflater {
|
|
11 public:
|
|
12
|
|
13 // Data reader callback
|
|
14 typedef blargg_err_t (*callback_t)( void* user_data, void* out, long* count );
|
|
15
|
|
16 // Begin inflation using specified mode and fill buffer using read callback.
|
|
17 // Default buffer is 16K and filled to 4K, or specify buf_size for custom
|
|
18 // buffer size and to read that much file data. Using mode_auto selects
|
|
19 // between mode_copy and mode_ungz by examining first two bytes of buffer.
|
|
20 enum mode_t { mode_copy, mode_ungz, mode_raw_deflate, mode_auto };
|
|
21 blargg_err_t begin( mode_t, callback_t, void* user_data, long buf_size = 0 );
|
|
22
|
|
23 // True if begin() has been called with mode_ungz or mode_raw_deflate
|
|
24 bool deflated() const { return deflated_; }
|
|
25
|
|
26 // Read/inflate at most *count_io bytes into out and set *count_io to actual
|
|
27 // number of bytes read (less than requested if end of deflated data is reached).
|
|
28 // Keeps buffer full with user-provided callback.
|
|
29 blargg_err_t read( void* out, long* count_io, callback_t, void* user_data );
|
|
30
|
|
31 // End inflation and free memory
|
|
32 void end();
|
|
33
|
|
34 private:
|
|
35 // noncopyable
|
|
36 Zlib_Inflater( const Zlib_Inflater& );
|
|
37 Zlib_Inflater& operator = ( const Zlib_Inflater& );
|
|
38
|
|
39 public:
|
|
40 Zlib_Inflater();
|
|
41 ~Zlib_Inflater();
|
|
42 private:
|
|
43 z_stream_s zbuf;
|
|
44 blargg_vector<unsigned char> buf;
|
|
45 bool deflated_;
|
|
46 };
|
|
47
|
|
48 #endif
|