[+] ICompressionStream::ToStreamReader

This commit is contained in:
Reece Wilson 2023-10-24 17:14:54 +01:00
parent 7c65affc76
commit 69188d8c1e
4 changed files with 34 additions and 6 deletions

View File

@ -82,5 +82,11 @@ namespace Aurora::Compression
* @return
*/
virtual AuOptional<AuString> GetLastErrorString() = 0;
/**
* @brief
* @return
*/
virtual IO::IStreamReader *ToStreamReader() = 0;
};
}

View File

@ -227,4 +227,9 @@ namespace Aurora::Compression
{
return false;
}
IO::IStreamReader *BaseStream::ToStreamReader()
{
return &this->reader_;
}
}

View File

@ -8,12 +8,18 @@
#pragma once
#include "AuIngestableReadBase.hpp"
#include <Source/IO/Adapters/AuIOAdapterCompression.hpp>
namespace Aurora::Compression
{
struct BaseStream : ICompressionStream, protected IngestableReadBase
struct BaseStream :
ICompressionStream,
protected IngestableReadBase
{
inline BaseStream(AuUInt32 bufferSize = 4096 * 64) : _outbufferOwned(bufferSize, true), uBufferSize_(bufferSize)
inline BaseStream(AuUInt32 bufferSize = 4096 * 64) :
_outbufferOwned(bufferSize, true),
uBufferSize_(bufferSize),
reader_(AuUnsafeRaiiToShared(this))
{
SetBuffer({});
}
@ -48,6 +54,8 @@ namespace Aurora::Compression
virtual bool Flush() override;
virtual bool Finish() override;
virtual IO::IStreamReader *ToStreamReader() override;
bool IsValid();
AuSPtr<Memory::ByteBuffer> GetBuffer();
@ -61,7 +69,7 @@ namespace Aurora::Compression
protected:
virtual AuStreamReadWrittenPair_t Ingest_s(AuUInt32 dwBytesFromUnprocessedInputSource) = 0;
IO::Adapters::CompressionStreamReader reader_;
AuSPtr<Memory::ByteBuffer> pOutputBuffer_;
AuWPtr<Memory::ByteBuffer> wpInBuffer_;
AuSPtr<AuIO::IStreamWriter> pOutputBufferInterface_;

View File

@ -25,7 +25,14 @@ namespace Aurora::IO::Adapters
EStreamError CompressionStreamReader::IsOpen()
{
return this->bErrored_ ? EStreamError::eErrorEndOfStream : EStreamError::eErrorNone;
if (this->pCompressionStream->GetLastError())
{
return EStreamError::eErrorGenericFault;
}
return this->bErrored_ ?
EStreamError::eErrorEndOfStream :
EStreamError::eErrorNone;
}
EStreamError CompressionStreamReader::Read(const Memory::MemoryViewStreamWrite &parameters)
@ -67,7 +74,7 @@ namespace Aurora::IO::Adapters
if (!this->pCompressionStream->GoBackByProcessedN(this->uOffset - offset))
{
SysPushErrorIO("Negative compression seek out of bounds");
return EStreamError::eErrorStreamInterrupted;
return EStreamError::eErrorOutOfBounds;
}
}
else
@ -75,7 +82,7 @@ namespace Aurora::IO::Adapters
if (!this->pCompressionStream->GoForwardByProcessedN(offset - this->uOffset))
{
SysPushErrorIO("Positive compression seek out of bounds");
return EStreamError::eErrorStreamInterrupted;
return EStreamError::eErrorOutOfBounds;
}
}
@ -100,11 +107,13 @@ namespace Aurora::IO::Adapters
AUKN_SYM AuSPtr<IStreamReader> NewCompressionReadAdapter(const AuSPtr<Compression::ICompressionStream> &pCompresionStream)
{
SysCheckArgNotNull(pCompresionStream, {});
return AuMakeShared<CompressionStreamReader>(pCompresionStream);
}
AUKN_SYM AuSPtr<ISeekingReader> NewCompressionSeekingAdapter(const AuSPtr<Compression::ICompressionStream> &pCompresionStream)
{
SysCheckArgNotNull(pCompresionStream, {});
return AuMakeShared<CompressionSeekingReader>(pCompresionStream);
}
}