diff options
author | Alyssa Milburn | 2011-08-22 20:03:05 +0200 |
---|---|---|
committer | Alyssa Milburn | 2011-08-22 20:03:05 +0200 |
commit | 84063dc9727a9f55e09d39574027beab695680e6 (patch) | |
tree | d71a9599cb550d9f7949a2d3209574064e054d85 /common/zlib.cpp | |
parent | c6e89df3d940747a85d447f172e2323c800f5eaf (diff) | |
parent | a39a3eda46aea108a51556f001617ad28d29e520 (diff) | |
download | scummvm-rg350-84063dc9727a9f55e09d39574027beab695680e6.tar.gz scummvm-rg350-84063dc9727a9f55e09d39574027beab695680e6.tar.bz2 scummvm-rg350-84063dc9727a9f55e09d39574027beab695680e6.zip |
Merge remote-tracking branch 'origin/master' into soltys_wip2
Diffstat (limited to 'common/zlib.cpp')
-rw-r--r-- | common/zlib.cpp | 26 |
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); |