Home | History | Annotate | Download | only in pdf
      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"
     15 
     16 /**
     17   * Wrap a stream in this class to compress the information written to
     18   * this stream using the Deflate algorithm.
     19   *
     20   * See http://en.wikipedia.org/wiki/DEFLATE
     21   */
     22 class SkDeflateWStream final : public SkWStream {
     23 public:
     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);
     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
     56