1 /******************************************************************************/ 2 /* Mednafen - Multi-system Emulator */ 3 /******************************************************************************/ 4 /* ZLInflateFilter.h: 5 ** Copyright (C) 2014-2016 Mednafen Team 6 ** 7 ** This program is free software; you can redistribute it and/or 8 ** modify it under the terms of the GNU General Public License 9 ** as published by the Free Software Foundation; either version 2 10 ** of the License, or (at your option) any later version. 11 ** 12 ** This program is distributed in the hope that it will be useful, 13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 ** GNU General Public License for more details. 16 ** 17 ** You should have received a copy of the GNU General Public License 18 ** along with this program; if not, write to the Free Software Foundation, Inc., 19 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef __MDFN_ZLINFLATEFILTER_H 23 #define __MDFN_ZLINFLATEFILTER_H 24 25 #include <mednafen/Stream.h> 26 27 #include <zlib.h> 28 29 namespace Mednafen 30 { 31 32 class ZLInflateFilter : public Stream 33 { 34 public: 35 36 enum class FORMAT 37 { 38 RAW = 0, // Raw inflate 39 ZLIB = 1, // zlib format 40 GZIP = 2, // gzip format 41 AUTO_ZGZ = 3 // zlib or gzip, autodetect 42 }; 43 44 ZLInflateFilter(Stream *source_stream, const std::string& vfcontext, FORMAT df, uint64 csize, uint64 ucs = ~(uint64)0, uint64 ucrc32 = ~(uint64)0); 45 virtual ~ZLInflateFilter() override; 46 virtual uint64 read(void *data, uint64 count, bool error_on_eos = true) override; 47 virtual void write(const void *data, uint64 count) override; 48 virtual void seek(int64 offset, int whence) override; 49 virtual uint64 tell(void) override; 50 virtual uint64 size(void) override; 51 virtual void close(void) override; 52 virtual uint64 attributes(void) override; 53 virtual void truncate(uint64 length) override; 54 virtual void flush(void) override; 55 56 private: 57 58 uint64 read_real(void *data, uint64 count, bool error_on_eos); 59 60 Stream* ss; 61 const uint64 ss_startpos; 62 const uint64 ss_boundpos; 63 uint64 ss_pos; 64 65 z_stream zs; 66 uint8 buf[8192]; 67 68 uint64 position; 69 uint64 target_position; 70 uint64 uc_size; 71 72 uint32 running_crc32; 73 const uint64 expected_crc32; 74 75 std::string vfcontext; 76 }; 77 78 /* 79 class GZIPReadFilter : public ZLInflateFilter 80 { 81 public: 82 INLINE GZIPReadFilter(Stream* source_stream) : ZLInflateFilter(source_stream, "", FORMAT::GZIP, ~(uint64)0); 83 84 } 85 */ 86 87 } 88 #endif 89