From 3be51018c9d192100388f03ea85e23c2ea58cf62 Mon Sep 17 00:00:00 2001 From: Reece Date: Sun, 11 Jul 2021 12:36:15 +0100 Subject: [PATCH] [-] Remove Flush from public compression interface [+] Improved base block [de]compression objects --- .../Aurora/Compression/ICompressionStream.hpp | 6 ----- .../Aurora/Compression/StreamProcessor.hpp | 2 +- Source/Compression/BlockCompressor.cpp | 23 ++++++++++++++++--- Source/Compression/BlockCompressor.hpp | 9 +++++++- Source/Compression/BlockDecompressor.cpp | 6 ++++- Source/Compression/Compression.hpp | 2 +- Source/Compression/StreamCompression.cpp | 1 - 7 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Include/Aurora/Compression/ICompressionStream.hpp b/Include/Aurora/Compression/ICompressionStream.hpp index 75f54de4..76322cd3 100644 --- a/Include/Aurora/Compression/ICompressionStream.hpp +++ b/Include/Aurora/Compression/ICompressionStream.hpp @@ -15,10 +15,4 @@ namespace Aurora::Compression virtual std::pair Ingest(AuUInt32 input) = 0; virtual bool Read(void * /*opt*/, AuUInt32 &len, bool ingestUntilEOS = true) = 0; }; - - class ICompressionStreamEx : public ICompressionStream - { - public: - virtual void Flush() = 0; - }; } \ No newline at end of file diff --git a/Include/Aurora/Compression/StreamProcessor.hpp b/Include/Aurora/Compression/StreamProcessor.hpp index 8a247cba..140894ff 100644 --- a/Include/Aurora/Compression/StreamProcessor.hpp +++ b/Include/Aurora/Compression/StreamProcessor.hpp @@ -12,5 +12,5 @@ namespace Aurora::Compression { AUKN_SHARED_API(Decompressor, ICompressionStream, Aurora::IO::IStreamReader *reader, ECompresionType type); - AUKN_SHARED_API(Compressor, ICompressionStreamEx, Aurora::IO::IStreamReader *reader, const CompressionInfo &info); + AUKN_SHARED_API(Compressor, ICompressionStream, Aurora::IO::IStreamReader *reader, const CompressionInfo &info); } \ No newline at end of file diff --git a/Source/Compression/BlockCompressor.cpp b/Source/Compression/BlockCompressor.cpp index 72c28948..ab66f256 100644 --- a/Source/Compression/BlockCompressor.cpp +++ b/Source/Compression/BlockCompressor.cpp @@ -16,28 +16,45 @@ namespace Aurora::Compression { + std::pair BaseStreamDeflate::Ingest(AuUInt32 input) + { + auto ingest = IngestImpl(input); + _count += ingest.first; + return ingest; + } + bool BaseStreamDeflate::Read(void * /*opt*/ buffer, AuUInt32 &len, bool ingestUntilError) { + if (_count != _lastCount) + { + Flush(); + } + if (ingestUntilError) { while (this->_outbuffer.size() < len) { if (Ingest(4096).second == 0) { + if (this->_outbuffer.size()) + { + break; + } + return false; } } } - return StreamRead(buffer, len, this->_outbuffer); + return !buffer || StreamRead(buffer, len, this->_outbuffer); } - AUKN_SYM ICompressionStreamEx *CompressorNew(IO::IStreamReader *reader, const CompressionInfo &info) + AUKN_SYM ICompressionStream *CompressorNew(IO::IStreamReader *reader, const CompressionInfo &info) { return nullptr; } - AUKN_SYM void CompressorRelease(ICompressionStreamEx * stream) + AUKN_SYM void CompressorRelease(ICompressionStream * stream) { SafeDelete(stream); } diff --git a/Source/Compression/BlockCompressor.hpp b/Source/Compression/BlockCompressor.hpp index 506a773d..83aff843 100644 --- a/Source/Compression/BlockCompressor.hpp +++ b/Source/Compression/BlockCompressor.hpp @@ -9,15 +9,22 @@ namespace Aurora::Compression { - class BaseStreamDeflate : public ICompressionStreamEx + class BaseStreamDeflate : public ICompressionStream { public: virtual ~BaseStreamDeflate() { } + + virtual std::pair IngestImpl(AuUInt32 input); + virtual void Flush() = 0; + virtual bool Init(Aurora::IO::IStreamReader *reader, const CompressionInfo &info) = 0; bool Read(void * /*opt*/ buffer, AuUInt32 &len, bool ingestUntilError) override; + std::pair Ingest(AuUInt32 input) override; protected: + AuUInt32 _count {}; + AuUInt32 _lastCount {}; AuList _outbuffer; }; } \ No newline at end of file diff --git a/Source/Compression/BlockDecompressor.cpp b/Source/Compression/BlockDecompressor.cpp index 4f94f840..23a02e1c 100644 --- a/Source/Compression/BlockDecompressor.cpp +++ b/Source/Compression/BlockDecompressor.cpp @@ -24,12 +24,16 @@ namespace Aurora::Compression { if (Ingest(4096).second == 0) { + if (this->_outbuffer.size()) + { + break; + } return false; } } } - return StreamRead(buffer, len, this->_outbuffer); + return !buffer || StreamRead(buffer, len, this->_outbuffer); } class ZSTDInflate : public BaseStream diff --git a/Source/Compression/Compression.hpp b/Source/Compression/Compression.hpp index 6cf8b1cd..67bd0911 100644 --- a/Source/Compression/Compression.hpp +++ b/Source/Compression/Compression.hpp @@ -12,7 +12,7 @@ namespace Aurora::Compression static const AuUInt64 kChunkSize = 4096; // This is acommon prolog required by BlockCompressors and BlockDecompressors. dw about it. - static inline bool StreamRead(void * /*opt*/ buffer, AuUInt32 &len, AuList &vec) + static inline bool StreamRead(void * buffer, AuUInt32 &len, AuList &vec) { len = std::min(AuUInt32(vec.size()), len); if (len == 0) return false; diff --git a/Source/Compression/StreamCompression.cpp b/Source/Compression/StreamCompression.cpp index 740e1399..bf3215b2 100644 --- a/Source/Compression/StreamCompression.cpp +++ b/Source/Compression/StreamCompression.cpp @@ -437,7 +437,6 @@ namespace Aurora::Compression std::shared_ptr inBuf(new char[size], std::default_delete()); std::shared_ptr outBuf(new char[size], std::default_delete()); - AuUInt32 inputStat = 0, outputStat = 0; while (true)