Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-22 10:59:21

0001 /*
0002  * XrdZipZIP64EOCDL.hh
0003  *
0004  *  Created on: 9 Nov 2020
0005  *      Author: simonm
0006  */
0007 
0008 #ifndef SRC_XRDZIP_XRDZIPZIP64EOCDL_HH_
0009 #define SRC_XRDZIP_XRDZIPZIP64EOCDL_HH_
0010 
0011 #include "XrdZip/XrdZipUtils.hh"
0012 #include "XrdZip/XrdZipEOCD.hh"
0013 #include "XrdZip/XrdZipZIP64EOCD.hh"
0014 #include <string>
0015 #include <sstream>
0016 
0017 namespace XrdZip
0018 {
0019   //---------------------------------------------------------------------------
0020   //! A data structure representing the ZIP64 end of central directory locator
0021   //---------------------------------------------------------------------------
0022   struct ZIP64_EOCDL
0023   {
0024     //-------------------------------------------------------------------------
0025     //! Constructor from a buffer
0026     //-------------------------------------------------------------------------
0027     ZIP64_EOCDL( const char *buffer )
0028     {
0029       nbDiskZip64Eocd = to<uint32_t>(buffer + 4);
0030       zip64EocdOffset = to<uint64_t>(buffer + 8);
0031       totalNbDisks    = to<uint32_t>(buffer + 16);
0032     }
0033 
0034     //-------------------------------------------------------------------------
0035     //! Constructor from EOCD and ZIP64 EOCD
0036     //-------------------------------------------------------------------------
0037     ZIP64_EOCDL( const EOCD &eocd, const ZIP64_EOCD &zip64Eocd ):
0038       nbDiskZip64Eocd( 0 ),
0039       totalNbDisks( 1 )
0040     {
0041       if ( eocd.cdOffset == ovrflw<uint32_t>::value )
0042         zip64EocdOffset = zip64Eocd.cdOffset;
0043       else
0044         zip64EocdOffset = eocd.cdOffset;
0045 
0046       if ( eocd.cdSize == ovrflw<uint32_t>::value )
0047         zip64EocdOffset += zip64Eocd.cdSize;
0048       else
0049         zip64EocdOffset += eocd.cdSize;
0050     }
0051 
0052     //-------------------------------------------------------------------------
0053     //! Serialize the object into a buffer
0054     //-------------------------------------------------------------------------
0055     void Serialize( buffer_t &buffer )
0056     {
0057       copy_bytes( zip64EocdlSign,  buffer );
0058       copy_bytes( nbDiskZip64Eocd, buffer );
0059       copy_bytes( zip64EocdOffset, buffer );
0060       copy_bytes( totalNbDisks,    buffer );
0061     }
0062 
0063     //-------------------------------------------------------------------------
0064     //! Convert the EOCDL into a string for logging purposes
0065     //-------------------------------------------------------------------------
0066     std::string ToString()
0067     {
0068       std::stringstream ss;
0069       ss << "{nbDiskZip64Eocd=" << nbDiskZip64Eocd;
0070       ss << ";zip64EocdOffset=" << zip64EocdOffset;
0071       ss << ";totalNbDisks="    << totalNbDisks << "}";
0072       return ss.str();
0073     }
0074 
0075     uint32_t nbDiskZip64Eocd; //< number of the disk with the start of the zip64 end of central directory
0076     uint64_t zip64EocdOffset; //< relative offset of the zip64 end of central directory record
0077     uint32_t totalNbDisks;    //< total number of disks
0078 
0079     //-------------------------------------------------------------------------
0080     // the End of Central Directory locator signature
0081     //-------------------------------------------------------------------------
0082     static const uint32_t zip64EocdlSign = 0x07064b50;
0083     static const uint16_t zip64EocdlSize = 20;
0084   };
0085 }
0086 
0087 #endif /* SRC_XRDZIP_XRDZIPZIP64EOCDL_HH_ */