AuroraRuntime/Source/Compression/AuCompression.hpp
Reece Wilson 267c2216b0 [+] UDP over socket API via existing INetSrvDatagram layer
(...missing send)
[+] AuIO::Buffer::ViewReader
[+] AuIO::Buffer::ViewSeekableReadable
[+] AuIO::Buffer::ViewWriter
[*] Clean up AuCompression
[*[ AuLog messages must always crunch for memory
[*] Various bug fixes
[*] Refactor+clean up
2022-12-12 23:50:05 +00:00

100 lines
2.1 KiB
C++

/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: AuCompression.hpp
Date: 2021-6-17
Author: Reece
***/
#pragma once
namespace Aurora::Compression
{
static const AuUInt64 kChunkSize = 32 * 1024;
/// * compression type + bits -> internal zlib windowBits
static bool CompressionLevelFromExternalApi(const DecompressInfo &info, AuInt8 &out)
{
out = 0;
if (!info.bHasWindowbits)
{
if (info.alg == ECompressionType::eGZip)
{
out = 15 | 16;
}
else if (info.alg == ECompressionType::eDeflate)
{
out = -15;
}
else
{
out = 15;
return true;
}
}
if (info.uWindowBits < 0)
{
return {};
}
if (info.uWindowBits > 15)
{
return {};
}
if (info.alg == ECompressionType::eGZip)
{
out = info.uWindowBits | 16;
}
else if (info.alg == ECompressionType::eDeflate)
{
out = 0 - info.uWindowBits;
}
else
{
out = info.uWindowBits;
}
return true;
}
/// * compression type + bits -> internal zlib windowBits
static bool CompressionLevelFromExternalApi(const CompressInfo &info, AuInt8 &out)
{
out = 0;
if (!info.uWindowBits)
{
if (info.type == ECompressionType::eGZip)
{
out = 15 | 16;
}
else if (info.type == ECompressionType::eDeflate)
{
out = -15;
}
else
{
out = 15;
return true;
}
}
if (info.type == ECompressionType::eGZip)
{
out = info.uWindowBits | 16;
}
else if (info.type == ECompressionType::eDeflate)
{
out = 0 - info.uWindowBits;
}
else
{
out = info.uWindowBits;
}
return true;
}
}