halcanary | d9e5715 | 2015-08-12 11:24:40 -0700 | [diff] [blame] | 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 | |
halcanary | d9e5715 | 2015-08-12 11:24:40 -0700 | [diff] [blame] | 12 | #include "SkStream.h" |
halcanary | d9e5715 | 2015-08-12 11:24:40 -0700 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * Wrap a stream in this class to compress the information written to |
halcanary | e365bfa | 2016-02-08 09:34:34 -0800 | [diff] [blame] | 16 | * this stream using the Deflate algorithm. |
halcanary | d9e5715 | 2015-08-12 11:24:40 -0700 | [diff] [blame] | 17 | * |
| 18 | * See http://en.wikipedia.org/wiki/DEFLATE |
| 19 | */ |
halcanary | 70d1554 | 2015-11-22 12:55:04 -0800 | [diff] [blame] | 20 | class SkDeflateWStream final : public SkWStream { |
halcanary | d9e5715 | 2015-08-12 11:24:40 -0700 | [diff] [blame] | 21 | public: |
halcanary | e365bfa | 2016-02-08 09:34:34 -0800 | [diff] [blame] | 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, alowing a client to identify a gzip file. |
| 32 | */ |
| 33 | SkDeflateWStream(SkWStream*, |
| 34 | int compressionLevel = -1, |
| 35 | bool gzip = false); |
halcanary | d9e5715 | 2015-08-12 11:24:40 -0700 | [diff] [blame] | 36 | |
| 37 | /** The destructor calls finalize(). */ |
| 38 | ~SkDeflateWStream(); |
| 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; |
halcanary | b8fb993 | 2016-03-28 07:58:30 -0700 | [diff] [blame] | 50 | std::unique_ptr<Impl> fImpl; |
halcanary | d9e5715 | 2015-08-12 11:24:40 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | #endif // SkFlate_DEFINED |