2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2007-09-17 03:48:03 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _nsDeflateConverter_h_
|
|
|
|
#define _nsDeflateConverter_h_
|
|
|
|
|
|
|
|
#include "nsIStreamConverter.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIPipe.h"
|
|
|
|
#include "zlib.h"
|
2012-06-13 07:27:07 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-09-17 03:48:03 +04:00
|
|
|
|
|
|
|
#define DEFLATECONVERTER_CID { 0x461cd5dd, 0x73c6, 0x47a4, \
|
|
|
|
{ 0x8c, 0xc3, 0x60, 0x3b, 0x37, 0xd8, 0x4a, 0x61 } }
|
|
|
|
|
|
|
|
#define ZIP_BUFLEN (4 * 1024 - 1)
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsDeflateConverter final : public nsIStreamConverter
|
2007-09-17 03:48:03 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSISTREAMCONVERTER
|
|
|
|
|
|
|
|
nsDeflateConverter()
|
|
|
|
{
|
2007-11-22 01:05:11 +03:00
|
|
|
// 6 is Z_DEFAULT_COMPRESSION but we need the actual value
|
|
|
|
mLevel = 6;
|
2007-09-17 03:48:03 +04:00
|
|
|
}
|
|
|
|
|
2014-09-03 02:24:24 +04:00
|
|
|
explicit nsDeflateConverter(int32_t level)
|
2007-09-17 03:48:03 +04:00
|
|
|
{
|
|
|
|
mLevel = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
~nsDeflateConverter()
|
|
|
|
{
|
|
|
|
}
|
2007-11-22 01:05:11 +03:00
|
|
|
|
|
|
|
enum WrapMode {
|
|
|
|
WRAP_ZLIB,
|
|
|
|
WRAP_GZIP,
|
|
|
|
WRAP_NONE
|
|
|
|
};
|
2007-09-17 03:48:03 +04:00
|
|
|
|
2007-11-22 01:05:11 +03:00
|
|
|
WrapMode mWrapMode;
|
2012-09-06 06:41:02 +04:00
|
|
|
uint64_t mOffset;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mLevel;
|
2007-09-17 03:48:03 +04:00
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
|
|
|
nsCOMPtr<nsISupports> mContext;
|
|
|
|
z_stream mZstream;
|
|
|
|
unsigned char mWriteBuffer[ZIP_BUFLEN];
|
|
|
|
|
|
|
|
nsresult Init();
|
|
|
|
nsresult PushAvailableData(nsIRequest *aRequest, nsISupports *aContext);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|