aboutsummaryrefslogtreecommitdiff
path: root/common/zlib.cpp
diff options
context:
space:
mode:
authorMatthew Hoops2011-08-07 20:11:27 -0400
committerMatthew Hoops2011-08-07 20:11:27 -0400
commitc05c42ecc60c8f928628787272743f169a0d5903 (patch)
treef2b06be630676b7302a1fb62940099b2ec71442d /common/zlib.cpp
parente43a6671fc04f2c67b8efa2c0fdfdd6ec0ea1023 (diff)
parent45dc303159d5bbe77a351df31e6f2d2f97a3412d (diff)
downloadscummvm-rg350-c05c42ecc60c8f928628787272743f169a0d5903.tar.gz
scummvm-rg350-c05c42ecc60c8f928628787272743f169a0d5903.tar.bz2
scummvm-rg350-c05c42ecc60c8f928628787272743f169a0d5903.zip
Merge remote branch 'upstream/master' into soccer
Diffstat (limited to 'common/zlib.cpp')
-rw-r--r--common/zlib.cpp26
1 files changed, 9 insertions, 17 deletions
diff --git a/common/zlib.cpp b/common/zlib.cpp
index b047586af0..86c618830e 100644
--- a/common/zlib.cpp
+++ b/common/zlib.cpp
@@ -24,6 +24,7 @@
#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include "common/zlib.h"
+#include "common/ptr.h"
#include "common/util.h"
#include "common/stream.h"
@@ -53,7 +54,7 @@ bool uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long
* other SeekableReadStream and will then provide on-the-fly decompression support.
* Assumes the compressed data to be in gzip format.
*/
-class GZipReadStream : public Common::SeekableReadStream {
+class GZipReadStream : public SeekableReadStream {
protected:
enum {
BUFSIZE = 16384 // 1 << MAX_WBITS
@@ -61,7 +62,7 @@ protected:
byte _buf[BUFSIZE];
- Common::SeekableReadStream *_wrapped;
+ ScopedPtr<SeekableReadStream> _wrapped;
z_stream _stream;
int _zlibErr;
uint32 _pos;
@@ -70,13 +71,9 @@ protected:
public:
- GZipReadStream(Common::SeekableReadStream *w) : _wrapped(w) {
+ GZipReadStream(SeekableReadStream *w) : _wrapped(w), _stream() {
assert(w != 0);
- _stream.zalloc = Z_NULL;
- _stream.zfree = Z_NULL;
- _stream.opaque = Z_NULL;
-
// Verify file header is correct
w->seek(0, SEEK_SET);
uint16 header = w->readUint16BE();
@@ -111,7 +108,6 @@ public:
~GZipReadStream() {
inflateEnd(&_stream);
- delete _wrapped;
}
bool err() const { return (_zlibErr != Z_OK) && (_zlibErr != Z_STREAM_END); }
@@ -201,14 +197,14 @@ public:
* other WriteStream and will then provide on-the-fly compression support.
* The compressed data is written in the gzip format.
*/
-class GZipWriteStream : public Common::WriteStream {
+class GZipWriteStream : public WriteStream {
protected:
enum {
BUFSIZE = 16384 // 1 << MAX_WBITS
};
byte _buf[BUFSIZE];
- Common::WriteStream *_wrapped;
+ ScopedPtr<WriteStream> _wrapped;
z_stream _stream;
int _zlibErr;
@@ -228,11 +224,8 @@ protected:
}
public:
- GZipWriteStream(Common::WriteStream *w) : _wrapped(w) {
+ GZipWriteStream(WriteStream *w) : _wrapped(w), _stream() {
assert(w != 0);
- _stream.zalloc = Z_NULL;
- _stream.zfree = Z_NULL;
- _stream.opaque = Z_NULL;
// Adding 16 to windowBits indicates to zlib that it is supposed to
// write gzip headers. This feature was added in zlib 1.2.0.4,
@@ -255,7 +248,6 @@ public:
~GZipWriteStream() {
finalize();
deflateEnd(&_stream);
- delete _wrapped;
}
bool err() const {
@@ -308,7 +300,7 @@ public:
#endif // USE_ZLIB
-Common::SeekableReadStream *wrapCompressedReadStream(Common::SeekableReadStream *toBeWrapped) {
+SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped) {
#if defined(USE_ZLIB)
if (toBeWrapped) {
uint16 header = toBeWrapped->readUint16BE();
@@ -323,7 +315,7 @@ Common::SeekableReadStream *wrapCompressedReadStream(Common::SeekableReadStream
return toBeWrapped;
}
-Common::WriteStream *wrapCompressedWriteStream(Common::WriteStream *toBeWrapped) {
+WriteStream *wrapCompressedWriteStream(WriteStream *toBeWrapped) {
#if defined(USE_ZLIB)
if (toBeWrapped)
return new GZipWriteStream(toBeWrapped);