ROOT  6.06/09
Reference Guide
TZIPFile.h
Go to the documentation of this file.
1 // @(#)root/io:$Id$
2 // Author: Fons Rademakers 30/6/04
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TZIPFile
13 #define ROOT_TZIPFile
14 
15 #ifndef ROOT_TArchiveFile
16 #include "TArchiveFile.h"
17 #endif
18 
19 class TZIPMember;
20 
21 
22 class TZIPFile : public TArchiveFile {
23 
24 protected:
25  Long64_t fDirPos; ///< Central directory position
26  Long64_t fDirSize; ///< Central directory size
27  Long64_t fDirOffset; ///< Central directory offset (from the beginning of the archive)
28  TString fComment; ///< Archive comment
29 
36  UInt_t Get(const void *buffer, Int_t bytes);
37  ULong64_t Get64(const void *buffer, Int_t bytes);
39 
40  /// ZIP archive constants
42  // - Archive version required (and made)
44 
45  // - Magic header constants
46  kDIR_HEADER_MAGIC = 0x02014b50,
47  kENTRY_HEADER_MAGIC = 0x04034b50,
48  kEND_HEADER_MAGIC = 0x06054b50,
51  kZIP64_EXTENDED_MAGIC = 0x0001, ///< Zip64 Extended Information Extra Field
52  kZIP_MAGIC_LEN = 4, ///< Length of magic's
53  kMAX_VAR_LEN = 0xffff, ///< Max variable-width field length
54  kMAX_SIZE = 0xffffffff, ///< Max size of things
55 
56  // - Offsets into the central directory headers
74 
75  // - Offsets into the Zip64 end of central directory record (EDR)
87 
88  // - Offsets into the Zip64 end of central directory locator (EDL)
94 
95  // - Offsets into the end-of-archive header
105 
106  // - Offsets into the local entry headers
118 
119  // - Offsets into the Zip64 Extended Information Extra Field
127 
128  // - Compression method and strategy
129  kSTORED = 0, ///< Stored as is
130  kDEFLATED = 8 ///< Stored using deflate
131  };
132 
133  TZIPFile(const TZIPFile&); // Not implemented
134  TZIPFile& operator=(const TZIPFile&); // Not implemented
135 
136 public:
137  TZIPFile();
138  TZIPFile(const char *archive, const char *member, TFile *file);
139  virtual ~TZIPFile() { }
140 
141  virtual Int_t OpenArchive();
142  virtual Int_t SetCurrentMember();
143 
144  void Print(Option_t *option = "") const;
145 
146  ClassDef(TZIPFile,1) //A ZIP archive file
147 };
148 
149 /**
150 \class TZIPMember
151 \ingroup IO
152 A ZIP archive consists of files compressed with the popular ZLIB
153 compression algorithm; this class records the information about a
154 single archive member.
155 */
156 
157 
158 class TZIPMember : public TArchiveMember {
159 
160 friend class TZIPFile;
161 
162 private:
163  void *fLocal; ///< Extra file header data
164  UInt_t fLocalLen; ///< Length of extra file header data
165  void *fGlobal; ///< Extra directory data
166  UInt_t fGlobalLen; ///< Length of extra directory data
167  UInt_t fCRC32; ///< CRC-32 for all decompressed data
168  UInt_t fAttrInt; ///< Internal file attributes
169  UInt_t fAttrExt; ///< External file attributes
170  UInt_t fMethod; ///< Compression type
171  UInt_t fLevel; ///< Compression level
172 
173 public:
174  TZIPMember();
175  TZIPMember(const char *name);
176  TZIPMember(const TZIPMember &member);
177  TZIPMember &operator=(const TZIPMember &rhs);
178  virtual ~TZIPMember();
179 
180  void *GetLocal() const { return fLocal; }
181  UInt_t GetLocalLen() const { return fLocalLen; }
182  void *GetGlobal() const { return fGlobal; }
183  UInt_t GetGlobalLen() const { return fGlobalLen; }
184  UInt_t GetCRC32() const { return fCRC32; }
185  UInt_t GetAttrInt() const { return fAttrInt; }
186  UInt_t GetAttrExt() const { return fAttrExt; }
187  UInt_t GetMethod() const { return fMethod; }
188  UInt_t GetLevel() const { return fLevel; }
189 
190  void Print(Option_t *option = "") const;
191 
192  ClassDef(TZIPMember,2) //A ZIP archive member file
193 };
194 
195 #endif
Stored using deflate.
Definition: TZIPFile.h:130
Class describing an archive file containing multiple sub-files, like a ZIP or TAR archive...
Definition: TArchiveFile.h:30
Int_t ReadZip64EndRecord(Long64_t pos)
Read Zip64 end of central directory record.
Definition: TZIPFile.cxx:246
TZIPMember & operator=(const TZIPMember &rhs)
Assignment operator.
Definition: TZIPFile.cxx:628
virtual Int_t SetCurrentMember()
Find the desired member in the member array and make it the current member.
Definition: TZIPFile.cxx:486
long long Long64_t
Definition: RtypesCore.h:69
Long64_t fDirSize
Central directory size.
Definition: TZIPFile.h:26
virtual Int_t OpenArchive()
Open archive and read end-header and directory.
Definition: TZIPFile.cxx:88
void * fLocal
Extra file header data.
Definition: TZIPFile.h:163
Stored as is.
Definition: TZIPFile.h:129
const char Option_t
Definition: RtypesCore.h:62
Max variable-width field length.
Definition: TZIPFile.h:53
Int_t ReadMemberHeader(TZIPMember *member)
Read the member header of the ZIP archive.
Definition: TZIPFile.cxx:404
Long64_t FindEndHeader()
Find the end header of the ZIP archive. Returns 0 in case of error.
Definition: TZIPFile.cxx:98
UInt_t Get(const void *buffer, Int_t bytes)
Read a "bytes" long little-endian integer value from "buffer".
Definition: TZIPFile.cxx:514
UInt_t GetCRC32() const
Definition: TZIPFile.h:184
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
Definition: TFile.h:45
Int_t ReadEndHeader(Long64_t pos)
Read the end header of the ZIP archive including the archive comment at the current file position...
Definition: TZIPFile.cxx:139
UInt_t GetLocalLen() const
Definition: TZIPFile.h:181
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Length of magic's.
Definition: TZIPFile.h:52
TString fComment
Archive comment.
Definition: TZIPFile.h:28
ULong64_t Get64(const void *buffer, Int_t bytes)
Read a 8 byte long little-endian integer value from "buffer".
Definition: TZIPFile.cxx:535
UInt_t GetLevel() const
Definition: TZIPFile.h:188
Long64_t fDirPos
Central directory position.
Definition: TZIPFile.h:25
Zip64 Extended Information Extra Field.
Definition: TZIPFile.h:51
#define ClassDef(name, id)
Definition: Rtypes.h:254
Describes a ZIP archive file containing multiple sub-files.
Definition: TZIPFile.h:22
void Print(Option_t *option="") const
Pretty print basic ZIP member info.
Definition: TZIPFile.cxx:670
UInt_t GetAttrInt() const
Definition: TZIPFile.h:185
void Print(Option_t *option="") const
Pretty print ZIP archive members.
Definition: TZIPFile.cxx:557
UInt_t GetAttrExt() const
Definition: TZIPFile.h:186
Long64_t ReadZip64EndLocator(Long64_t pos)
Read Zip64 end of central directory locator.
Definition: TZIPFile.cxx:211
EZIPConstants
ZIP archive constants.
Definition: TZIPFile.h:41
Max size of things.
Definition: TZIPFile.h:54
UInt_t fGlobalLen
Length of extra directory data.
Definition: TZIPFile.h:166
Int_t ReadDirectory()
Read the directory of the ZIP archive.
Definition: TZIPFile.cxx:278
unsigned int UInt_t
Definition: RtypesCore.h:42
TMarker * m
Definition: textangle.C:8
UInt_t fMethod
Compression type.
Definition: TZIPFile.h:170
Long64_t fDirOffset
Central directory offset (from the beginning of the archive)
Definition: TZIPFile.h:27
void * GetGlobal() const
Definition: TZIPFile.h:182
UInt_t fAttrExt
External file attributes.
Definition: TZIPFile.h:169
unsigned long long ULong64_t
Definition: RtypesCore.h:70
UInt_t GetGlobalLen() const
Definition: TZIPFile.h:183
virtual ~TZIPMember()
Cleanup.
Definition: TZIPFile.cxx:661
#define name(a, b)
Definition: linkTestLib0.cpp:5
virtual ~TZIPFile()
Definition: TZIPFile.h:139
void * GetLocal() const
Definition: TZIPFile.h:180
Int_t DecodeZip64ExtendedExtraField(TZIPMember *m, Bool_t global=kTRUE)
Decode the Zip64 extended extra field.
Definition: TZIPFile.cxx:441
UInt_t fLocalLen
Length of extra file header data.
Definition: TZIPFile.h:164
UInt_t fLevel
Compression level.
Definition: TZIPFile.h:171
UInt_t GetMethod() const
Definition: TZIPFile.h:187
void * fGlobal
Extra directory data.
Definition: TZIPFile.h:165
A ZIP archive consists of files compressed with the popular ZLIB compression algorithm; this class re...
Definition: TZIPFile.h:158
const Bool_t kTRUE
Definition: Rtypes.h:91
TZIPFile & operator=(const TZIPFile &)
UInt_t fAttrInt
Internal file attributes.
Definition: TZIPFile.h:168
UInt_t fCRC32
CRC-32 for all decompressed data.
Definition: TZIPFile.h:167