Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gzip_inflater.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_UTIL_GZIP_INFLATER_H_
20 #define PAGESPEED_KERNEL_UTIL_GZIP_INFLATER_H_
21 
22 #include <cstddef>
25 
26 typedef struct z_stream_s z_stream;
27 
28 namespace net_instaweb {
29 
30 class Writer;
31 
32 class GzipInflater {
33  public:
34  enum InflateType {kGzip, kDeflate};
35 
36  explicit GzipInflater(InflateType type);
37  ~GzipInflater();
38 
40  bool Init();
41 
43  void ShutDown();
44 
48  bool HasUnconsumedInput() const;
49 
55  bool SetInput(const void *in, size_t in_size);
56 
61  int InflateBytes(char *buf, size_t buf_size);
62 
64  bool finished() const { return finished_; }
65 
67  bool error() const { return error_; }
68 
71  static bool Deflate(StringPiece in, InflateType format, Writer* writer);
72  static bool Deflate(StringPiece in, InflateType format, int compression_level,
73  Writer* writer);
74 
77  static bool Inflate(StringPiece in, InflateType format, Writer* writer);
78 
80  static bool HasGzipMagicBytes(StringPiece in);
81 
82  private:
83  friend class GzipInflaterTestPeer;
84 
85  enum StreamFormat {
86  FORMAT_GZIP,
87  FORMAT_ZLIB_STREAM,
88  FORMAT_RAW_INFLATE,
89  };
90 
91  static bool GetWindowBitsForFormat(
92  StreamFormat format, int* out_window_bits);
93  void Free();
94  void SetInputInternal(const void *in, size_t in_size);
95  void SwitchToRawDeflateFormat();
96 
97  z_stream *zlib_;
98  StreamFormat format_;
99  bool finished_;
100  bool error_;
101 
102 
103 };
104 
105 }
106 
107 #endif
int InflateBytes(char *buf, size_t buf_size)
bool finished() const
Has the entire input been inflated?
Definition: gzip_inflater.h:64
bool HasUnconsumedInput() const
static bool Deflate(StringPiece in, InflateType format, Writer *writer)
Interface for writing bytes to an output stream.
Definition: writer.h:29
static bool HasGzipMagicBytes(StringPiece in)
Checks whether in starts with the gzip file signature.
bool SetInput(const void *in, size_t in_size)
Definition: gzip_inflater.h:32
bool error() const
Was an error encountered during inflating?
Definition: gzip_inflater.h:67
void ShutDown()
Should be called once, after inflating is finished.
static bool Inflate(StringPiece in, InflateType format, Writer *writer)
bool Init()
Should be called once, before inflating any data.