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