AuroraRuntime/Source/Compression/BlockCompressor.cpp
2022-03-18 04:30:39 +00: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 ECompresionType::eZSTD:
ret = _new ZSTDDeflate(info);
break;
#endif
case ECompresionType::eBZIP2:
#if defined(_AUHAS_BZIP2)
ret = _new BZIPDeflate(info);
break;
#endif
#if defined(_AUHAS_LZ4)
case ECompresionType::eLZ4:
///ret = new LZ4Deflate(info);
break;
#endif
#if defined(_AUHAS_ZLIB)
case ECompresionType::eDeflate:
case ECompresionType::eZip:
case ECompresionType::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);
}
}