aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf/SkDeflate.h
blob: 387de40a15f12f3da7759389b40f93a684daa8b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Copyright 2010 The Android Open Source Project
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#ifndef SkFlate_DEFINED
#define SkFlate_DEFINED

#include "SkStream.h"

/**
  * Wrap a stream in this class to compress the information written to
  * this stream using the Deflate algorithm.
  *
  * See http://en.wikipedia.org/wiki/DEFLATE
  */
class SkDeflateWStream final : public SkWStream {
public:
    /** Does not take ownership of the stream.

        @param compressionLevel - 0 is no compression; 1 is best
        speed; 9 is best compression.  The default, -1, is to use
        zlib's Z_DEFAULT_COMPRESSION level.

        @param gzip iff true, output a gzip file. "The gzip format is
        a wrapper, documented in RFC 1952, around a deflate stream."
        gzip adds a header with a magic number to the beginning of the
        stream, alowing a client to identify a gzip file.
     */
    SkDeflateWStream(SkWStream*,
                     int compressionLevel = -1,
                     bool gzip = false);

    /** The destructor calls finalize(). */
    ~SkDeflateWStream();

    /** Write the end of the compressed stream.  All subsequent calls to
        write() will fail. Subsequent calls to finalize() do nothing. */
    void finalize();

    // The SkWStream interface:
    bool write(const void*, size_t) override;
    size_t bytesWritten() const override;

private:
    struct Impl;
    std::unique_ptr<Impl> fImpl;
};

#endif  // SkFlate_DEFINED