modules/libjar/zipwriter/src/nsZipHeader.h

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:516696dbcde0
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 _nsZipHeader_h_
7 #define _nsZipHeader_h_
8
9 #include "nsString.h"
10 #include "nsIOutputStream.h"
11 #include "nsIInputStream.h"
12 #include "nsIZipReader.h"
13 #include "nsAutoPtr.h"
14 #include "mozilla/Attributes.h"
15
16 // High word is S_IFREG, low word is DOS file attribute
17 #define ZIP_ATTRS_FILE 0x80000000
18 // High word is S_IFDIR, low word is DOS dir attribute
19 #define ZIP_ATTRS_DIRECTORY 0x40000010
20 #define PERMISSIONS_FILE 0644
21 #define PERMISSIONS_DIR 0755
22
23 // Combine file type attributes with unix style permissions
24 #define ZIP_ATTRS(p, a) ((p & 0xfff) << 16) | a
25
26 class nsZipHeader MOZ_FINAL : public nsIZipEntry
27 {
28 public:
29 NS_DECL_ISUPPORTS
30 NS_DECL_NSIZIPENTRY
31
32 nsZipHeader() :
33 mCRC(0),
34 mCSize(0),
35 mUSize(0),
36 mEAttr(0),
37 mOffset(0),
38 mFieldLength(0),
39 mLocalFieldLength(0),
40 mVersionMade(0x0300 + 23), // Generated on Unix by v2.3 (matches infozip)
41 mVersionNeeded(20), // Requires v2.0 to extract
42 mFlags(0),
43 mMethod(0),
44 mTime(0),
45 mDate(0),
46 mDisk(0),
47 mIAttr(0),
48 mInited(false),
49 mWriteOnClose(false),
50 mExtraField(nullptr),
51 mLocalExtraField(nullptr)
52 {
53 }
54
55 ~nsZipHeader()
56 {
57 mExtraField = nullptr;
58 mLocalExtraField = nullptr;
59 }
60
61 uint32_t mCRC;
62 uint32_t mCSize;
63 uint32_t mUSize;
64 uint32_t mEAttr;
65 uint32_t mOffset;
66 uint32_t mFieldLength;
67 uint32_t mLocalFieldLength;
68 uint16_t mVersionMade;
69 uint16_t mVersionNeeded;
70 uint16_t mFlags;
71 uint16_t mMethod;
72 uint16_t mTime;
73 uint16_t mDate;
74 uint16_t mDisk;
75 uint16_t mIAttr;
76 bool mInited;
77 bool mWriteOnClose;
78 nsCString mName;
79 nsCString mComment;
80 nsAutoArrayPtr<uint8_t> mExtraField;
81 nsAutoArrayPtr<uint8_t> mLocalExtraField;
82
83 void Init(const nsACString & aPath, PRTime aDate, uint32_t aAttr,
84 uint32_t aOffset);
85 uint32_t GetFileHeaderLength();
86 nsresult WriteFileHeader(nsIOutputStream *aStream);
87 uint32_t GetCDSHeaderLength();
88 nsresult WriteCDSHeader(nsIOutputStream *aStream);
89 nsresult ReadCDSHeader(nsIInputStream *aStream);
90 const uint8_t * GetExtraField(uint16_t aTag, bool aLocal, uint16_t *aBlockSize);
91 nsresult PadExtraField(uint32_t aOffset, uint16_t aAlignSize);
92 };
93
94 #endif

mercurial