AuroraRuntime/Source/Compression/AuBlockDecompressor.cpp
2023-03-12 21:03:47 +00:00

105 lines
2.5 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuBlockDecompressor.cpp
Date: 2021-6-17
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuCompression.hpp"
#include "AuBlockDecompressor.hpp"
#include "AuBaseStream.hpp"
#if defined(_AUHAS_ZSTD)
#include "Compressors/ZSTDDecompressor.hpp"
#endif
#if defined(_AUHAS_ZLIB)
#include "Compressors/DeflateDecompressor.hpp"
#endif
#if defined(_AUHAS_LZ4)
#include "Compressors/LZ4Decompressor.hpp"
#endif
#if defined(_AUHAS_BZIP2)
#include "Compressors/BZip2Decompressor.hpp"
#endif
#if defined(_AUHAS_BROTLI)
#include "Compressors/BrotliDecompressor.hpp"
#endif
namespace Aurora::Compression
{
AUKN_SYM ICompressionStream *DecompressorNew(const AuSPtr<IO::IStreamReader> &pReader, const DecompressInfo &ref)
{
DecompressInfo info = ref;
BaseStream *pRet {};
AuInt8 bits {};
bool bHasBits {};
if (!pReader)
{
SysPushErrorArg("Missing compressed stream pReader");
return nullptr;
}
switch (info.alg)
{
#if defined(_AUHAS_ZSTD)
case ECompressionType::eZSTD:
pRet = _new ZSTDInflate(info);
break;
#endif
case ECompressionType::eBZIP2:
#if defined(_AUHAS_BZIP2)
pRet = _new BZIPInflate(info);
#endif
break;
#if defined(_AUHAS_LZ4)
case ECompressionType::eLZ4:
pRet = _new LZ4Inflate(info);
break;
#endif
#if defined(_AUHAS_BROTLI)
case ECompressionType::eBrotli:
pRet = _new BrotliInflate(info);
break;
#endif
#if defined(_AUHAS_ZLIB)
case ECompressionType::eDeflate:
case ECompressionType::eZip:
case ECompressionType::eGZip:
bHasBits = CompressionLevelFromExternalApi(info, bits);
if (!bHasBits && info.alg != ECompressionType::eZip)
{
return {};
}
pRet = _new ZIPInflate(info, bHasBits, bits);
break;
#endif
default:
pRet = nullptr;
break;
}
if (pRet)
{
if (!pRet->Init(pReader))
{
delete pRet;
pRet = nullptr;
}
}
return pRet;
}
AUKN_SYM void DecompressorRelease(ICompressionStream *pStream)
{
AuSafeDelete<BaseStream *>(pStream);
}
}