Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TZIPFile.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/io:$Id$
0002 // Author: Fons Rademakers   30/6/04
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TZIPFile
0013 #define ROOT_TZIPFile
0014 
0015 #include "TArchiveFile.h"
0016 
0017 class TZIPMember;
0018 
0019 
0020 class TZIPFile : public TArchiveFile {
0021 
0022 protected:
0023    Long64_t    fDirPos;     ///< Central directory position
0024    Long64_t    fDirSize;    ///< Central directory size
0025    Long64_t    fDirOffset;  ///< Central directory offset (from the beginning of the archive)
0026    TString     fComment;    ///< Archive comment
0027 
0028    Long64_t   FindEndHeader();
0029    Int_t      ReadEndHeader(Long64_t pos);
0030    Long64_t   ReadZip64EndLocator(Long64_t pos);
0031    Int_t      ReadZip64EndRecord(Long64_t pos);
0032    Int_t      ReadDirectory();
0033    Int_t      ReadMemberHeader(TZIPMember *member);
0034    UInt_t     Get(const void *buffer, Int_t bytes);
0035    ULong64_t  Get64(const void *buffer, Int_t bytes);
0036    Int_t      DecodeZip64ExtendedExtraField(TZIPMember *m, Bool_t global = kTRUE);
0037 
0038    /// ZIP archive constants
0039    enum EZIPConstants {
0040       // - Archive version required (and made)
0041       kARCHIVE_VERSION     = 45,
0042 
0043       // - Magic header constants
0044       kDIR_HEADER_MAGIC       = 0x02014b50,
0045       kENTRY_HEADER_MAGIC     = 0x04034b50,
0046       kEND_HEADER_MAGIC       = 0x06054b50,
0047       kZIP64_EDR_HEADER_MAGIC = 0x06064b50,
0048       kZIP64_EDL_HEADER_MAGIC = 0x07064b50,
0049       kZIP64_EXTENDED_MAGIC   = 0x0001,     ///< Zip64 Extended Information Extra Field
0050       kZIP_MAGIC_LEN          = 4,          ///< Length of magic's
0051       kMAX_VAR_LEN            = 0xffff,     ///< Max variable-width field length
0052       kMAX_SIZE               = 0xffffffff, ///< Max size of things
0053 
0054       // - Offsets into the central directory headers
0055       kDIR_MAGIC_OFF      = 0,
0056       kDIR_VMADE_OFF      = 4,    kDIR_VMADE_LEN          = 2,
0057       kDIR_VREQD_OFF      = 6,    kDIR_VREQD_LEN          = 2,
0058       kDIR_FLAG_OFF       = 8,    kDIR_FLAG_LEN           = 2,
0059       kDIR_METHOD_OFF     = 10,   kDIR_METHOD_LEN         = 2,
0060       kDIR_DATE_OFF       = 12,   kDIR_DATE_LEN           = 4,
0061       kDIR_CRC32_OFF      = 16,   kDIR_CRC32_LEN          = 4,
0062       kDIR_CSIZE_OFF      = 20,   kDIR_CSIZE_LEN          = 4,
0063       kDIR_USIZE_OFF      = 24,   kDIR_USIZE_LEN          = 4,
0064       kDIR_NAMELEN_OFF    = 28,   kDIR_NAMELEN_LEN        = 2,
0065       kDIR_EXTRALEN_OFF   = 30,   kDIR_EXTRALEN_LEN       = 2,
0066       kDIR_COMMENTLEN_OFF = 32,   kDIR_COMMENTLEN_LEN     = 2,
0067       kDIR_DISK_START_OFF = 34,   kDIR_DISK_START_LEN     = 2,
0068       kDIR_INT_ATTR_OFF   = 36,   kDIR_INT_ATTR_LEN       = 2,
0069       kDIR_EXT_ATTR_OFF   = 38,   kDIR_EXT_ATTR_LEN       = 4,
0070       kDIR_ENTRY_POS_OFF  = 42,   kDIR_ENTRY_POS_LEN      = 4,
0071       kDIR_HEADER_SIZE    = 46,
0072 
0073       // - Offsets into the Zip64 end of central directory record (EDR)
0074       kZIP64_EDR_MAGIC_OFF      = 0,
0075       kZIP64_EDR_SIZE_OFF       = 4,  kZIP64_EDR_SIZE_LEN       = 8,
0076       kZIP64_EDR_VERS_MADE_OFF  = 12, kZIP64_EDR_VERS_MADE_LEN  = 2,
0077       kZIP64_EDR_VERS_EXT_OFF   = 14, kZIP64_EDR_VERS_EXT_LEN   = 2,
0078       kZIP64_EDR_DISK_OFF       = 16, kZIP64_EDR_DISK_LEN       = 4,
0079       kZIP64_EDR_DIR_DISK_OFF   = 20, kZIP64_EDR_DIR_DISK_LEN   = 4,
0080       kZIP64_EDR_DISK_HDRS_OFF  = 24, kZIP64_EDR_DISK_HDRS_LEN  = 8,
0081       kZIP64_EDR_TOTAL_HDRS_OFF = 32, kZIP64_EDR_TOTAL_HDRS_LEN = 8,
0082       kZIP64_EDR_DIR_SIZE_OFF   = 40, kZIP64_EDR_DIR_SIZE_LEN   = 8,
0083       kZIP64_EDR_DIR_OFFSET_OFF = 48, kZIP64_EDR_DIR_OFFSET_LEN = 8,
0084       kZIP64_EDR_HEADER_SIZE    = 56,
0085 
0086       // - Offsets into the Zip64 end of central directory locator (EDL)
0087       kZIP64_EDL_MAGIC_OFF      = 0,
0088       kZIP64_EDL_DISK_OFF       = 4,  kZIP64_EDL_DISK_LEN       = 4,
0089       kZIP64_EDL_REC_OFFSET_OFF = 8,  kZIP64_EDL_REC_OFFSET_LEN = 8,
0090       kZIP64_EDL_TOTAL_DISK_OFF = 16, kZIP64_EDL_TOTAL_DISK_LEN = 4,
0091       kZIP64_EDL_HEADER_SIZE    = 20,
0092 
0093       // - Offsets into the end-of-archive header
0094       kEND_MAGIC_OFF      = 0,
0095       kEND_DISK_OFF       = 4,    kEND_DISK_LEN           = 2,
0096       kEND_DIR_DISK_OFF   = 6,    kEND_DIR_DISK_LEN       = 2,
0097       kEND_DISK_HDRS_OFF  = 8,    kEND_DISK_HDRS_LEN      = 2,
0098       kEND_TOTAL_HDRS_OFF = 10,   kEND_TOTAL_HDRS_LEN     = 2,
0099       kEND_DIR_SIZE_OFF   = 12,   kEND_DIR_SIZE_LEN       = 4,
0100       kEND_DIR_OFFSET_OFF = 16,   kEND_DIR_OFFSET_LEN     = 4,
0101       kEND_COMMENTLEN_OFF = 20,   kEND_COMMENTLEN_LEN     = 2,
0102       kEND_HEADER_SIZE    = 22,
0103 
0104       // - Offsets into the local entry headers
0105       kENTRY_MAGIC_OFF    = 0,
0106       kENTRY_VREQD_OFF    = 4,    kENTRY_VREQD_LEN        = 2,
0107       kENTRY_FLAG_OFF     = 6,    kENTRY_FLAG_LEN         = 2,
0108       kENTRY_METHOD_OFF   = 8,    kENTRY_METHOD_LEN       = 2,
0109       kENTRY_DATE_OFF     = 10,   kENTRY_DATE_LEN         = 4,
0110       kENTRY_CRC32_OFF    = 14,   kENTRY_CRC32_LEN        = 4,
0111       kENTRY_CSIZE_OFF    = 18,   kENTRY_CSIZE_LEN        = 4,
0112       kENTRY_USIZE_OFF    = 22,   kENTRY_USIZE_LEN        = 4,
0113       kENTRY_NAMELEN_OFF  = 26,   kENTRY_NAMELEN_LEN      = 2,
0114       kENTRY_EXTRALEN_OFF = 28,   kENTRY_EXTRALEN_LEN     = 2,
0115       kENTRY_HEADER_SIZE  = 30,
0116 
0117       // - Offsets into the Zip64 Extended Information Extra Field
0118       kZIP64_EXTENDED_MAGIC_OFF      = 0,  kZIP64_EXTENDED_MAGIC_LEN      = 2,
0119       kZIP64_EXTENDED_SIZE_OFF       = 2,  kZIP64_EXTENDED_SIZE_LEN       = 2,
0120       kZIP64_EXTENDED_USIZE_OFF      = 4,  kZIP64_EXTENDED_USIZE_LEN      = 8,
0121       kZIP64_EXTENTED_CSIZE_OFF      = 12, kZIP64_EXTENDED_CSIZE_LEN      = 8,
0122       kZIP64_EXTENDED_HDR_OFFSET_OFF = 20, kZIP64_EXTENDED_HDR_OFFSET_LEN = 8,
0123       kZIP64_EXTENDED_DISK_OFF       = 28, kZIP64_EXTENDED_DISK_LEN       = 4,
0124       kZIP64_EXTENDED_SIZE           = 32,
0125 
0126       // - Compression method and strategy
0127       kSTORED              = 0,            ///< Stored as is
0128       kDEFLATED            = 8             ///< Stored using deflate
0129    };
0130 
0131    TZIPFile(const TZIPFile&) = delete; // Not implemented
0132    TZIPFile& operator=(const TZIPFile&) = delete; // Not implemented
0133 
0134 public:
0135    TZIPFile();
0136    TZIPFile(const char *archive, const char *member, TFile *file);
0137    ~TZIPFile() override { }
0138 
0139    Int_t      OpenArchive() override;
0140    Int_t      SetCurrentMember() override;
0141 
0142    void       Print(Option_t *option = "") const override;
0143 
0144    ClassDefOverride(TZIPFile,1)  //A ZIP archive file
0145 };
0146 
0147 /**
0148 \class TZIPMember
0149 \ingroup IO
0150 A ZIP archive consists of files compressed with the popular ZLIB
0151 compression algorithm; this class records the information about a
0152 single archive member.
0153 */
0154 
0155 
0156 class TZIPMember : public TArchiveMember {
0157 
0158 friend class TZIPFile;
0159 
0160 private:
0161    void          *fLocal;     ///< Extra file header data
0162    UInt_t         fLocalLen;  ///< Length of extra file header data
0163    void          *fGlobal;    ///< Extra directory data
0164    UInt_t         fGlobalLen; ///< Length of extra directory data
0165    UInt_t         fCRC32;     ///< CRC-32 for all decompressed data
0166    UInt_t         fAttrInt;   ///< Internal file attributes
0167    UInt_t         fAttrExt;   ///< External file attributes
0168    UInt_t         fMethod;    ///< Compression type
0169    UInt_t         fLevel;     ///< Compression level
0170 
0171 public:
0172    TZIPMember();
0173    TZIPMember(const char *name);
0174    TZIPMember(const TZIPMember &member);
0175    TZIPMember &operator=(const TZIPMember &rhs);
0176    ~TZIPMember() override;
0177 
0178    void     *GetLocal() const { return fLocal; }
0179    UInt_t    GetLocalLen() const { return fLocalLen; }
0180    void     *GetGlobal() const { return fGlobal; }
0181    UInt_t    GetGlobalLen() const { return fGlobalLen; }
0182    UInt_t    GetCRC32() const { return fCRC32; }
0183    UInt_t    GetAttrInt() const { return fAttrInt; }
0184    UInt_t    GetAttrExt() const { return fAttrExt; }
0185    UInt_t    GetMethod() const { return fMethod; }
0186    UInt_t    GetLevel() const { return fLevel; }
0187 
0188    void      Print(Option_t *option = "") const override;
0189 
0190    ClassDefOverride(TZIPMember, 0);  //A ZIP archive member file
0191 };
0192 
0193 #endif