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