Page Speed Optimization Libraries
1.5.27.2
|
00001 /* 00002 * Copyright 2010 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00018 00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_GZIP_INFLATER_H_ 00020 #define NET_INSTAWEB_UTIL_PUBLIC_GZIP_INFLATER_H_ 00021 00022 #include <cstddef> 00023 #include "net/instaweb/util/public/basictypes.h" 00024 #include "net/instaweb/util/public/string_util.h" 00025 00026 typedef struct z_stream_s z_stream; 00027 00028 namespace net_instaweb { 00029 00030 class Writer; 00031 00032 class GzipInflater { 00033 public: 00034 enum InflateType {kGzip, kDeflate}; 00035 00036 explicit GzipInflater(InflateType type); 00037 ~GzipInflater(); 00038 00040 bool Init(); 00041 00043 void ShutDown(); 00044 00048 bool HasUnconsumedInput() const; 00049 00055 bool SetInput(const void *in, size_t in_size); 00056 00061 int InflateBytes(char *buf, size_t buf_size); 00062 00064 bool finished() const { return finished_; } 00065 00067 bool error() const { return error_; } 00068 00071 static bool Deflate(StringPiece in, Writer* writer); 00072 00075 static bool Inflate(StringPiece in, Writer* writer); 00076 00077 private: 00078 friend class GzipInflaterTestPeer; 00079 00080 enum StreamFormat { 00081 FORMAT_GZIP, 00082 FORMAT_ZLIB_STREAM, 00083 FORMAT_RAW_INFLATE, 00084 }; 00085 00086 static bool GetWindowBitsForFormat( 00087 StreamFormat format, int* out_window_bits); 00088 void Free(); 00089 void SetInputInternal(const void *in, size_t in_size); 00090 void SwitchToRawDeflateFormat(); 00091 00092 z_stream *zlib_; 00093 StreamFormat format_; 00094 bool finished_; 00095 bool error_; 00096 00097 DISALLOW_COPY_AND_ASSIGN(GzipInflater); 00098 }; 00099 00100 } 00101 00102 #endif ///< NET_INSTAWEB_UTIL_PUBLIC_GZIP_INFLATER_H_