Loading...
Searching...
No Matches
XrdZipExtra.hh
Go to the documentation of this file.
//------------------------------------------------------------------------------
// Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN)
// Author: Michal Simon <michal.simon@cern.ch>
//------------------------------------------------------------------------------
// This file is part of the XRootD software suite.
//
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD. If not, see <http://www.gnu.org/licenses/>.
//
// In applying this licence, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
//------------------------------------------------------------------------------
#ifndef SRC_XRDZIP_XRDZIPEXTRA_HH_
#define SRC_XRDZIP_XRDZIPEXTRA_HH_
#include "XrdZip/XrdZipUtils.hh"
#include <cstdint>
#include <sys/types.h>
namespace XrdZip
{
//---------------------------------------------------------------------------
// A data structure for the ZIP64 extra field
//---------------------------------------------------------------------------
struct Extra
{
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
Extra( uint64_t fileSize )
{
offset = 0;
nbDisk = 0;
if ( fileSize >= ovrflw<uint32_t>::value )
{
dataSize = 16;
uncompressedSize = fileSize;
compressedSize = fileSize;
totalSize = dataSize + 4;
}
else
{
dataSize = 0;
uncompressedSize = 0;
compressedSize = 0;
totalSize = 0;
}
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
Extra( Extra *extra, uint64_t offset )
{
nbDisk = 0;
uncompressedSize = extra->uncompressedSize;
compressedSize = extra->compressedSize;
dataSize = extra->dataSize;
totalSize = extra->totalSize;
if ( offset >= ovrflw<uint32_t>::value )
{
this->offset = offset;
dataSize += 8;
totalSize = dataSize + 4;
}
else
this->offset = 0;
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
Extra() : dataSize( 0 ),
uncompressedSize( 0 ),
compressedSize( 0 ),
offset( 0 ),
nbDisk( 0 ),
totalSize( 0 )
{
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
inline static const char* Find( const char *buffer, uint16_t length )
{
const char *end = buffer + length;
while( buffer < end )
{
uint16_t signature = to<uint16_t>( buffer );
uint16_t datasize = to<uint16_t>( buffer + 2 );
if( signature == headerID ) return buffer;
buffer += 2 * sizeof( uint16_t ) + datasize;
}
return nullptr;
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
void FromBuffer( const char *&buffer, uint16_t exsize, uint8_t flags )
{
uint16_t signature = 0;
from_buffer( signature, buffer );
if( signature != headerID ) throw bad_data();
from_buffer( dataSize, buffer );
if( dataSize != exsize ) throw bad_data();
if( UCMPSIZE & flags )
from_buffer( uncompressedSize, buffer );
if( CPMSIZE & flags )
from_buffer( compressedSize, buffer );
if( OFFSET & flags )
from_buffer( offset, buffer );
if( NBDISK & flags )
from_buffer( nbDisk, buffer );
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
void Serialize( buffer_t &buffer )
{
if( totalSize > 0 )
{
copy_bytes( headerID, buffer );
copy_bytes( dataSize, buffer );
if ( uncompressedSize > 0)
{
copy_bytes( uncompressedSize, buffer );
copy_bytes( compressedSize, buffer );
if ( offset > 0 )
copy_bytes( offset, buffer );
}
else if( offset > 0 )
copy_bytes( offset, buffer );
}
}
enum Ovrflw
{
NONE = 0,
UCMPSIZE = 1,
CPMSIZE = 2,
OFFSET = 4,
NBDISK = 8
};
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
static const uint16_t headerID = 0x0001;
uint16_t dataSize; //< size of the extra block
uint64_t uncompressedSize; //< size of the uncompressed data
uint64_t compressedSize; //< size of the compressed data
uint64_t offset; //< offset of local header record
uint32_t nbDisk; //< number of disk where file starts
uint16_t totalSize; //< total size in buffer
};
}
#endif /* SRC_XRDZIP_XRDZIPEXTRA_HH_ */
extra
int extra
Definition XrdAccTest.cc:63
XrdZipUtils.hh
XrdZip
Definition XrdZipCDFH.hh:42
XrdZip::to
static INT to(const char *buffer)
Definition XrdZipUtils.hh:91
XrdZip::from_buffer
static void from_buffer(INT &var, const char *&buffer)
Definition XrdZipUtils.hh:78
XrdZip::buffer_t
std::vector< char > buffer_t
Definition XrdZipUtils.hh:56
XrdZip::copy_bytes
static void copy_bytes(const INT value, buffer_t &buffer)
Definition XrdZipUtils.hh:62
XrdZip::Extra::Extra
Extra(uint64_t fileSize)
Constructor from file size.
Definition XrdZipExtra.hh:43
XrdZip::Extra::headerID
static const uint16_t headerID
The extra field marker.
Definition XrdZipExtra.hh:172
XrdZip::Extra::totalSize
uint16_t totalSize
Definition XrdZipExtra.hh:179
XrdZip::Extra::Find
static const char * Find(const char *buffer, uint16_t length)
Definition XrdZipExtra.hh:101
XrdZip::Extra::offset
uint64_t offset
Definition XrdZipExtra.hh:177
XrdZip::Extra::Ovrflw
Ovrflw
Definition XrdZipExtra.hh:161
XrdZip::Extra::CPMSIZE
@ CPMSIZE
Definition XrdZipExtra.hh:164
XrdZip::Extra::UCMPSIZE
@ UCMPSIZE
Definition XrdZipExtra.hh:163
XrdZip::Extra::NONE
@ NONE
Definition XrdZipExtra.hh:162
XrdZip::Extra::OFFSET
@ OFFSET
Definition XrdZipExtra.hh:165
XrdZip::Extra::NBDISK
@ NBDISK
Definition XrdZipExtra.hh:166
XrdZip::Extra::Extra
Extra(Extra *extra, uint64_t offset)
Constructor from another extra + offset.
Definition XrdZipExtra.hh:66
XrdZip::Extra::uncompressedSize
uint64_t uncompressedSize
Definition XrdZipExtra.hh:175
XrdZip::Extra::Extra
Extra()
Default constructor.
Definition XrdZipExtra.hh:86
XrdZip::Extra::dataSize
uint16_t dataSize
Definition XrdZipExtra.hh:174
XrdZip::Extra::compressedSize
uint64_t compressedSize
Definition XrdZipExtra.hh:176
XrdZip::Extra::nbDisk
uint32_t nbDisk
Definition XrdZipExtra.hh:178
XrdZip::Extra::Serialize
void Serialize(buffer_t &buffer)
Serialize the extra field into a buffer.
Definition XrdZipExtra.hh:142
XrdZip::Extra::FromBuffer
void FromBuffer(const char *&buffer, uint16_t exsize, uint8_t flags)
Constructor from buffer.
Definition XrdZipExtra.hh:117
XrdZip::bad_data
Definition XrdZipUtils.hh:42
XrdZip::ovrflw::value
static const UINT value
Definition XrdZipUtils.hh:50