XRootD
XrdZipZIP64EOCDL.hh
Go to the documentation of this file.
1 /*
2  * XrdZipZIP64EOCDL.hh
3  *
4  * Created on: 9 Nov 2020
5  * Author: simonm
6  */
7 
8 #ifndef SRC_XRDZIP_XRDZIPZIP64EOCDL_HH_
9 #define SRC_XRDZIP_XRDZIPZIP64EOCDL_HH_
10 
11 #include "XrdZip/XrdZipUtils.hh"
12 #include "XrdZip/XrdZipEOCD.hh"
14 #include <string>
15 #include <sstream>
16 
17 namespace XrdZip
18 {
19  //---------------------------------------------------------------------------
21  //---------------------------------------------------------------------------
22  struct ZIP64_EOCDL
23  {
24  //-------------------------------------------------------------------------
26  //-------------------------------------------------------------------------
27  ZIP64_EOCDL( const char *buffer )
28  {
29  nbDiskZip64Eocd = to<uint32_t>(buffer + 4);
30  zip64EocdOffset = to<uint64_t>(buffer + 8);
31  totalNbDisks = to<uint32_t>(buffer + 16);
32  }
33 
34  //-------------------------------------------------------------------------
36  //-------------------------------------------------------------------------
37  ZIP64_EOCDL( const EOCD &eocd, const ZIP64_EOCD &zip64Eocd ):
38  nbDiskZip64Eocd( 0 ),
39  totalNbDisks( 1 )
40  {
41  if ( eocd.cdOffset == ovrflw<uint32_t>::value )
42  zip64EocdOffset = zip64Eocd.cdOffset;
43  else
45 
46  if ( eocd.cdSize == ovrflw<uint32_t>::value )
47  zip64EocdOffset += zip64Eocd.cdSize;
48  else
49  zip64EocdOffset += eocd.cdSize;
50  }
51 
52  //-------------------------------------------------------------------------
54  //-------------------------------------------------------------------------
55  void Serialize( buffer_t &buffer )
56  {
57  copy_bytes( zip64EocdlSign, buffer );
58  copy_bytes( nbDiskZip64Eocd, buffer );
59  copy_bytes( zip64EocdOffset, buffer );
60  copy_bytes( totalNbDisks, buffer );
61  }
62 
63  //-------------------------------------------------------------------------
65  //-------------------------------------------------------------------------
66  std::string ToString()
67  {
68  std::stringstream ss;
69  ss << "{nbDiskZip64Eocd=" << nbDiskZip64Eocd;
70  ss << ";zip64EocdOffset=" << zip64EocdOffset;
71  ss << ";totalNbDisks=" << totalNbDisks << "}";
72  return ss.str();
73  }
74 
75  uint32_t nbDiskZip64Eocd; //< number of the disk with the start of the zip64 end of central directory
76  uint64_t zip64EocdOffset; //< relative offset of the zip64 end of central directory record
77  uint32_t totalNbDisks; //< total number of disks
78 
79  //-------------------------------------------------------------------------
80  // the End of Central Directory locator signature
81  //-------------------------------------------------------------------------
82  static const uint32_t zip64EocdlSign = 0x07064b50;
83  static const uint16_t zip64EocdlSize = 20;
84  };
85 }
86 
87 #endif /* SRC_XRDZIP_XRDZIPZIP64EOCDL_HH_ */
std::vector< char > buffer_t
Definition: XrdZipUtils.hh:56
static void copy_bytes(const INT value, buffer_t &buffer)
Definition: XrdZipUtils.hh:62
uint32_t cdOffset
Definition: XrdZipEOCD.hh:143
uint32_t cdSize
Definition: XrdZipEOCD.hh:142
A data structure representing the ZIP64 end of central directory locator.
static const uint32_t zip64EocdlSign
static const uint16_t zip64EocdlSize
void Serialize(buffer_t &buffer)
Serialize the object into a buffer.
ZIP64_EOCDL(const char *buffer)
Constructor from a buffer.
ZIP64_EOCDL(const EOCD &eocd, const ZIP64_EOCD &zip64Eocd)
Constructor from EOCD and ZIP64 EOCD.
std::string ToString()
Convert the EOCDL into a string for logging purposes.