Reece Wilson
267c2216b0
(...missing send) [+] AuIO::Buffer::ViewReader [+] AuIO::Buffer::ViewSeekableReadable [+] AuIO::Buffer::ViewWriter [*] Clean up AuCompression [*[ AuLog messages must always crunch for memory [*] Various bug fixes [*] Refactor+clean up
96 lines
2.3 KiB
C++
96 lines
2.3 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
|
|
|
|
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_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);
|
|
}
|
|
} |