AuroraRuntime/Source/Compression/AuBlockCompressor.cpp

112 lines
2.6 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuBlockCompressor.cpp
Date: 2021-6-17
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "AuCompression.hpp"
#include "AuBlockCompressor.hpp"
#include "AuBaseStream.hpp"
#if defined(_AUHAS_ZSTD)
#include "Compressors/ZSTDCompressor.hpp"
#endif
#if defined(_AUHAS_ZLIB)
#include "Compressors/DeflateCompressor.hpp"
#endif
#if defined(_AUHAS_LZ4)
#include "Compressors/LZ4Compressor.hpp"
#endif
#if defined(_AUHAS_BZIP2)
#include "Compressors/BZip2Compressor.hpp"
#endif
#if defined(_AUHAS_BROTLI)
#include "Compressors/BrotliCompressor.hpp"
#endif
#if defined(_AUHAS_LIBLZMA)
#include "Compressors/LZMACompressor.hpp"
#endif
namespace Aurora::Compression
{
AUKN_SYM ICompressionStream *CompressorNew(const AuSPtr<IO::IStreamReader> &pReader, const CompressInfo &ref)
{
CompressInfo info = ref;
BaseStream *pRet {};
AuInt8 bits {};
if (!pReader)
{
SysPushErrorArg("Missing deflated stream pReader");
return nullptr;
}
switch (info.type)
{
#if defined(_AUHAS_ZSTD)
case ECompressionType::eZSTD:
pRet = _new ZSTDDeflate(info);
break;
#endif
case ECompressionType::eBZIP2:
#if defined(_AUHAS_BZIP2)
pRet = _new BZIPDeflate(info);
break;
#endif
#if defined(_AUHAS_LZ4)
case ECompressionType::eLZ4:
pRet = _new LZ4Deflate(info);
break;
#endif
#if defined(_AUHAS_BROTLI)
case ECompressionType::eBrotli:
pRet = _new BrotliDeflate(info);
break;
#endif
#if defined(_AUHAS_LIBLZMA)
case ECompressionType::eLZMA:
pRet = _new LZMADeflate(info);
break;
#endif
#if defined(_AUHAS_ZLIB)
case ECompressionType::eDeflate:
case ECompressionType::eZip:
case ECompressionType::eGZip:
if (!CompressionLevelFromExternalApi(info, bits))
{
return {};
}
pRet = _new ZIPDeflate(info, bits);
break;
#endif
default:
pRet = nullptr;
break;
}
if (pRet)
{
if (!pRet->Init(pReader))
{
delete pRet;
pRet = nullptr;
}
}
return pRet;
}
AUKN_SYM void CompressorRelease(ICompressionStream *pStream)
{
AuSafeDelete<BaseStream *>(pStream);
}
}