Plasma Engine  2.0
Loading...
Searching...
No Matches
CompressedStreamZlib.h
1
2#pragma once
3
4#include <Foundation/Basics.h>
5#include <Foundation/Containers/DynamicArray.h>
6#include <Foundation/IO/Stream.h>
7
8#ifdef BUILDSYSTEM_ENABLE_ZLIB_SUPPORT
9
10struct z_stream_s;
11
14class PL_FOUNDATION_DLL plCompressedStreamReaderZip : public plStreamReader
15{
16public:
17 plCompressedStreamReaderZip();
18 ~plCompressedStreamReaderZip();
19
24 void SetInputStream(plStreamReader* pInputStream, plUInt64 uiInputSize);
25
30 virtual plUInt64 ReadBytes(void* pReadBuffer, plUInt64 uiBytesToRead) override; // [tested]
31
32private:
33 plUInt64 m_uiRemainingInputSize = 0;
34 bool m_bReachedEnd = false;
35 plDynamicArray<plUInt8> m_CompressedCache;
36 plStreamReader* m_pInputStream = nullptr;
37 z_stream_s* m_pZLibStream = nullptr;
38};
39
40
45class PL_FOUNDATION_DLL plCompressedStreamReaderZlib : public plStreamReader
46{
47public:
49 plCompressedStreamReaderZlib(plStreamReader* pInputStream); // [tested]
50
51 ~plCompressedStreamReaderZlib(); // [tested]
52
57 virtual plUInt64 ReadBytes(void* pReadBuffer, plUInt64 uiBytesToRead) override; // [tested]
58
59private:
60 bool m_bReachedEnd = false;
61 plDynamicArray<plUInt8> m_CompressedCache;
62 plStreamReader* m_pInputStream = nullptr;
63 z_stream_s* m_pZLibStream = nullptr;
64};
65
74class PL_FOUNDATION_DLL plCompressedStreamWriterZlib : public plStreamWriter
75{
76public:
78 enum Compression
79 {
80 Uncompressed = 0,
81 Fastest = 1,
82 Fast = 3,
83 Average = 5,
84 High = 7,
85 Highest = 9,
86 Default = Fastest
88 };
89
91 plCompressedStreamWriterZlib(plStreamWriter* pOutputStream, Compression ratio = Compression::Default); // [tested]
92
94 ~plCompressedStreamWriterZlib(); // [tested]
95
99 virtual plResult WriteBytes(const void* pWriteBuffer, plUInt64 uiBytesToWrite) override; // [tested]
100
107 plResult CloseStream(); // [tested]
108
110 plUInt64 GetUncompressedSize() const { return m_uiUncompressedSize; } // [tested]
111
118 plUInt64 GetCompressedSize() const { return m_uiCompressedSize; } // [tested]
119
124 virtual plResult Flush() override;
125
126private:
127 plUInt64 m_uiUncompressedSize = 0;
128 plUInt64 m_uiCompressedSize = 0;
129
130 plStreamWriter* m_pOutputStream = nullptr;
131 z_stream_s* m_pZLibStream = nullptr;
132
133 plDynamicArray<plUInt8> m_CompressedCache;
134};
135
136#endif // BUILDSYSTEM_ENABLE_ZLIB_SUPPORT
Definition DynamicArray.h:81
Interface for binary in (read) streams.
Definition Stream.h:22
virtual plUInt64 ReadBytes(void *pReadBuffer, plUInt64 uiBytesToRead)=0
Reads a raw number of bytes into the read buffer, this is the only method which has to be implemented...
Interface for binary out (write) streams.
Definition Stream.h:107
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54