COMMON: Add wrapper for inflating headerless zlib data
This commit is contained in:
parent
59200bf426
commit
f408456d14
2 changed files with 38 additions and 0 deletions
|
@ -49,6 +49,35 @@ bool uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long
|
||||||
return Z_OK == ::uncompress(dst, dstLen, src, srcLen);
|
return Z_OK == ::uncompress(dst, dstLen, src, srcLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool inflateZlibHeaderless(byte *dst, uint dstLen, const byte *src, uint srcLen) {
|
||||||
|
if (!dst || !dstLen || !src || !srcLen)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// Initialize zlib
|
||||||
|
z_stream stream;
|
||||||
|
stream.next_in = const_cast<byte *>(src);
|
||||||
|
stream.avail_in = srcLen;
|
||||||
|
stream.next_out = dst;
|
||||||
|
stream.avail_out = dstLen;
|
||||||
|
stream.zalloc = Z_NULL;
|
||||||
|
stream.zfree = Z_NULL;
|
||||||
|
stream.opaque = Z_NULL;
|
||||||
|
|
||||||
|
// Negative MAX_WBITS tells zlib there's no zlib header
|
||||||
|
int err = inflateInit2(&stream, -MAX_WBITS);
|
||||||
|
if (err != Z_OK)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
err = inflate(&stream, Z_SYNC_FLUSH);
|
||||||
|
if (err != Z_OK && err != Z_STREAM_END) {
|
||||||
|
inflateEnd(&stream);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
inflateEnd(&stream);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple wrapper class which can be used to wrap around an arbitrary
|
* A simple wrapper class which can be used to wrap around an arbitrary
|
||||||
* other SeekableReadStream and will then provide on-the-fly decompression support.
|
* other SeekableReadStream and will then provide on-the-fly decompression support.
|
||||||
|
|
|
@ -41,6 +41,15 @@ class WriteStream;
|
||||||
*/
|
*/
|
||||||
bool uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long srcLen);
|
bool uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long srcLen);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper around zlib's inflate functions. This function will call the
|
||||||
|
* necessary inflate functions to uncompress data compressed with deflate
|
||||||
|
* but *not* with the standard zlib header.
|
||||||
|
*
|
||||||
|
* @return true on success (Z_OK or Z_STREAM_END), false otherwise
|
||||||
|
*/
|
||||||
|
bool inflateZlibHeaderless(byte *dst, uint dstLen, const byte *src, uint srcLen);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue