1 /* 2 * Copyright 2010 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 9 #ifndef SkFlate_DEFINED 10 #define SkFlate_DEFINED 11 12 #include "SkStream.h" 13 14 /** 15 * Wrap a stream in this class to compress the information written to 16 * this stream using the Deflate algorithm. 17 * 18 * See http://en.wikipedia.org/wiki/DEFLATE 19 */ 20 class SkDeflateWStream final : public SkWStream { 21 public: 22 /** Does not take ownership of the stream. 23 24 @param compressionLevel - 0 is no compression; 1 is best 25 speed; 9 is best compression. The default, -1, is to use 26 zlib's Z_DEFAULT_COMPRESSION level. 27 28 @param gzip iff true, output a gzip file. "The gzip format is 29 a wrapper, documented in RFC 1952, around a deflate stream." 30 gzip adds a header with a magic number to the beginning of the 31 stream, allowing a client to identify a gzip file. 32 */ 33 SkDeflateWStream(SkWStream*, 34 int compressionLevel = -1, 35 bool gzip = false); 36 37 /** The destructor calls finalize(). */ 38 ~SkDeflateWStream() override; 39 40 /** Write the end of the compressed stream. All subsequent calls to 41 write() will fail. Subsequent calls to finalize() do nothing. */ 42 void finalize(); 43 44 // The SkWStream interface: 45 bool write(const void*, size_t) override; 46 size_t bytesWritten() const override; 47 48 private: 49 struct Impl; 50 std::unique_ptr<Impl> fImpl; 51 }; 52 53 #endif // SkFlate_DEFINED 54