25 #ifndef SRC_XRDZIP_XRDZIPCDFH_HH_
26 #define SRC_XRDZIP_XRDZIPCDFH_HH_
35 #include <unordered_map>
39 #include <sys/types.h>
51 typedef std::vector<std::unique_ptr<CDFH>>
cdvec_t;
56 typedef std::unordered_map<std::string, size_t>
cdmap_t;
61 typedef std::unordered_map<std::string, std::unique_ptr<CDFH>>
cdrecs_t;
75 inline static std::tuple<cdvec_t, cdmap_t>
Parse(
const char *buffer, uint32_t bufferSize, uint16_t nbCdRecords )
80 cdvec.reserve( nbCdRecords );
82 for(
size_t i = 0; i < nbCdRecords; ++i )
86 uint32_t signature = to<uint32_t>( buffer +
offset );
89 std::unique_ptr<CDFH> cdfh(
new CDFH( buffer +
offset, bufferSize ) );
91 bufferSize -= cdfh->cdfhSize;
92 cdmap[cdfh->filename] = i;
93 cdvec.push_back( std::move( cdfh ) );
96 return std::make_tuple( std::move( cdvec ), std::move( cdmap ) );
105 inline static std::tuple<cdvec_t, cdmap_t>
Parse(
const char *&buffer, uint32_t bufferSize )
110 while( bufferSize > 0 )
112 if( bufferSize <
sizeof( uint32_t ) )
throw bad_data();
114 uint32_t signature = to<uint32_t>( buffer );
116 return std::make_tuple( std::move( cdvec ), std::move( cdmap ) );
118 std::unique_ptr<CDFH> cdfh(
new CDFH( buffer ) );
120 buffer += cdfh->cdfhSize;
121 bufferSize -= cdfh->cdfhSize;
122 cdmap[cdfh->filename] = i++;
123 cdvec.push_back( std::move( cdfh ) );
126 return std::make_tuple( std::move( cdvec ), std::move( cdmap ) );
132 inline static size_t CalcSize(
const cdvec_t &cdvec, uint32_t orgcdsz, uint32_t orgcdcnt )
135 auto itr = cdvec.begin() + orgcdcnt;
136 for( ; itr != cdvec.end() ; ++itr )
138 CDFH *cdfh = itr->get();
141 return size + orgcdsz;
149 std::copy( orgcdbuf.begin(), orgcdbuf.end(), std::back_inserter( buffer ) );
150 auto itr = cdvec.begin() + orgcdcnt;
151 for( ; itr != cdvec.end() ; ++itr )
153 CDFH *cdfh = itr->get();
161 CDFH(
LFH *lfh, mode_t mode, uint64_t lfhOffset ):
195 CDFH(
const char *buffer,
const uint32_t maxSize = 0 )
203 ZCRC32 = to<uint32_t>(buffer + 16);
209 nbDisk = to<uint16_t>(buffer + 34);
212 offset = to<uint32_t>(buffer + 42);
231 return cdfh.
extra->offset;
246 exsize +=
sizeof( uint64_t );
253 exsize +=
sizeof( uint64_t );
260 exsize +=
sizeof( uint64_t );
267 exsize +=
sizeof( uint32_t );
272 if( exsize == 0 )
return;
279 extra->FromBuffer( buffer, exsize, ovrflws );
305 std::copy(
filename.begin(),
filename.end(), std::back_inserter( buffer ) );
307 extra->Serialize( buffer );
310 std::copy(
comment.begin(),
comment.end(), std::back_inserter( buffer ) );
std::unordered_map< std::string, std::unique_ptr< CDFH > > cdrecs_t
std::vector< std::unique_ptr< CDFH > > cdvec_t
std::vector< char > buffer_t
static void copy_bytes(const INT value, buffer_t &buffer)
std::unordered_map< std::string, size_t > cdmap_t
static std::tuple< cdvec_t, cdmap_t > Parse(const char *&buffer, uint32_t bufferSize)
uint32_t uncompressedSize
static uint64_t GetOffset(const CDFH &cdfh)
std::unique_ptr< Extra > extra
CDFH(LFH *lfh, mode_t mode, uint64_t lfhOffset)
static const uint16_t cdfhBaseSize
static std::tuple< cdvec_t, cdmap_t > Parse(const char *buffer, uint32_t bufferSize, uint16_t nbCdRecords)
uint16_t compressionMethod
void Serialize(buffer_t &buffer)
Serialize the object into a buffer.
static size_t CalcSize(const cdvec_t &cdvec, uint32_t orgcdsz, uint32_t orgcdcnt)
static const uint32_t cdfhSign
static void Serialize(uint32_t orgcdcnt, const buffer_t &orgcdbuf, const cdvec_t &cdvec, buffer_t &buffer)
void ParseExtra(const char *buffer, uint16_t length)
CDFH(const char *buffer, const uint32_t maxSize=0)
static const uint16_t flag
A data structure representing ZIP Local File Header.