From 2be865b83103d316003f956cbd2d913d3686f82e Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 27 Nov 2017 16:56:11 +0000 Subject: [PATCH] Added a GZIPCompressorOutputStream constructor that takes a reference. --- .../zip/juce_GZIPCompressorOutputStream.cpp | 24 ++++++++++--------- .../zip/juce_GZIPCompressorOutputStream.h | 23 ++++++++++++++---- modules/juce_core/zip/juce_ZipFile.cpp | 2 +- .../fonts/juce_CustomTypeface.cpp | 2 +- .../marketplace/juce_OnlineUnlockStatus.cpp | 2 +- 5 files changed, 34 insertions(+), 19 deletions(-) diff --git a/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp b/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp index df64f23d2c..aa46cb63ad 100644 --- a/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp +++ b/modules/juce_core/zip/juce_GZIPCompressorOutputStream.cpp @@ -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;) { diff --git a/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h b/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h index 25a28101a6..02da3a7fee 100644 --- a/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h +++ b/modules/juce_core/zip/juce_GZIPCompressorOutputStream.h @@ -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 diff --git a/modules/juce_core/zip/juce_ZipFile.cpp b/modules/juce_core/zip/juce_ZipFile.cpp index 43b6e9a447..8fc01fa5d1 100644 --- a/modules/juce_core/zip/juce_ZipFile.cpp +++ b/modules/juce_core/zip/juce_ZipFile.cpp @@ -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; diff --git a/modules/juce_graphics/fonts/juce_CustomTypeface.cpp b/modules/juce_graphics/fonts/juce_CustomTypeface.cpp index e8b05254ef..e7e0f8e95a 100644 --- a/modules/juce_graphics/fonts/juce_CustomTypeface.cpp +++ b/modules/juce_graphics/fonts/juce_CustomTypeface.cpp @@ -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)); diff --git a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockStatus.cpp b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockStatus.cpp index c264866c8d..ff83a09ba3 100644 --- a/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockStatus.cpp +++ b/modules/juce_product_unlocking/marketplace/juce_OnlineUnlockStatus.cpp @@ -263,7 +263,7 @@ void OnlineUnlockStatus::save() MemoryOutputStream mo; { - GZIPCompressorOutputStream gzipStream (&mo, 9); + GZIPCompressorOutputStream gzipStream (mo, 9); status.writeToStream (gzipStream); }