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

Added a GZIPCompressorOutputStream constructor that takes a reference.

This commit is contained in:
jules 2017-11-27 16:56:11 +00:00
parent a0bd5f5be7
commit 2be865b831
5 changed files with 34 additions and 19 deletions

View file

@ -26,7 +26,7 @@ namespace juce
class GZIPCompressorOutputStream::GZIPCompressorHelper
{
public:
GZIPCompressorHelper (const int compressionLevel, const int windowBits)
GZIPCompressorHelper (int compressionLevel, int windowBits)
: compLevel ((compressionLevel < 0 || compressionLevel > 9) ? -1 : compressionLevel)
{
using namespace zlibNamespace;
@ -84,8 +84,8 @@ private:
stream.avail_in = (z_uInt) dataSize;
stream.avail_out = (z_uInt) sizeof (buffer);
const int result = isFirstDeflate ? deflateParams (&stream, compLevel, strategy)
: deflate (&stream, flushMode);
auto result = isFirstDeflate ? deflateParams (&stream, compLevel, strategy)
: deflate (&stream, flushMode);
isFirstDeflate = false;
switch (result)
@ -97,7 +97,7 @@ private:
{
data += dataSize - stream.avail_in;
dataSize = stream.avail_in;
const ssize_t bytesDone = (ssize_t) sizeof (buffer) - (ssize_t) stream.avail_out;
auto bytesDone = (ssize_t) sizeof (buffer) - (ssize_t) stream.avail_out;
return bytesDone <= 0 || out.write (buffer, (size_t) bytesDone);
}
@ -113,12 +113,14 @@ private:
};
//==============================================================================
GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const out,
const int compressionLevel,
const bool deleteDestStream,
const int windowBits)
: destStream (out, deleteDestStream),
helper (new GZIPCompressorHelper (compressionLevel, windowBits))
GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream& destStream, int compressionLevel, int windowBits)
: GZIPCompressorOutputStream (&destStream, compressionLevel, false, windowBits)
{
}
GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* out, int compressionLevel, bool deleteDestStream, int windowBits)
: destStream (out, deleteDestStream),
helper (new GZIPCompressorHelper (compressionLevel, windowBits))
{
jassert (out != nullptr);
}
@ -169,7 +171,7 @@ struct GZIPTests : public UnitTest
MemoryOutputStream original, compressed, uncompressed;
{
GZIPCompressorOutputStream zipper (&compressed, rng.nextInt (10), false);
GZIPCompressorOutputStream zipper (compressed, rng.nextInt (10));
for (int j = rng.nextInt (100); --j >= 0;)
{

View file

@ -38,15 +38,28 @@ class JUCE_API GZIPCompressorOutputStream : public OutputStream
public:
//==============================================================================
/** Creates a compression stream.
@param destStream the stream into which the compressed data should
be written
@param destStream the stream into which the compressed data will be written
@param compressionLevel how much to compress the data, between 0 and 9, where
0 is non-compressed storage, 1 is the fastest/lowest compression,
and 9 is the slowest/highest compression. Any value outside this range
indicates that a default compression level should be used.
@param deleteDestStreamWhenDestroyed whether or not to delete the destStream object when
this stream is destroyed
@param windowBits this is used internally to change the window size used
by zlib - leave it as 0 unless you specifically need to set
its value for some reason
*/
GZIPCompressorOutputStream (OutputStream& destStream,
int compressionLevel = -1,
int windowBits = 0);
/** Creates a compression stream.
@param destStream the stream into which the compressed data will be written.
Ownership of this object depends on the value of deleteDestStreamWhenDestroyed
@param compressionLevel how much to compress the data, between 0 and 9, where
0 is non-compressed storage, 1 is the fastest/lowest compression,
and 9 is the slowest/highest compression. Any value outside this range
indicates that a default compression level should be used.
@param deleteDestStreamWhenDestroyed whether or not the GZIPCompressorOutputStream will delete the
destStream object when it is destroyed
@param windowBits this is used internally to change the window size used
by zlib - leave it as 0 unless you specifically need to set
its value for some reason

View file

@ -447,7 +447,7 @@ struct ZipFile::Builder::Item
if (compressionLevel > 0)
{
GZIPCompressorOutputStream compressor (&compressedData, compressionLevel, false,
GZIPCompressorOutputStream compressor (compressedData, compressionLevel,
GZIPCompressorOutputStream::windowBitsRaw);
if (! writeSource (compressor))
return false;

View file

@ -258,7 +258,7 @@ void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_
bool CustomTypeface::writeToStream (OutputStream& outputStream)
{
GZIPCompressorOutputStream out (&outputStream);
GZIPCompressorOutputStream out (outputStream);
out.writeString (name);
out.writeBool (FontStyleHelpers::isBold (style));

View file

@ -263,7 +263,7 @@ void OnlineUnlockStatus::save()
MemoryOutputStream mo;
{
GZIPCompressorOutputStream gzipStream (&mo, 9);
GZIPCompressorOutputStream gzipStream (mo, 9);
status.writeToStream (gzipStream);
}