Etterna 0.74.4
Loading...
Searching...
No Matches
RageFileDriverDeflate.h
1/* RageFileObjInflate - decompress streams compressed with "deflate"
2 * compression. */
3
4#ifndef RAGE_FILE_DRIVER_DEFLATE_H
5#define RAGE_FILE_DRIVER_DEFLATE_H
6
7#include "RageFileBasic.h"
8
9using z_stream = struct z_stream_s;
10
12{
13 public:
14 /* By default, pFile will not be freed. To implement GetFileSize(), the
15 * container format must store the file size. */
16 RageFileObjInflate(RageFileBasic* pFile, int iUncompressedSize);
18 ~RageFileObjInflate() override;
19 int ReadInternal(void* pBuffer, size_t iBytes) override;
20 int WriteInternal(const void* /* pBuffer */, size_t /* iBytes */) override
21 {
22 SetError("Not implemented");
23 return -1;
24 }
25 int SeekInternal(int iOffset) override;
26 int GetFileSize() const override { return m_iUncompressedSize; }
27 int GetFD() override { return m_pFile->GetFD(); }
28 RageFileObjInflate* Copy() const override;
29
30 void DeleteFileWhenFinished() { m_bFileOwned = true; }
31
32 private:
33 int m_iUncompressedSize;
34 RageFileBasic* m_pFile;
35 int m_iFilePos;
36 bool m_bFileOwned;
37
38 z_stream* m_pInflate;
39 enum
40 {
41 INBUFSIZE = 1024 * 4
42 };
43 char decomp_buf[INBUFSIZE], *decomp_buf_ptr;
44 int decomp_buf_avail;
45};
46
48{
49 public:
50 /* By default, pFile will not be freed. */
52 ~RageFileObjDeflate() override;
53
54 int GetFileSize() const override { return m_pFile->GetFileSize(); }
55 void DeleteFileWhenFinished() { m_bFileOwned = true; }
56
57 protected:
58 int ReadInternal(void* /* pBuffer */, size_t /* iBytes */) override
59 {
60 SetError("Not implemented");
61 return -1;
62 }
63 int WriteInternal(const void* pBuffer, size_t iBytes) override;
64 int FlushInternal() override;
65
66 RageFileBasic* m_pFile;
67 z_stream* m_pDeflate;
68 bool m_bFileOwned;
69};
70
72{
73 public:
75 int Start();
76 int Finish();
77
78 private:
79 int m_iDataStartOffset;
80};
81
83GunzipFile(RageFileBasic* pFile, std::string& sError, uint32_t* iCRC32);
84
85/* Quick helpers: */
86void
87GzipString(const std::string& sIn, std::string& sOut);
88bool
89GunzipString(const std::string& sIn,
90 std::string& sOut,
91 std::string& sError); // returns false on CRC, etc. error
92
93#endif
Definition RageFileBasic.h:10
Definition RageFileDriverDeflate.h:48
Definition RageFileDriverDeflate.h:72
Definition RageFileDriverDeflate.h:12
Definition RageFileBasic.h:66