Files
smartservice_native/hdssd/huslib/Zlibex.h
T
2026-05-20 03:08:08 +09:00

66 lines
1.3 KiB
C

#ifndef ZLIB_EX__H_
#define ZLIB_EX__H_
#ifdef _WIN32
#pragma once
#endif
#include "zlib.h"
#ifdef _WIN32
#pragma comment(lib, "zlib.lib")
#endif
extern inline bool Gunzip(const char * pSrc, unsigned long nSrcSize, HDynamicArray<char> * pdaDst, unsigned long * pnDstSize)
{
if (nSrcSize == 0)
return false;
unsigned full_length = nSrcSize;
unsigned half_length = nSrcSize / 2;
unsigned uncompLength = full_length;
pdaDst->m_p = (char *)malloc(uncompLength + 8); // 8 : safety space for post process
z_stream strm;
strm.next_in = (Bytef *)pSrc;
strm.avail_in = nSrcSize;
strm.total_out = 0;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
bool done = false ;
if (inflateInit2(&strm, (16+MAX_WBITS)) != Z_OK)
return false;
while (!done)
{
if (strm.total_out >= uncompLength)
{
char * uncomp2 = (char *)malloc(uncompLength + half_length + 8); // 8 : safety space for post process
memcpy(uncomp2, pdaDst->m_p, uncompLength);
uncompLength += half_length;
pdaDst->Restruct(uncomp2);
}
strm.next_out = (Bytef *) (pdaDst->m_p + strm.total_out);
strm.avail_out = uncompLength - strm.total_out;
int err = inflate(&strm, Z_SYNC_FLUSH);
if (err == Z_STREAM_END)
done = true;
else if (err != Z_OK)
break;
}
if (inflateEnd(&strm) != Z_OK)
return false;
*pnDstSize = strm.total_out;
return true ;
}
#endif // ZLIB_EX__H_