nsDeflateConverter.h (1438B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 */ 5 6 #ifndef _nsDeflateConverter_h_ 7 #define _nsDeflateConverter_h_ 8 9 #include "nsIStreamConverter.h" 10 #include "nsCOMPtr.h" 11 #include "nsIThreadRetargetableStreamListener.h" 12 #include "zlib.h" 13 14 #define DEFLATECONVERTER_CID \ 15 {0x461cd5dd, 0x73c6, 0x47a4, {0x8c, 0xc3, 0x60, 0x3b, 0x37, 0xd8, 0x4a, 0x61}} 16 17 class nsDeflateConverter final : public nsIStreamConverter { 18 public: 19 static constexpr size_t kZipBufLen = (4 * 1024 - 1); 20 21 NS_DECL_ISUPPORTS 22 NS_DECL_NSIREQUESTOBSERVER 23 NS_DECL_NSISTREAMLISTENER 24 NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER 25 NS_DECL_NSISTREAMCONVERTER 26 27 nsDeflateConverter() : mWrapMode(WRAP_NONE), mOffset(0), mZstream() { 28 // 6 is Z_DEFAULT_COMPRESSION but we need the actual value 29 mLevel = 6; 30 } 31 32 explicit nsDeflateConverter(int32_t level) 33 : mWrapMode(WRAP_NONE), mOffset(0), mZstream() { 34 mLevel = level; 35 } 36 37 private: 38 ~nsDeflateConverter() {} 39 40 enum WrapMode { WRAP_ZLIB, WRAP_GZIP, WRAP_NONE }; 41 42 WrapMode mWrapMode; 43 uint64_t mOffset; 44 int32_t mLevel; 45 nsCOMPtr<nsIStreamListener> mListener; 46 nsCOMPtr<nsISupports> mContext; 47 z_stream mZstream; 48 unsigned char mWriteBuffer[kZipBufLen]; 49 50 nsresult Init(); 51 nsresult PushAvailableData(nsIRequest* aRequest); 52 }; 53 54 #endif