1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/libjar/zipwriter/src/nsZipHeader.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 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 _nsZipHeader_h_ 1.10 +#define _nsZipHeader_h_ 1.11 + 1.12 +#include "nsString.h" 1.13 +#include "nsIOutputStream.h" 1.14 +#include "nsIInputStream.h" 1.15 +#include "nsIZipReader.h" 1.16 +#include "nsAutoPtr.h" 1.17 +#include "mozilla/Attributes.h" 1.18 + 1.19 +// High word is S_IFREG, low word is DOS file attribute 1.20 +#define ZIP_ATTRS_FILE 0x80000000 1.21 +// High word is S_IFDIR, low word is DOS dir attribute 1.22 +#define ZIP_ATTRS_DIRECTORY 0x40000010 1.23 +#define PERMISSIONS_FILE 0644 1.24 +#define PERMISSIONS_DIR 0755 1.25 + 1.26 +// Combine file type attributes with unix style permissions 1.27 +#define ZIP_ATTRS(p, a) ((p & 0xfff) << 16) | a 1.28 + 1.29 +class nsZipHeader MOZ_FINAL : public nsIZipEntry 1.30 +{ 1.31 +public: 1.32 + NS_DECL_ISUPPORTS 1.33 + NS_DECL_NSIZIPENTRY 1.34 + 1.35 + nsZipHeader() : 1.36 + mCRC(0), 1.37 + mCSize(0), 1.38 + mUSize(0), 1.39 + mEAttr(0), 1.40 + mOffset(0), 1.41 + mFieldLength(0), 1.42 + mLocalFieldLength(0), 1.43 + mVersionMade(0x0300 + 23), // Generated on Unix by v2.3 (matches infozip) 1.44 + mVersionNeeded(20), // Requires v2.0 to extract 1.45 + mFlags(0), 1.46 + mMethod(0), 1.47 + mTime(0), 1.48 + mDate(0), 1.49 + mDisk(0), 1.50 + mIAttr(0), 1.51 + mInited(false), 1.52 + mWriteOnClose(false), 1.53 + mExtraField(nullptr), 1.54 + mLocalExtraField(nullptr) 1.55 + { 1.56 + } 1.57 + 1.58 + ~nsZipHeader() 1.59 + { 1.60 + mExtraField = nullptr; 1.61 + mLocalExtraField = nullptr; 1.62 + } 1.63 + 1.64 + uint32_t mCRC; 1.65 + uint32_t mCSize; 1.66 + uint32_t mUSize; 1.67 + uint32_t mEAttr; 1.68 + uint32_t mOffset; 1.69 + uint32_t mFieldLength; 1.70 + uint32_t mLocalFieldLength; 1.71 + uint16_t mVersionMade; 1.72 + uint16_t mVersionNeeded; 1.73 + uint16_t mFlags; 1.74 + uint16_t mMethod; 1.75 + uint16_t mTime; 1.76 + uint16_t mDate; 1.77 + uint16_t mDisk; 1.78 + uint16_t mIAttr; 1.79 + bool mInited; 1.80 + bool mWriteOnClose; 1.81 + nsCString mName; 1.82 + nsCString mComment; 1.83 + nsAutoArrayPtr<uint8_t> mExtraField; 1.84 + nsAutoArrayPtr<uint8_t> mLocalExtraField; 1.85 + 1.86 + void Init(const nsACString & aPath, PRTime aDate, uint32_t aAttr, 1.87 + uint32_t aOffset); 1.88 + uint32_t GetFileHeaderLength(); 1.89 + nsresult WriteFileHeader(nsIOutputStream *aStream); 1.90 + uint32_t GetCDSHeaderLength(); 1.91 + nsresult WriteCDSHeader(nsIOutputStream *aStream); 1.92 + nsresult ReadCDSHeader(nsIInputStream *aStream); 1.93 + const uint8_t * GetExtraField(uint16_t aTag, bool aLocal, uint16_t *aBlockSize); 1.94 + nsresult PadExtraField(uint32_t aOffset, uint16_t aAlignSize); 1.95 +}; 1.96 + 1.97 +#endif