Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:38

0001 /*
0002  * XrdZipZIP64EOCD.hh
0003  *
0004  *  Created on: 9 Nov 2020
0005  *      Author: simonm
0006  */
0007 
0008 #ifndef SRC_XRDZIP_XRDZIPZIP64EOCD_HH_
0009 #define SRC_XRDZIP_XRDZIPZIP64EOCD_HH_
0010 
0011 #include "XrdZip/XrdZipUtils.hh"
0012 #include "XrdZip/XrdZipLFH.hh"
0013 #include "XrdZip/XrdZipCDFH.hh"
0014 #include <string>
0015 #include <sstream>
0016 
0017 namespace XrdZip
0018 {
0019   //---------------------------------------------------------------------------
0020   //! A data structure representing the ZIP64 extension to End of Central
0021   //! Directory record
0022   //---------------------------------------------------------------------------
0023   struct ZIP64_EOCD
0024   {
0025     //-------------------------------------------------------------------------
0026     //! Constructor from a buffer
0027     //-------------------------------------------------------------------------
0028     ZIP64_EOCD( const char* buffer ):
0029       extensibleDataLength( 0 )
0030     {
0031       zip64EocdSize = to<uint64_t>(buffer + 4);
0032       zipVersion    = to<uint16_t>(buffer + 12);
0033       minZipVersion = to<uint16_t>(buffer + 14);
0034       nbDisk        = to<uint32_t>(buffer + 16);
0035       nbDiskCd      = to<uint32_t>(buffer + 20);
0036       nbCdRecD      = to<uint64_t>(buffer + 24);
0037       nbCdRec       = to<uint64_t>(buffer + 32);
0038       cdSize        = to<uint64_t>(buffer + 40);
0039       cdOffset      = to<uint64_t>(buffer + 48);
0040 
0041       zip64EocdTotalSize = zip64EocdBaseSize + extensibleDataLength;
0042     }
0043 
0044     //-------------------------------------------------------------------------
0045     //! Constructor from last LFH + CDFH
0046     //-------------------------------------------------------------------------
0047     ZIP64_EOCD( uint64_t cdoff, uint32_t cdcnt, uint32_t cdsize ) :
0048                   zipVersion( ( 3 << 8 ) | 63 ),
0049                   minZipVersion( 45 ),
0050                   nbDisk( 0 ),
0051                   nbDiskCd( 0 ),
0052                   extensibleDataLength( 0 )
0053     {
0054       nbCdRec  = cdcnt;
0055       nbCdRecD = cdcnt;
0056       cdSize   = cdsize;
0057       cdOffset = cdoff;
0058 
0059       zip64EocdSize = zip64EocdBaseSize + extensibleDataLength - 12;
0060       zip64EocdTotalSize = zip64EocdBaseSize + extensibleDataLength;
0061     }
0062 
0063     //-------------------------------------------------------------------------
0064     //! Serialize the object into a buffer
0065     //-------------------------------------------------------------------------
0066     void Serialize( buffer_t &buffer )
0067     {
0068       copy_bytes( zip64EocdSign, buffer );
0069       copy_bytes( zip64EocdSize, buffer );
0070       copy_bytes( zipVersion,    buffer );
0071       copy_bytes( minZipVersion, buffer );
0072       copy_bytes( nbDisk,        buffer );
0073       copy_bytes( nbDiskCd,      buffer );
0074       copy_bytes( nbCdRecD,      buffer );
0075       copy_bytes( nbCdRec,       buffer );
0076       copy_bytes( cdSize,        buffer );
0077       copy_bytes( cdOffset,      buffer );
0078 
0079       std::copy( extensibleData.begin(), extensibleData.end(), std::back_inserter( buffer ) );
0080     }
0081 
0082     //-------------------------------------------------------------------------
0083     //! Convert the ZIP64EOCD into a string for logging purposes
0084     //-------------------------------------------------------------------------
0085     std::string ToString()
0086     {
0087       std::stringstream ss;
0088       ss << "{zip64EocdSize="       << zip64EocdSize;
0089       ss << ";zipVersion="          << zipVersion;
0090       ss << ";minZipVersion="       << minZipVersion;
0091       ss << ";nbDisk="              << nbDisk;
0092       ss << ";nbDiskCd="            << nbDiskCd;
0093       ss << ";nbCdRecD="            << nbCdRecD;
0094       ss << ";nbCdRec="             << nbCdRec;
0095       ss << ";cdSize="              << cdSize;
0096       ss << ";cdOffset="            << cdOffset;
0097       ss << ";extensibleData="      << extensibleData;
0098       ss << ";extensibleDataLength" << extensibleDataLength << "}";
0099       return ss.str();
0100     }
0101 
0102     uint64_t    zip64EocdSize;        //< size of zip64 end of central directory record
0103     uint16_t    zipVersion;           //< version made by
0104     uint16_t    minZipVersion;        //< version needed to extract
0105     uint32_t    nbDisk;               //< number of this disk
0106     uint32_t    nbDiskCd;             //< number of the disk with the  start of the central directory
0107     uint64_t    nbCdRecD;             //< total number of entries in the central directory on this disk
0108     uint64_t    nbCdRec;              //< total number of entries in the central directory
0109     uint64_t    cdSize;               //< size of the central directory
0110     uint64_t    cdOffset;             //< offset of start of central directory
0111     std::string extensibleData;       //< zip64 extensible data sector
0112     uint64_t    extensibleDataLength; //< extensible data length
0113     uint64_t    zip64EocdTotalSize;   //< size of the record
0114 
0115     //-------------------------------------------------------------------------
0116     // the End of Central Directory signature
0117     //-------------------------------------------------------------------------
0118     static const uint32_t zip64EocdSign = 0x06064b50;
0119     static const uint16_t zip64EocdBaseSize = 56;
0120   };
0121 }
0122 
0123 #endif /* SRC_XRDZIP_XRDZIPZIP64EOCD_HH_ */