File indexing completed on 2025-06-30 08:55:00
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #ifndef SRC_XRDZIP_XRDZIPEXTRA_HH_
0026 #define SRC_XRDZIP_XRDZIPEXTRA_HH_
0027
0028 #include "XrdZip/XrdZipUtils.hh"
0029
0030 #include <cstdint>
0031 #include <sys/types.h>
0032
0033 namespace XrdZip
0034 {
0035
0036
0037
0038 struct Extra
0039 {
0040
0041
0042
0043 Extra( uint64_t fileSize )
0044 {
0045 offset = 0;
0046 nbDisk = 0;
0047 if ( fileSize >= ovrflw<uint32_t>::value )
0048 {
0049 dataSize = 16;
0050 uncompressedSize = fileSize;
0051 compressedSize = fileSize;
0052 totalSize = dataSize + 4;
0053 }
0054 else
0055 {
0056 dataSize = 0;
0057 uncompressedSize = 0;
0058 compressedSize = 0;
0059 totalSize = 0;
0060 }
0061 }
0062
0063
0064
0065
0066 Extra( Extra *extra, uint64_t offset )
0067 {
0068 nbDisk = 0;
0069 uncompressedSize = extra->uncompressedSize;
0070 compressedSize = extra->compressedSize;
0071 dataSize = extra->dataSize;
0072 totalSize = extra->totalSize;
0073 if ( offset >= ovrflw<uint32_t>::value )
0074 {
0075 this->offset = offset;
0076 dataSize += 8;
0077 totalSize = dataSize + 4;
0078 }
0079 else
0080 this->offset = 0;
0081 }
0082
0083
0084
0085
0086 Extra() : dataSize( 0 ),
0087 uncompressedSize( 0 ),
0088 compressedSize( 0 ),
0089 offset( 0 ),
0090 nbDisk( 0 ),
0091 totalSize( 0 )
0092 {
0093 }
0094
0095
0096
0097
0098
0099
0100
0101 inline static const char* Find( const char *buffer, uint16_t length )
0102 {
0103 const char *end = buffer + length;
0104 while( buffer < end )
0105 {
0106 uint16_t signature = to<uint16_t>( buffer );
0107 uint16_t datasize = to<uint16_t>( buffer + 2 );
0108 if( signature == headerID ) return buffer;
0109 buffer += 2 * sizeof( uint16_t ) + datasize;
0110 }
0111 return nullptr;
0112 }
0113
0114
0115
0116
0117 void FromBuffer( const char *&buffer, uint16_t exsize, uint8_t flags )
0118 {
0119 uint16_t signature = 0;
0120 from_buffer( signature, buffer );
0121 if( signature != headerID ) throw bad_data();
0122
0123 from_buffer( dataSize, buffer );
0124 if( dataSize != exsize ) throw bad_data();
0125
0126 if( UCMPSIZE & flags )
0127 from_buffer( uncompressedSize, buffer );
0128
0129 if( CPMSIZE & flags )
0130 from_buffer( compressedSize, buffer );
0131
0132 if( OFFSET & flags )
0133 from_buffer( offset, buffer );
0134
0135 if( NBDISK & flags )
0136 from_buffer( nbDisk, buffer );
0137 }
0138
0139
0140
0141
0142 void Serialize( buffer_t &buffer )
0143 {
0144 if( totalSize > 0 )
0145 {
0146 copy_bytes( headerID, buffer );
0147 copy_bytes( dataSize, buffer );
0148 if ( uncompressedSize > 0)
0149 {
0150 copy_bytes( uncompressedSize, buffer );
0151 copy_bytes( compressedSize, buffer );
0152 if ( offset > 0 )
0153 copy_bytes( offset, buffer );
0154 }
0155 else if( offset > 0 )
0156 copy_bytes( offset, buffer );
0157 }
0158 }
0159
0160 enum Ovrflw
0161 {
0162 NONE = 0,
0163 UCMPSIZE = 1,
0164 CPMSIZE = 2,
0165 OFFSET = 4,
0166 NBDISK = 8
0167 };
0168
0169
0170
0171
0172 static const uint16_t headerID = 0x0001;
0173
0174 uint16_t dataSize;
0175 uint64_t uncompressedSize;
0176 uint64_t compressedSize;
0177 uint64_t offset;
0178 uint32_t nbDisk;
0179 uint16_t totalSize;
0180 };
0181 }
0182
0183 #endif