diff options
author | Eugene Sandulenko | 2011-08-27 08:21:57 -0700 |
---|---|---|
committer | Eugene Sandulenko | 2011-08-27 08:21:57 -0700 |
commit | 35aa235e4b4c4212b59d00adb77d2e3d00dd440e (patch) | |
tree | 08f22fd45b7d886a96e73809ff48dc4e9df39bcc /common/zlib.cpp | |
parent | ac53915d01e69b90fc6bf64dbce2606c9d4044fd (diff) | |
parent | 5346ac18b7e33a603aa2743fa57f430d96cdbc33 (diff) | |
download | scummvm-rg350-35aa235e4b4c4212b59d00adb77d2e3d00dd440e.tar.gz scummvm-rg350-35aa235e4b4c4212b59d00adb77d2e3d00dd440e.tar.bz2 scummvm-rg350-35aa235e4b4c4212b59d00adb77d2e3d00dd440e.zip |
Merge pull request #79 from clone2727/agos_cab
AGOS: Add support for loading data from Windows (InstallShield) installer archives
Diffstat (limited to 'common/zlib.cpp')
-rw-r--r-- | common/zlib.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/common/zlib.cpp b/common/zlib.cpp index 86c618830e..70133fea30 100644 --- a/common/zlib.cpp +++ b/common/zlib.cpp @@ -49,6 +49,35 @@ bool uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long 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 * other SeekableReadStream and will then provide on-the-fly decompression support. |