1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/libjar/zipwriter/src/nsDeflateConverter.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,63 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + */ 1.8 + 1.9 +#ifndef _nsDeflateConverter_h_ 1.10 +#define _nsDeflateConverter_h_ 1.11 + 1.12 +#include "nsIStreamConverter.h" 1.13 +#include "nsCOMPtr.h" 1.14 +#include "nsIPipe.h" 1.15 +#include "zlib.h" 1.16 +#include "mozilla/Attributes.h" 1.17 + 1.18 +#define DEFLATECONVERTER_CID { 0x461cd5dd, 0x73c6, 0x47a4, \ 1.19 + { 0x8c, 0xc3, 0x60, 0x3b, 0x37, 0xd8, 0x4a, 0x61 } } 1.20 + 1.21 +#define ZIP_BUFLEN (4 * 1024 - 1) 1.22 + 1.23 +class nsDeflateConverter MOZ_FINAL : public nsIStreamConverter 1.24 +{ 1.25 +public: 1.26 + NS_DECL_ISUPPORTS 1.27 + NS_DECL_NSIREQUESTOBSERVER 1.28 + NS_DECL_NSISTREAMLISTENER 1.29 + NS_DECL_NSISTREAMCONVERTER 1.30 + 1.31 + nsDeflateConverter() 1.32 + { 1.33 + // 6 is Z_DEFAULT_COMPRESSION but we need the actual value 1.34 + mLevel = 6; 1.35 + } 1.36 + 1.37 + nsDeflateConverter(int32_t level) 1.38 + { 1.39 + mLevel = level; 1.40 + } 1.41 + 1.42 +private: 1.43 + 1.44 + ~nsDeflateConverter() 1.45 + { 1.46 + } 1.47 + 1.48 + enum WrapMode { 1.49 + WRAP_ZLIB, 1.50 + WRAP_GZIP, 1.51 + WRAP_NONE 1.52 + }; 1.53 + 1.54 + WrapMode mWrapMode; 1.55 + uint64_t mOffset; 1.56 + int32_t mLevel; 1.57 + nsCOMPtr<nsIStreamListener> mListener; 1.58 + nsCOMPtr<nsISupports> mContext; 1.59 + z_stream mZstream; 1.60 + unsigned char mWriteBuffer[ZIP_BUFLEN]; 1.61 + 1.62 + nsresult Init(); 1.63 + nsresult PushAvailableData(nsIRequest *aRequest, nsISupports *aContext); 1.64 +}; 1.65 + 1.66 +#endif