25#ifndef SRC_XRDZIP_XRDZIPARCHIVE_HH_
26#define SRC_XRDZIP_XRDZIPARCHIVE_HH_
40#include <unordered_map>
66 friend class ::MicroTest;
67 friend class ::XrdEcTests;
69 template<
typename RSP>
95 uint16_t timeout = 0 );
109 uint32_t crc32 = 0 );
126 uint16_t timeout = 0 )
129 return ReadFrom( openfn, offset, size, buffer, handler, timeout );
147 uint16_t timeout = 0 )
150 return PgReadFrom( openfn, offset, size, buffer, handler, timeout );
169 uint16_t timeout = 0 );
187 uint16_t timeout = 0 );
201 uint16_t timeout = 0 )
203 if( openstage != Done || openfn.empty() )
206 return WriteImpl( size, buffer, handler, timeout );
233 uint16_t timeout = 0 );
244 if( openstage != Done )
247 auto cditr = cdmap.find( fn );
248 if( cditr == cdmap.end() )
251 info = make_stat( fn );
268 return Stat( openfn, info );
280 if( openstage != Done )
283 auto cditr = cdmap.find( fn );
284 if( cditr == cdmap.end() )
286 cksum = cdvec[cditr->second]->ZCRC32;
291 if( openstage != XrdCl::ZipArchive::Done || !archive.
IsOpen() )
294 auto cditr = cdmap.find( fn );
295 if( cditr == cdmap.end() )
304 0,
"The compression algorithm is not supported!" );
313 uint64_t cdOffset = zip64eocd ? zip64eocd->cdOffset : eocd->cdOffset;
314 uint64_t nextRecordOffset = ( cditr->second + 1 < cdvec.size() ) ?
315 XrdCl::CDFH::GetOffset( *cdvec[cditr->second + 1] ) : cdOffset;
317 if( filesize == std::numeric_limits<uint32_t>::max() && cdfh->
extra )
318 filesize = cdfh->
extra->compressedSize;
320 XrdCl::DataDescriptor::GetSize( cdfh->
IsZIP64() ) : 0;
321 offset = nextRecordOffset - filesize - descsize;
333 uint16_t timeout = 0 );
341 if( openstage != Done || openfn.empty() )
343 0,
"Archive not opened." );
360 return openstage == Done;
374 inline bool SetProperty(
const std::string &name,
const std::string &value )
382 inline bool GetProperty(
const std::string &name, std::string &value )
423 uint16_t timeout = 0 );
437 void SetCD(
const buffer_t &buffer );
445 template<
typename Response>
446 inline static AnyObject* PkgRsp( Response *rsp )
448 if( !rsp )
return nullptr;
457 template<
typename Response>
458 inline static void Free( XRootDStatus *st, Response *rsp )
472 template<
typename Response>
473 inline static void Schedule( ResponseHandler *handler, XRootDStatus *st, Response *rsp =
nullptr )
475 if( !handler )
return Free( st, rsp );
476 ResponseJob *job =
new ResponseJob( handler, st, PkgRsp( rsp ), 0 );
487 inline static StatInfo* make_stat(
const StatInfo &starch, uint64_t size )
489 StatInfo *info =
new StatInfo( starch );
490 uint32_t flags = info->GetFlags();
492 info->SetSize( size );
502 inline StatInfo* make_stat(
const std::string &fn )
504 StatInfo *infoptr = 0;
505 XRootDStatus st = archive.
Stat(
false, infoptr );
506 if (!st.IsOK())
return nullptr;
507 std::unique_ptr<StatInfo> stinfo( infoptr );
508 auto itr = cdmap.find( fn );
509 if( itr == cdmap.end() )
return nullptr;
510 size_t index = itr->second;
511 uint64_t uncompressedSize = cdvec[index]->uncompressedSize;
512 if( cdvec[index]->
extra && uncompressedSize == std::numeric_limits<uint32_t>::max() )
513 uncompressedSize = cdvec[index]->extra->uncompressedSize;
514 return make_stat( *stinfo, uncompressedSize );
520 inline static XRootDStatus* make_status(
const XRootDStatus &status = XRootDStatus() )
522 return new XRootDStatus( status );
558 NewFile( uint64_t offset, std::unique_ptr<LFH> lfh ) : offset( offset ),
559 lfh( std::move( lfh ) ),
564 NewFile( NewFile && nf ) : offset( nf.offset ),
565 lfh( std::move( nf.lfh ) ),
566 overwrt( nf.overwrt )
571 std::unique_ptr<LFH> lfh;
578 typedef std::unordered_map<std::string, ZipCache> zipcache_t;
579 typedef std::unordered_map<std::string, NewFile> new_files_t;
585 std::unique_ptr<char[]> buffer;
586 std::unique_ptr<EOCD> eocd;
593 std::unique_ptr<ZIP64_EOCD> zip64eocd;
594 OpenStages openstage;
597 std::unique_ptr<LFH> lfh;
599 new_files_t newfiles;
void Set(Type object, bool own=true)
static PostMaster * GetPostMaster()
Get default post master.
bool IsSecure() const
Check if the file is using an encrypted connection.
bool IsOpen() const
Check if the file is open.
bool GetProperty(const std::string &name, std::string &value) const
XRootDStatus Stat(bool force, ResponseHandler *handler, uint16_t timeout=0) XRD_WARN_UNUSED_RESULT
bool SetProperty(const std::string &name, const std::string &value)
void QueueJob(Job *job, void *arg=0)
Add a job to be run.
JobManager * GetJobManager()
Get the job manager object user by the post master.
Handle an async response.
@ IsWritable
Write access is allowed.
XRootDStatus ReadFrom(const std::string &fn, uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus PgRead(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
bool IsSecure()
Check if the underlying file is using an encrypted connection.
XRootDStatus Stat(const std::string &fn, StatInfo *&info)
XRootDStatus Write(uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus UpdateMetadata(uint32_t crc32)
bool GetProperty(const std::string &name, std::string &value)
Get property on the underlying File object.
XRootDStatus OpenArchive(const std::string &url, OpenFlags::Flags flags, ResponseHandler *handler, uint16_t timeout=0)
XRootDStatus List(DirectoryList *&list)
XRootDStatus AppendFile(const std::string &fn, uint32_t crc32, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
bool SetProperty(const std::string &name, const std::string &value)
Set property on the underlying File object.
XRootDStatus Stat(StatInfo *&info)
virtual ~ZipArchive()
Destructor.
XRootDStatus CloseArchive(ResponseHandler *handler, uint16_t timeout=0)
Create the central directory at the end of ZIP archive and close it.
XRootDStatus GetOffset(const std::string &fn, uint64_t &offset)
XRootDStatus PgReadFrom(const std::string &fn, uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
friend XRootDStatus ReadFromImpl(ZipArchive &, const std::string &, uint64_t, uint32_t, void *, ResponseHandler *, uint16_t)
XRootDStatus GetCRC32(const std::string &fn, uint32_t &cksum)
ZipArchive(bool enablePlugIns=true)
Constructor.
XRootDStatus OpenFile(const std::string &fn, OpenFlags::Flags flags=OpenFlags::None, uint64_t size=0, uint32_t crc32=0)
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
File & GetFile()
Get the underlying File object.
const uint16_t stError
An error occurred that could potentially be retried.
const uint16_t errNotFound
const uint16_t errInvalidOp
const uint16_t errNotSupported
std::vector< std::unique_ptr< CDFH > > cdvec_t
std::vector< char > buffer_t
std::unordered_map< std::string, size_t > cdmap_t
Flags
Open flags, may be or'd when appropriate.
std::unique_ptr< Extra > extra
uint16_t compressionMethod