mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Zero-sized compression fixes
This commit is contained in:
parent
46fbba9712
commit
61222f8525
2 changed files with 10 additions and 18 deletions
|
@ -11,16 +11,12 @@ namespace utils
|
|||
[CallingConvention(.Stdcall), CLink]
|
||||
extern static Span<uint8> Compression_Decompress(void* ptr, int size);
|
||||
|
||||
[CallingConvention(.Stdcall), CLink]
|
||||
extern static void Compression_Free(void* ptr);
|
||||
|
||||
public static Result<void> Compress(Span<uint8> inData, List<uint8> outData)
|
||||
{
|
||||
var outSpan = Compression_Compress(inData.Ptr, inData.Length);
|
||||
if ((outSpan.Length == 0) && (inData.Length != 0))
|
||||
return .Err;
|
||||
outData.AddRange(outSpan);
|
||||
Compression_Free(outSpan.Ptr);
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
|
@ -30,27 +26,24 @@ namespace utils
|
|||
if ((outSpan.Length == 0) && (inData.Length != 0))
|
||||
return .Err;
|
||||
outData.Insert(outData.Length, StringView((.)outSpan.Ptr, outSpan.Length));
|
||||
Compression_Free(outSpan.Ptr);
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
public static Result<void> Decompress(Span<uint8> inData, List<uint8> outData)
|
||||
{
|
||||
var outSpan = Compression_Decompress(inData.Ptr, inData.Length);
|
||||
if ((outSpan.Length == 0) && (inData.Length != 0))
|
||||
if (outSpan == default)
|
||||
return .Err;
|
||||
outData.AddRange(outSpan);
|
||||
Compression_Free(outSpan.Ptr);
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
public static Result<void> Decompress(Span<uint8> inData, String outData)
|
||||
{
|
||||
var outSpan = Compression_Decompress(inData.Ptr, inData.Length);
|
||||
if ((outSpan.Length == 0) && (inData.Length != 0))
|
||||
if (outSpan == default)
|
||||
return .Err;
|
||||
outData.Insert(outData.Length, StringView((.)outSpan.Ptr, outSpan.Length));
|
||||
Compression_Free(outSpan.Ptr);
|
||||
return .Ok;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
USING_NS_BF;
|
||||
|
||||
static TLSingleton<Array<uint8>> gCompression_TLDataReturn;
|
||||
|
||||
bool Compression::Compress(Span<uint8> inData, Array<uint8>& outData)
|
||||
{
|
||||
outData.Reserve(128);
|
||||
|
@ -65,7 +67,7 @@ bool Compression::Decompress(Span<uint8> inData, Array<uint8>& outData)
|
|||
zs.next_out = outData.mVals;
|
||||
zs.avail_out = outData.mAllocSize;
|
||||
|
||||
inflateInit(&zs, Z_BEST_COMPRESSION);
|
||||
inflateInit(&zs);
|
||||
|
||||
bool isDone = false;
|
||||
bool hadError = false;
|
||||
|
@ -101,8 +103,9 @@ bool Compression::Decompress(Span<uint8> inData, Array<uint8>& outData)
|
|||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
BF_EXPORT Span<uint8> BF_CALLTYPE Compression_Compress(void* ptr, int size)
|
||||
{
|
||||
Array<uint8> outData;
|
||||
{
|
||||
auto& outData = *gCompression_TLDataReturn.Get();
|
||||
outData.Reserve(128);
|
||||
if (!Compression::Compress(Span<uint8>((uint8*)ptr, size), outData))
|
||||
return Span<uint8>();
|
||||
uint8* outPtr = outData.mVals;
|
||||
|
@ -112,15 +115,11 @@ BF_EXPORT Span<uint8> BF_CALLTYPE Compression_Compress(void* ptr, int size)
|
|||
|
||||
BF_EXPORT Span<uint8> BF_CALLTYPE Compression_Decompress(void* ptr, int size)
|
||||
{
|
||||
Array<uint8> outData;
|
||||
auto& outData = *gCompression_TLDataReturn.Get();
|
||||
outData.Reserve(128);
|
||||
if (!Compression::Decompress(Span<uint8>((uint8*)ptr, size), outData))
|
||||
return Span<uint8>();
|
||||
uint8* outPtr = outData.mVals;
|
||||
outData.mVals = NULL;
|
||||
return Span<uint8>(outPtr, outData.mSize);
|
||||
}
|
||||
|
||||
BF_EXPORT void BF_CALLTYPE Compression_Free(void* ptr)
|
||||
{
|
||||
delete ptr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue