AuroraRuntime/Source/Compression/BlockCompressor.cpp
Reece Wilson ad4c18abe7 [+] Missing LZ4 compressor
[*] Various compression related bugs under the 1/4th of the AuCompression platform related to compression stream objects. Now all 1/4ths match up.
2022-07-20 21:09:40 +01:00

88 lines
2.0 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> &reader, const CompressionInfo &ref)
{
CompressionInfo info = ref;
BaseStream *ret {};
AuInt8 bits;
switch (info.type)
{
#if defined(_AUHAS_ZSTD)
case ECompressionType::eZSTD:
ret = _new ZSTDDeflate(info);
break;
#endif
case ECompressionType::eBZIP2:
#if defined(_AUHAS_BZIP2)
ret = _new BZIPDeflate(info);
break;
#endif
#if defined(_AUHAS_LZ4)
case ECompressionType::eLZ4:
ret = new LZ4Deflate(info);
break;
#endif
#if defined(_AUHAS_ZLIB)
case ECompressionType::eDeflate:
case ECompressionType::eZip:
case ECompressionType::eGZip:
if (!CompressionLevelFromExternalApi(info, bits))
{
return {};
}
ret = _new ZIPDeflate(info, bits);
break;
#endif
default:
ret = nullptr;
break;
}
if (ret)
{
if (!ret->Init(reader))
{
delete ret;
ret = nullptr;
}
}
return ret;
}
AUKN_SYM void CompressorRelease(ICompressionStream *stream)
{
AuSafeDelete<BaseStream *>(stream);
}
}