AuroraRuntime/Source/Compression/BlockDecompressor.cpp
Reece Wilson 8844e8fe64 [+] AuCrypto::BCrypt
> GetForcedMinRounds
> GenSalt
> HashPW
> HashPWEx
> CheckPassword
> CheckPasswordEx
[*] Refactor AuCompression APIs
[*] Clean up AuTryConstructs
[+] Internal compression API for compression based interceptors
[+] Root-level input stream arg check for all compression apis (harden)
[*] Clean up AuCompression code
[+] Solar Designer / OpenWall blowfish crypt
[*] BlowCrypt: accept length input parameter
[*] Split locale into 2 source files
[-] Ugly comment from Open.Win32.cpp. TODO: Readd later. Might warn on empty string bc it makes sense given, "." and "/" normalizes to nothing, and memory pre-idc-if-drops are dropped siliently.
2022-09-15 20:48:50 +01:00

96 lines
2.3 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: BlockDecompressor.cpp
Date: 2021-6-17
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "Compression.hpp"
#include "BlockDecompressor.hpp"
#include "BaseStream.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);
}
}