90 lines
2.1 KiB
C++
90 lines
2.1 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> &reader, const DecompressInfo &ref)
|
|
{
|
|
DecompressInfo info = ref;
|
|
BaseStream * ret{};
|
|
AuInt8 bits;
|
|
bool hasBits;
|
|
|
|
switch (info.alg)
|
|
{
|
|
#if defined(_AUHAS_ZSTD)
|
|
case ECompressionType::eZSTD:
|
|
ret = _new ZSTDInflate(info);
|
|
break;
|
|
#endif
|
|
case ECompressionType::eBZIP2:
|
|
#if defined(_AUHAS_BZIP2)
|
|
ret = _new BZIPInflate(info);
|
|
#endif
|
|
break;
|
|
#if defined(_AUHAS_LZ4)
|
|
case ECompressionType::eLZ4:
|
|
ret = _new LZ4Inflate(info);
|
|
break;
|
|
#endif
|
|
#if defined(_AUHAS_ZLIB)
|
|
case ECompressionType::eDeflate:
|
|
case ECompressionType::eZip:
|
|
case ECompressionType::eGZip:
|
|
|
|
hasBits = CompressionLevelFromExternalApi(info, bits);
|
|
if (!hasBits && info.alg != ECompressionType::eZip)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
ret = _new ZIPInflate(info, hasBits, bits);
|
|
break;
|
|
#endif
|
|
default:
|
|
ret = nullptr;
|
|
break;
|
|
}
|
|
|
|
if (ret)
|
|
{
|
|
if (!ret->Init(reader))
|
|
{
|
|
delete ret;
|
|
ret = nullptr;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
AUKN_SYM void DecompressorRelease(ICompressionStream * stream)
|
|
{
|
|
AuSafeDelete<BaseStream *>(stream);
|
|
}
|
|
} |