[-] Remove Flush from public compression interface
[+] Improved base block [de]compression objects
This commit is contained in:
parent
955578cf8e
commit
3be51018c9
@ -15,10 +15,4 @@ namespace Aurora::Compression
|
||||
virtual std::pair<AuUInt32, AuUInt32> Ingest(AuUInt32 input) = 0;
|
||||
virtual bool Read(void * /*opt*/, AuUInt32 &len, bool ingestUntilEOS = true) = 0;
|
||||
};
|
||||
|
||||
class ICompressionStreamEx : public ICompressionStream
|
||||
{
|
||||
public:
|
||||
virtual void Flush() = 0;
|
||||
};
|
||||
}
|
@ -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);
|
||||
}
|
@ -16,28 +16,45 @@
|
||||
|
||||
namespace Aurora::Compression
|
||||
{
|
||||
std::pair<AuUInt32, AuUInt32> 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<BaseStreamDeflate *>(stream);
|
||||
}
|
||||
|
@ -9,15 +9,22 @@
|
||||
|
||||
namespace Aurora::Compression
|
||||
{
|
||||
class BaseStreamDeflate : public ICompressionStreamEx
|
||||
class BaseStreamDeflate : public ICompressionStream
|
||||
{
|
||||
public:
|
||||
virtual ~BaseStreamDeflate() { }
|
||||
|
||||
|
||||
virtual std::pair<AuUInt32, AuUInt32> 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<AuUInt32, AuUInt32> Ingest(AuUInt32 input) override;
|
||||
|
||||
protected:
|
||||
AuUInt32 _count {};
|
||||
AuUInt32 _lastCount {};
|
||||
AuList<AuUInt8> _outbuffer;
|
||||
};
|
||||
}
|
@ -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
|
||||
|
@ -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<AuUInt8> &vec)
|
||||
static inline bool StreamRead(void * buffer, AuUInt32 &len, AuList<AuUInt8> &vec)
|
||||
{
|
||||
len = std::min(AuUInt32(vec.size()), len);
|
||||
if (len == 0) return false;
|
||||
|
@ -437,7 +437,6 @@ namespace Aurora::Compression
|
||||
std::shared_ptr<char> inBuf(new char[size], std::default_delete<char[]>());
|
||||
std::shared_ptr<char> outBuf(new char[size], std::default_delete<char[]>());
|
||||
|
||||
|
||||
AuUInt32 inputStat = 0, outputStat = 0;
|
||||
|
||||
while (true)
|
||||
|
Loading…
Reference in New Issue
Block a user