michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: #ifndef _nsDeflateConverter_h_ michael@0: #define _nsDeflateConverter_h_ michael@0: michael@0: #include "nsIStreamConverter.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIPipe.h" michael@0: #include "zlib.h" michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #define DEFLATECONVERTER_CID { 0x461cd5dd, 0x73c6, 0x47a4, \ michael@0: { 0x8c, 0xc3, 0x60, 0x3b, 0x37, 0xd8, 0x4a, 0x61 } } michael@0: michael@0: #define ZIP_BUFLEN (4 * 1024 - 1) michael@0: michael@0: class nsDeflateConverter MOZ_FINAL : public nsIStreamConverter michael@0: { michael@0: public: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIREQUESTOBSERVER michael@0: NS_DECL_NSISTREAMLISTENER michael@0: NS_DECL_NSISTREAMCONVERTER michael@0: michael@0: nsDeflateConverter() michael@0: { michael@0: // 6 is Z_DEFAULT_COMPRESSION but we need the actual value michael@0: mLevel = 6; michael@0: } michael@0: michael@0: nsDeflateConverter(int32_t level) michael@0: { michael@0: mLevel = level; michael@0: } michael@0: michael@0: private: michael@0: michael@0: ~nsDeflateConverter() michael@0: { michael@0: } michael@0: michael@0: enum WrapMode { michael@0: WRAP_ZLIB, michael@0: WRAP_GZIP, michael@0: WRAP_NONE michael@0: }; michael@0: michael@0: WrapMode mWrapMode; michael@0: uint64_t mOffset; michael@0: int32_t mLevel; michael@0: nsCOMPtr mListener; michael@0: nsCOMPtr mContext; michael@0: z_stream mZstream; michael@0: unsigned char mWriteBuffer[ZIP_BUFLEN]; michael@0: michael@0: nsresult Init(); michael@0: nsresult PushAvailableData(nsIRequest *aRequest, nsISupports *aContext); michael@0: }; michael@0: michael@0: #endif