You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
This is a binary patching and incremental downloading tool, similar to rsync or zsync. It aims to improve the large binary download processes that previously were served by robocopy (i.e. full packages produced by the build farm). The original code can be found in `//depot/usr/yuriy.odonnell/unsync`. This commit is a branch from the original location to preserve history. While the codebase is designed to be self-contained and does not depend on any engine libraries, it mostly follows the UE coding guidelines and can be built with UBT. Currently only Windows is supported, however the tool is expected to also work on Mac and Linux in the future. #rb Martin.Ridgers #preflight skip [CL 18993571 by Yuriy ODonnell in ue5-main branch]
60 lines
1.5 KiB
C++
60 lines
1.5 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "UnsyncCompression.h"
|
|
#include <zstd.h>
|
|
|
|
namespace unsync {
|
|
|
|
FBuffer
|
|
Compress(const uint8* Data, uint64 DataSize, int ZstdCompressionLevel)
|
|
{
|
|
FBuffer Result;
|
|
if (DataSize)
|
|
{
|
|
Result.Resize(ZSTD_compressBound(DataSize));
|
|
|
|
uint64 CompressedSize = ZSTD_compress(&Result[0], Result.Size(), Data, DataSize, ZstdCompressionLevel);
|
|
if (ZSTD_isError(CompressedSize))
|
|
{
|
|
const char* ZstdError = ZSTD_getErrorName(CompressedSize);
|
|
UNSYNC_ERROR(L"ZSTD_compress failed: %hs", ZstdError);
|
|
}
|
|
Result.Resize(CompressedSize);
|
|
}
|
|
return Result;
|
|
}
|
|
|
|
bool
|
|
Decompress(const uint8* InputData, uint64 InputDataSize, uint8* OutputData, uint64 OutputDataSize)
|
|
{
|
|
uint64 DecompressedSizeExpected = ZSTD_getDecompressedSize(InputData, InputDataSize);
|
|
if (OutputDataSize >= DecompressedSizeExpected)
|
|
{
|
|
uint64 DecompressedSizeActual = ZSTD_decompress(OutputData, OutputDataSize, InputData, InputDataSize);
|
|
return DecompressedSizeActual == OutputDataSize;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
FBuffer
|
|
Decompress(const uint8* Data, uint64 DataSize)
|
|
{
|
|
uint64 DecompressedSizeExpected = ZSTD_getDecompressedSize(Data, DataSize);
|
|
FBuffer Result(DecompressedSizeExpected);
|
|
uint64 DecompressedSizeActual = ZSTD_decompress(&Result[0], DecompressedSizeExpected, Data, DataSize);
|
|
if (DecompressedSizeExpected != DecompressedSizeActual)
|
|
{
|
|
Result.Clear();
|
|
}
|
|
return Result;
|
|
}
|
|
|
|
FBuffer
|
|
Decompress(const FBuffer& Buffer)
|
|
{
|
|
return Decompress(Buffer.Data(), Buffer.Size());
|
|
}
|
|
|
|
} // namespace unsync
|