TZIPFile.h

Go to the documentation of this file.
00001 // @(#)root/io:$Id: TZIPFile.h 23916 2008-05-19 20:01:28Z brun $
00002 // Author: Fons Rademakers   30/6/04
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TZIPFile
00013 #define ROOT_TZIPFile
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TZIPFile                                                             //
00019 //                                                                      //
00020 // This class describes a ZIP archive file containing multiple          //
00021 // sub-files. Typically the sub-files are ROOT files. Notice that       //
00022 // the ROOT files should not be compressed when being added to the      //
00023 // ZIP file, since ROOT files are normally already compressed.          //
00024 // Such a ZIP file should be created like:                              //
00025 //                                                                      //
00026 //    zip -n root multi file1.root file2.root                           //
00027 //                                                                      //
00028 // which creates a ZIP file multi.zip.                                  //
00029 //                                                                      //
00030 // For more on the ZIP file structure see TZIPFile.cxx.                 //
00031 //                                                                      //
00032 //////////////////////////////////////////////////////////////////////////
00033 
00034 #ifndef ROOT_TArchiveFile
00035 #include "TArchiveFile.h"
00036 #endif
00037 
00038 class TZIPMember;
00039 
00040 
00041 class TZIPFile : public TArchiveFile {
00042 
00043 protected:
00044    Long64_t    fDirPos;     // Central directory position
00045    Long64_t    fDirSize;    // Central directory size
00046    Long64_t    fDirOffset;  // Central directory offset (from the beginning of the archive)
00047    TString     fComment;    // Archive comment
00048 
00049    Long64_t   FindEndHeader();
00050    Int_t      ReadEndHeader(Long64_t pos);
00051    Int_t      ReadDirectory();
00052    Int_t      ReadMemberHeader(TZIPMember *member);
00053    UInt_t     Get(const void *buffer, Int_t bytes);
00054 
00055    // ZIP archive constants
00056    enum EZIPConstants {
00057       // - Archive version required (and made)
00058       kARCHIVE_VERSION     = 20,
00059 
00060       // - Magic header constants
00061       kDIR_HEADER_MAGIC    = 0x02014b50,
00062       kENTRY_HEADER_MAGIC  = 0x04034b50,
00063       kEND_HEADER_MAGIC    = 0x06054b50,
00064       kZIP_MAGIC_LEN       = 4,
00065       kMAX_VAR_LEN         = 0xffff,     // Max variable-width field length
00066       kMAX_SIZE            = 0xffffffff, // Max size of things
00067 
00068       // - Offsets into the central directory headers
00069       kDIR_MAGIC_OFF      = 0,
00070       kDIR_VMADE_OFF      = 4,    kDIR_VMADE_LEN          = 2,
00071       kDIR_VREQD_OFF      = 6,    kDIR_VREQD_LEN          = 2,
00072       kDIR_FLAG_OFF       = 8,    kDIR_FLAG_LEN           = 2,
00073       kDIR_METHOD_OFF     = 10,   kDIR_METHOD_LEN         = 2,
00074       kDIR_DATE_OFF       = 12,   kDIR_DATE_LEN           = 4,
00075       kDIR_CRC32_OFF      = 16,   kDIR_CRC32_LEN          = 4,
00076       kDIR_CSIZE_OFF      = 20,   kDIR_CSIZE_LEN          = 4,
00077       kDIR_USIZE_OFF      = 24,   kDIR_USIZE_LEN          = 4,
00078       kDIR_NAMELEN_OFF    = 28,   kDIR_NAMELEN_LEN        = 2,
00079       kDIR_EXTRALEN_OFF   = 30,   kDIR_EXTRALEN_LEN       = 2,
00080       kDIR_COMMENTLEN_OFF = 32,   kDIR_COMMENTLEN_LEN     = 2,
00081       kDIR_DISK_START_OFF = 34,   kDIR_DISK_START_LEN     = 2,
00082       kDIR_INT_ATTR_OFF   = 36,   kDIR_INT_ATTR_LEN       = 2,
00083       kDIR_EXT_ATTR_OFF   = 38,   kDIR_EXT_ATTR_LEN       = 4,
00084       kDIR_ENTRY_POS_OFF  = 42,   kDIR_ENTRY_POS_LEN      = 4,
00085       kDIR_HEADER_SIZE    = 46,
00086 
00087       // - Offsets into the end-of-archive header
00088       kEND_MAGIC_OFF      = 0,
00089       kEND_DISK_OFF       = 4,    kEND_DISK_LEN           = 2,
00090       kEND_DIR_DISK_OFF   = 6,    kEND_DIR_DISK_LEN       = 2,
00091       kEND_DISK_HDRS_OFF  = 8,    kEND_DISK_HDRS_LEN      = 2,
00092       kEND_TOTAL_HDRS_OFF = 10,   kEND_TOTAL_HDRS_LEN     = 2,
00093       kEND_DIR_SIZE_OFF   = 12,   kEND_DIR_SIZE_LEN       = 4,
00094       kEND_DIR_OFFSET_OFF = 16,   kEND_DIR_OFFSET_LEN     = 4,
00095       kEND_COMMENTLEN_OFF = 20,   kEND_COMMENTLEN_LEN     = 2,
00096       kEND_HEADER_SIZE    = 22,
00097 
00098       // - Offsets into the local entry headers
00099       kENTRY_MAGIC_OFF    = 0,
00100       kENTRY_VREQD_OFF    = 4,    kENTRY_VREQD_LEN        = 2,
00101       kENTRY_FLAG_OFF     = 6,    kENTRY_FLAG_LEN         = 2,
00102       kENTRY_METHOD_OFF   = 8,    kENTRY_METHOD_LEN       = 2,
00103       kENTRY_DATE_OFF     = 10,   kENTRY_DATE_LEN         = 4,
00104       kENTRY_CRC32_OFF    = 14,   kENTRY_CRC32_LEN        = 4,
00105       kENTRY_CSIZE_OFF    = 18,   kENTRY_CSIZE_LEN        = 4,
00106       kENTRY_USIZE_OFF    = 22,   kENTRY_USIZE_LEN        = 4,
00107       kENTRY_NAMELEN_OFF  = 26,   kENTRY_NAMELEN_LEN      = 2,
00108       kENTRY_EXTRALEN_OFF = 28,   kENTRY_EXTRALEN_LEN     = 2,
00109       kENTRY_HEADER_SIZE  = 30,
00110 
00111       // - Compression method and strategy
00112       kSTORED              = 0,            // Stored as is
00113       kDEFLATED            = 8             // Stored using deflate
00114    };
00115 
00116    TZIPFile(const TZIPFile&); // Not implemented
00117    TZIPFile& operator=(const TZIPFile&); // Not implemented
00118 
00119 public:
00120    TZIPFile();
00121    TZIPFile(const char *archive, const char *member, TFile *file);
00122    virtual ~TZIPFile() { }
00123 
00124    virtual Int_t OpenArchive();
00125    virtual Int_t SetCurrentMember();
00126 
00127    void          Print(Option_t *option = "") const;
00128 
00129    ClassDef(TZIPFile,1)  //A ZIP archive file
00130 };
00131 
00132 
00133 //////////////////////////////////////////////////////////////////////////
00134 //                                                                      //
00135 // TZIPMember                                                           //
00136 //                                                                      //
00137 // A ZIP archive consists of files compressed with the popular ZLIB     //
00138 // compression algorithm; this class records the information about a    //
00139 // single archive member.                                               //
00140 //                                                                      //
00141 //////////////////////////////////////////////////////////////////////////
00142 
00143 class TZIPMember : public TArchiveMember {
00144 
00145 friend class TZIPFile;
00146 
00147 private:
00148    void          *fLocal;     // Extra file header data
00149    Long64_t       fLocalLen;  // Length of extra file header data
00150    void          *fGlobal;    // Extra directory data
00151    Long64_t       fGlobalLen; // Length of extra directory data
00152    UInt_t         fCRC32;     // CRC-32 for all decompressed data
00153    UInt_t         fAttrInt;   // Internal file attributes
00154    UInt_t         fAttrExt;   // External file attributes
00155    UInt_t         fMethod;    // Compression type
00156    UInt_t         fLevel;     // Compression level
00157 
00158 public:
00159    TZIPMember();
00160    TZIPMember(const char *name);
00161    TZIPMember(const TZIPMember &member);
00162    TZIPMember &operator=(const TZIPMember &rhs);
00163    virtual ~TZIPMember();
00164 
00165    void     *GetLocal() const { return fLocal; }
00166    Long64_t  GetLocalLen() const { return fLocalLen; }
00167    void     *GetGlobal() const { return fGlobal; }
00168    Long64_t  GetGlobalLen() const { return fGlobalLen; }
00169    UInt_t    GetCRC32() const { return fCRC32; }
00170    UInt_t    GetAttrInt() const { return fAttrInt; }
00171    UInt_t    GetAttrExt() const { return fAttrExt; }
00172    UInt_t    GetMethod() const { return fMethod; }
00173    UInt_t    GetLevel() const { return fLevel; }
00174 
00175    void      Print(Option_t *option = "") const;
00176 
00177    ClassDef(TZIPMember,1)  //A ZIP archive member file
00178 };
00179 
00180 #endif

Generated on Tue Jul 5 14:28:32 2011 for ROOT_528-00b_version by  doxygen 1.5.1