Jamie Reece Wilson
4ce49941ff
[+] SysCheckNotNull [+] SysCheckRetExpNotNull [+] SysCheckRetExpNotNullMemory
119 lines
3.6 KiB
C++
119 lines
3.6 KiB
C++
/***
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuIOAdapterCompression.cpp
|
|
Date: 2022-6-6
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include <Aurora/IO/IOExperimental.hpp>
|
|
#include "AuIOAdapterCompression.hpp"
|
|
|
|
namespace Aurora::IO::Adapters
|
|
{
|
|
CompressionStreamReader::CompressionStreamReader(const AuSPtr<Compression::ICompressionStream> &pCompressionStream) :
|
|
pCompressionStream(pCompressionStream)
|
|
{
|
|
|
|
}
|
|
|
|
CompressionSeekingReader::CompressionSeekingReader(const AuSPtr<Compression::ICompressionStream> &pCompressionStream)
|
|
: pCompressionStream(pCompressionStream)
|
|
{
|
|
|
|
}
|
|
|
|
EStreamError CompressionStreamReader::IsOpen()
|
|
{
|
|
if (this->pCompressionStream->GetLastError())
|
|
{
|
|
return EStreamError::eErrorGenericFault;
|
|
}
|
|
|
|
return this->bErrored_ ?
|
|
EStreamError::eErrorEndOfStream :
|
|
EStreamError::eErrorNone;
|
|
}
|
|
|
|
EStreamError CompressionStreamReader::Read(const Memory::MemoryViewStreamWrite ¶meters)
|
|
{
|
|
if (!this->pCompressionStream)
|
|
{
|
|
return EStreamError::eErrorStreamNotOpen;
|
|
}
|
|
|
|
auto pair = this->pCompressionStream->ReadEx(parameters, true);
|
|
|
|
if (pair == AuStreamReadWrittenPair_t{})
|
|
{
|
|
this->bErrored_ = true;
|
|
return EStreamError::eErrorEndOfStream;
|
|
}
|
|
|
|
parameters.outVariable = pair.second;
|
|
return EStreamError::eErrorNone;
|
|
}
|
|
|
|
void CompressionStreamReader::Close()
|
|
{
|
|
}
|
|
|
|
EStreamError CompressionSeekingReader::IsOpen()
|
|
{
|
|
return this->bErrored_ ?
|
|
EStreamError::eErrorEndOfStream :
|
|
EStreamError::eErrorNone;
|
|
}
|
|
|
|
EStreamError CompressionSeekingReader::ArbitraryRead(AuUInt offset, const Memory::MemoryViewStreamWrite ¶meters)
|
|
{
|
|
if (this->uOffset != offset)
|
|
{
|
|
if (this->uOffset > offset)
|
|
{
|
|
if (!this->pCompressionStream->GoBackByProcessedN(this->uOffset - offset))
|
|
{
|
|
SysPushErrorIO("Negative compression seek out of bounds");
|
|
return EStreamError::eErrorOutOfBounds;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!this->pCompressionStream->GoForwardByProcessedN(offset - this->uOffset))
|
|
{
|
|
SysPushErrorIO("Positive compression seek out of bounds");
|
|
return EStreamError::eErrorOutOfBounds;
|
|
}
|
|
}
|
|
|
|
this->uOffset = offset;
|
|
}
|
|
|
|
auto pair = this->pCompressionStream->ReadEx(parameters, true);
|
|
if (pair == AuStreamReadWrittenPair_t {})
|
|
{
|
|
this->bErrored_ = true;
|
|
return EStreamError::eErrorEndOfStream;
|
|
}
|
|
|
|
this->uOffset += pair.second;
|
|
parameters.outVariable = pair.second;
|
|
return EStreamError::eErrorNone;
|
|
}
|
|
|
|
void CompressionSeekingReader::Close()
|
|
{
|
|
}
|
|
|
|
AUKN_SYM AuSPtr<IStreamReader> NewCompressionReadAdapter(const AuSPtr<Compression::ICompressionStream> &pCompresionStream)
|
|
{
|
|
SysCheckArgNotNull(pCompresionStream, {});
|
|
SysCheckRetExpNotNullMemory(AuMakeShared<CompressionStreamReader>(pCompresionStream), {});
|
|
}
|
|
|
|
AUKN_SYM AuSPtr<ISeekingReader> NewCompressionSeekingAdapter(const AuSPtr<Compression::ICompressionStream> &pCompresionStream)
|
|
{
|
|
SysCheckArgNotNull(pCompresionStream, {});
|
|
SysCheckRetExpNotNullMemory(AuMakeShared<CompressionSeekingReader>(pCompresionStream), {});
|
|
}
|
|
} |