blob: 978b57edaf6ada9d7b3b8ee22bad8e8ff021e024 [file] [log] [blame]
halcanaryd9e57152015-08-12 11:24:40 -07001/*
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"
halcanaryd9e57152015-08-12 11:24:40 -070015
16/**
17 * Wrap a stream in this class to compress the information written to
halcanarye365bfa2016-02-08 09:34:34 -080018 * this stream using the Deflate algorithm.
halcanaryd9e57152015-08-12 11:24:40 -070019 *
20 * See http://en.wikipedia.org/wiki/DEFLATE
21 */
halcanary70d15542015-11-22 12:55:04 -080022class SkDeflateWStream final : public SkWStream {
halcanaryd9e57152015-08-12 11:24:40 -070023public:
halcanarye365bfa2016-02-08 09:34:34 -080024 /** 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);
halcanaryd9e57152015-08-12 11:24:40 -070038
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
50private:
51 struct Impl;
52 SkAutoTDelete<Impl> fImpl;
53};
54
55#endif // SkFlate_DEFINED