COMMON: Remove useless inflateZlib function

To write on stream it's simpler to use wrapCompressedReadStream and
writeStream function.
This commit is contained in:
Le Philousophe 2023-08-15 09:28:56 +02:00 committed by Eugene Sandulenko
parent 7c9df6c2bf
commit 2f7c2149e5
3 changed files with 0 additions and 105 deletions

View File

@ -112,18 +112,6 @@ static inline bool inflateClickteam(byte *dst, uint dstLen, const byte *src, ui
return inflateClickteam(dst, &dstLen, src, srcLen);
}
/**
* Wrapper around zlib's inflate functions. This function is used by Glk to
* decompress TAF 4.0 files, which are Zlib compressed streams with a custom
* header
*
* @param dst the destination stream to write decompressed data out to
* @param src the Source stream
*
* @return true on success (Z_OK or Z_STREAM_END), false otherwise.
*/
bool inflateZlib(Common::WriteStream *dst, Common::SeekableReadStream *src);
/**
* Take an arbitrary SeekableReadStream and wrap it in a custom stream which
* provides transparent on-the-fly decompression. Assumes the data it

View File

@ -1409,22 +1409,6 @@ bool inflateZlibHeaderless(byte *dst, uint *dstLen, const byte *src, uint srcLen
// In zlib version we use Z_SYNC_FLUSH so no error is raised if buffer is not completely consumed
return !gzio->err();
}
bool inflateZlib(Common::WriteStream *dst, Common::SeekableReadStream *src) {
Common::ScopedPtr<Common::SeekableReadStream> gzio(wrapCompressedReadStream(src, DisposeAfterUse::NO, 0));
if (!gzio)
return false;
byte *buffer = new byte[65536];
while(!gzio->eos()) {
uint32 readBytes = gzio->read(buffer, 65536);
if (gzio->err()) {
return false;
}
dst->write(buffer, readBytes);
}
return true;
}
#endif
SeekableReadStream* wrapClickteamReadStream(Common::SeekableReadStream *parent, DisposeAfterUse::Flag disposeParent, uint64 uncompressed_size) {

View File

@ -83,83 +83,6 @@ bool inflateZlibHeaderless(byte *dst, uint *dstLen, const byte *src, uint srcLen
return true;
}
enum {
kTempBufSize = 65536
};
bool inflateZlib(Common::WriteStream *dst, Common::SeekableReadStream *src) {
byte *inBuffer, *outBuffer;
z_stream stream;
int status;
// Allocate buffers
inBuffer = new byte[kTempBufSize];
outBuffer = new byte[kTempBufSize];
/* Initialize Zlib inflation functions. */
stream.next_out = outBuffer;
stream.avail_out = kTempBufSize;
stream.next_in = inBuffer;
stream.avail_in = 0;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
status = inflateInit(&stream);
if (status != Z_OK) {
delete[] inBuffer;
delete[] outBuffer;
return false;
}
// Inflate the input buffers. */
for (;;) {
int inBytes, outBytes;
/* If the input buffer is empty, try to obtain more data. */
if (stream.avail_in == 0) {
inBytes = src->read(inBuffer, kTempBufSize);
stream.next_in = inBuffer;
stream.avail_in = inBytes;
}
// Decompress as much stream data as we can. */
status = inflate(&stream, Z_SYNC_FLUSH);
if (status != Z_STREAM_END && status != Z_OK) {
delete[] inBuffer;
delete[] outBuffer;
return false;
}
outBytes = kTempBufSize - stream.avail_out;
// See if decompressed data is available. */
if (outBytes > 0) {
// Add data from the buffer to the output
int consumed = dst->write(outBuffer, outBytes);
// Move unused buffer data to buffer start
memmove(outBuffer, outBuffer + consumed, kTempBufSize - consumed);
// Reset inflation stream for available space
stream.next_out = outBuffer + outBytes - consumed;
stream.avail_out += consumed;
}
// If at inflation stream end and output is empty, leave loop
if (status == Z_STREAM_END && stream.avail_out == kTempBufSize)
break;
}
// End inflation buffers
status = inflateEnd(&stream);
delete[] inBuffer;
delete[] outBuffer;
// Return result
return (status == Z_OK);
}
#ifndef RELEASE_BUILD
static bool _shownBackwardSeekingWarning = false;
#endif