1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-02-05 03:50:07 +00:00

Reverted recent changes to GZIPDecompressorInputStream - turns out that zlib can't auto-detect the difference between gzip and raw streams.

This commit is contained in:
jules 2014-06-25 11:22:28 +01:00
parent f89943d5f1
commit 7be01cd88b
3 changed files with 14 additions and 12 deletions

View file

@ -90,7 +90,7 @@ namespace zlibNamespace
class GZIPDecompressorInputStream::GZIPDecompressHelper
{
public:
GZIPDecompressHelper()
GZIPDecompressHelper (const bool dontWrap)
: finished (true),
needsDictionary (false),
error (true),
@ -100,7 +100,7 @@ public:
{
using namespace zlibNamespace;
zerostruct (stream);
streamIsValid = (inflateInit2 (&stream, MAX_WBITS + 32 /* auto-detect gzip encoding */) == Z_OK);
streamIsValid = (inflateInit2 (&stream, dontWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
finished = error = ! streamIsValid;
}
@ -172,27 +172,30 @@ private:
//==============================================================================
GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const source,
const bool deleteSourceWhenDestroyed,
const int64 uncompressedLength)
const bool noWrap_,
const int64 uncompressedStreamLength_)
: sourceStream (source, deleteSourceWhenDestroyed),
uncompressedStreamLength (uncompressedLength),
uncompressedStreamLength (uncompressedStreamLength_),
noWrap (noWrap_),
isEof (false),
activeBufferSize (0),
originalSourcePos (source->getPosition()),
currentPos (0),
buffer ((size_t) GZIPDecompressHelper::gzipDecompBufferSize),
helper (new GZIPDecompressHelper())
helper (new GZIPDecompressHelper (noWrap_))
{
}
GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream& source)
: sourceStream (&source, false),
uncompressedStreamLength (-1),
noWrap (false),
isEof (false),
activeBufferSize (0),
originalSourcePos (source.getPosition()),
currentPos (0),
buffer ((size_t) GZIPDecompressHelper::gzipDecompBufferSize),
helper (new GZIPDecompressHelper())
helper (new GZIPDecompressHelper (false))
{
}
@ -275,7 +278,7 @@ bool GZIPDecompressorInputStream::setPosition (int64 newPos)
isEof = false;
activeBufferSize = 0;
currentPos = 0;
helper = new GZIPDecompressHelper();
helper = new GZIPDecompressHelper (noWrap);
sourceStream->setPosition (originalSourcePos);
}

View file

@ -57,6 +57,7 @@ public:
*/
GZIPDecompressorInputStream (InputStream* sourceStream,
bool deleteSourceWhenDestroyed,
bool noWrap = false,
int64 uncompressedStreamLength = -1);
/** Creates a decompressor stream.
@ -79,7 +80,8 @@ public:
private:
//==============================================================================
OptionalScopedPointer<InputStream> sourceStream;
int64 uncompressedStreamLength;
const int64 uncompressedStreamLength;
const bool noWrap;
bool isEof;
int activeBufferSize;
int64 originalSourcePos, currentPos;
@ -89,9 +91,6 @@ private:
friend struct ContainerDeletePolicy<GZIPDecompressHelper>;
ScopedPointer<GZIPDecompressHelper> helper;
// NB: The old 'noWrap' parameter is no longer needed in the constructor
JUCE_DEPRECATED (GZIPDecompressorInputStream (InputStream*, bool, bool));
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GZIPDecompressorInputStream)
};

View file

@ -298,7 +298,7 @@ InputStream* ZipFile::createStreamForEntry (const int index)
if (zei->compressed)
{
stream = new GZIPDecompressorInputStream (stream, true, (int64) zei->entry.uncompressedSize);
stream = new GZIPDecompressorInputStream (stream, true, true, (int64) zei->entry.uncompressedSize);
// (much faster to unzip in big blocks using a buffer..)
stream = new BufferedInputStream (stream, 32768, true);