mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-06 03:07:48 +00:00
Move XChunk processors to ZoneCommon
This commit is contained in:
33
src/ZoneCommon/Zone/XChunk/XChunkProcessorInflate.cpp
Normal file
33
src/ZoneCommon/Zone/XChunk/XChunkProcessorInflate.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include "XChunkProcessorInflate.h"
|
||||
|
||||
#include <zlib.h>
|
||||
#include <zutil.h>
|
||||
|
||||
#include "XChunkException.h"
|
||||
|
||||
size_t XChunkProcessorInflate::Process(int streamNumber, const uint8_t* input, const size_t inputLength, uint8_t* output, const size_t outputBufferSize)
|
||||
{
|
||||
z_stream stream{};
|
||||
stream.zalloc = Z_NULL;
|
||||
stream.zfree = Z_NULL;
|
||||
stream.opaque = Z_NULL;
|
||||
|
||||
auto ret = inflateInit2(&stream, -DEF_WBITS);
|
||||
if (ret != Z_OK)
|
||||
throw XChunkException("Initializing inflate failed.");
|
||||
|
||||
stream.avail_in = inputLength;
|
||||
stream.next_in = input;
|
||||
stream.avail_out = outputBufferSize;
|
||||
stream.next_out = output;
|
||||
|
||||
ret = inflate(&stream, Z_FULL_FLUSH);
|
||||
if (ret != Z_STREAM_END)
|
||||
throw XChunkException("Zone has invalid or unsupported compression. Inflate failed");
|
||||
|
||||
const size_t outputSize = stream.total_out;
|
||||
|
||||
inflateEnd(&stream);
|
||||
|
||||
return outputSize;
|
||||
}
|
||||
Reference in New Issue
Block a user