/src/mozilla-central/modules/libjar/zipwriter/nsDeflateConverter.h
Line | Count | Source (jump to first uncovered line) |
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 "nsIPipe.h" |
12 | | #include "zlib.h" |
13 | | #include "mozilla/Attributes.h" |
14 | | |
15 | | #define DEFLATECONVERTER_CID { 0x461cd5dd, 0x73c6, 0x47a4, \ |
16 | | { 0x8c, 0xc3, 0x60, 0x3b, 0x37, 0xd8, 0x4a, 0x61 } } |
17 | | |
18 | | #define ZIP_BUFLEN (4 * 1024 - 1) |
19 | | |
20 | | class nsDeflateConverter final : public nsIStreamConverter |
21 | | { |
22 | | public: |
23 | | NS_DECL_ISUPPORTS |
24 | | NS_DECL_NSIREQUESTOBSERVER |
25 | | NS_DECL_NSISTREAMLISTENER |
26 | | NS_DECL_NSISTREAMCONVERTER |
27 | | |
28 | | nsDeflateConverter() |
29 | | : mWrapMode(WRAP_NONE) |
30 | | , mOffset(0) |
31 | | , mZstream() |
32 | 0 | { |
33 | 0 | // 6 is Z_DEFAULT_COMPRESSION but we need the actual value |
34 | 0 | mLevel = 6; |
35 | 0 | } |
36 | | |
37 | | explicit nsDeflateConverter(int32_t level) |
38 | | : mWrapMode(WRAP_NONE) |
39 | | , mOffset(0) |
40 | | , mZstream() |
41 | 0 | { |
42 | 0 | mLevel = level; |
43 | 0 | } |
44 | | |
45 | | private: |
46 | | |
47 | | ~nsDeflateConverter() |
48 | 0 | { |
49 | 0 | } |
50 | | |
51 | | enum WrapMode { |
52 | | WRAP_ZLIB, |
53 | | WRAP_GZIP, |
54 | | WRAP_NONE |
55 | | }; |
56 | | |
57 | | WrapMode mWrapMode; |
58 | | uint64_t mOffset; |
59 | | int32_t mLevel; |
60 | | nsCOMPtr<nsIStreamListener> mListener; |
61 | | nsCOMPtr<nsISupports> mContext; |
62 | | z_stream mZstream; |
63 | | unsigned char mWriteBuffer[ZIP_BUFLEN]; |
64 | | |
65 | | nsresult Init(); |
66 | | nsresult PushAvailableData(nsIRequest *aRequest, nsISupports *aContext); |
67 | | }; |
68 | | |
69 | | #endif |