AuroraRuntime/Source/Compression/BlockCompressor.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

94 lines
2.1 KiB
C++

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