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 "include/core/SkStream.h" 13 #include <cstddef> 14 15 #include <memory> 16 17 /** 18 * Wrap a stream in this class to compress the information written to 19 * this stream using the Deflate algorithm. 20 * 21 * See http://en.wikipedia.org/wiki/DEFLATE 22 */ 23 class SkDeflateWStream final : public SkWStream { 24 public: 25 /** Does not take ownership of the stream. 26 27 @param compressionLevel 1 is best speed; 9 is best compression. 28 The default, -1, is to use zlib's Z_DEFAULT_COMPRESSION level. 29 0 would be no compression, but due to broken zlibs, users should handle that themselves. 30 31 @param gzip iff true, output a gzip file. "The gzip format is 32 a wrapper, documented in RFC 1952, around a deflate stream." 33 gzip adds a header with a magic number to the beginning of the 34 stream, allowing a client to identify a gzip file. 35 */ 36 SkDeflateWStream(SkWStream*, 37 int compressionLevel, 38 bool gzip = false); 39 40 /** The destructor calls finalize(). */ 41 ~SkDeflateWStream() override; 42 43 /** Write the end of the compressed stream. All subsequent calls to 44 write() will fail. Subsequent calls to finalize() do nothing. */ 45 void finalize(); 46 47 // The SkWStream interface: 48 bool write(const void*, size_t) override; 49 size_t bytesWritten() const override; 50 51 private: 52 struct Impl; 53 std::unique_ptr<Impl> fImpl; 54 }; 55 56 #endif // SkFlate_DEFINED 57