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>
109 uint32_t crc32 = 0 );
150 return PgReadFrom( openfn, offset, size, buffer,
handler,
timeout );
203 if( openstage != Done || openfn.empty() )
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() ) ?
317 if( filesize == std::numeric_limits<uint32_t>::max() && cdfh->
extra )
318 filesize = cdfh->
extra->compressedSize;
321 offset = nextRecordOffset - filesize - descsize;
341 if( openstage != Done || openfn.empty() )
343 0,
"Archive not opened." );
360 return openstage == Done;
368 return archive.IsSecure();
374 inline bool SetProperty(
const std::string &name,
const std::string &value )
376 return archive.SetProperty( name, value );
382 inline bool GetProperty(
const std::string &name, std::string &value )
384 return archive.GetProperty( name, value );
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)
uint16_t timeout
Operation timeout.
static PostMaster * GetPostMaster()
Get default post master.
void QueueJob(Job *job, void *arg=0)
Add a job to be run.
std::unique_ptr< PipelineHandler > handler
Operation handler.
JobManager * GetJobManager()
Get the job manager object user by the post master.
Handle an async response.
@ IsWritable
Write access is allowed.
File & GetFile()
Get the underlying File object.
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)
bool GetProperty(const std::string &name, std::string &value)
Get property on the underlying File object.
bool SetProperty(const std::string &name, const std::string &value)
Set property on the underlying File object.
XRootDStatus Stat(StatInfo *&info)
XRootDStatus GetOffset(const std::string &fn, uint64_t &offset)
XRootDStatus GetCRC32(const std::string &fn, uint32_t &cksum)
XRootDStatus Read(uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
StatImpl< false > Stat(Ctx< File > file, Arg< bool > force, uint16_t timeout=0)
CloseArchiveImpl< false > CloseArchive(Ctx< ZipArchive > zip, uint16_t timeout=0)
Factory for creating CloseFileImpl objects.
const uint16_t stError
An error occurred that could potentially be retried.
const uint16_t errNotFound
ZipReadFromImpl< false > ReadFrom(Ctx< ZipArchive > zip, Arg< std::string > fn, Arg< uint64_t > offset, Arg< uint32_t > size, Arg< void * > buffer, uint16_t timeout=0)
Factory for creating ArchiveReadImpl objects.
const uint16_t errInvalidOp
OpenFileImpl< false > OpenFile(Ctx< ZipArchive > zip, Arg< std::string > fn, Arg< OpenFlags::Flags > flags=OpenFlags::None, Arg< uint64_t > size=0, Arg< uint32_t > crc32=0, uint16_t timeout=0)
Factory for creating OpenFileImpl objects.
const uint16_t errNotSupported
AppendFileImpl< false > AppendFile(Ctx< ZipArchive > zip, Arg< std::string > fn, Arg< uint32_t > crc32, Arg< uint32_t > size, Arg< const void * > buffer, uint16_t timeout=0)
Factory for creating ArchiveReadImpl objects.
XRootDStatus ReadFromImpl(ZipArchive &me, const std::string &fn, uint64_t relativeOffset, uint32_t size, void *usrbuff, ResponseHandler *usrHandler, uint16_t timeout)
OpenArchiveImpl< false > OpenArchive(Ctx< ZipArchive > zip, Arg< std::string > fn, Arg< OpenFlags::Flags > flags, uint16_t timeout=0)
Factory for creating OpenArchiveImpl objects.
ZipListImpl< false > List(Ctx< ZipArchive > zip)
Factory for creating ZipStatImpl objects.
OpenOnlyImpl< false > OpenOnly(XrdCl::Ctx< XrdCl::ZipArchive > zip, XrdCl::Arg< std::string > fn, XrdCl::Arg< bool > updt, uint16_t timeout=0)
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.
static uint64_t GetOffset(const CDFH &cdfh)
std::unique_ptr< Extra > extra
uint16_t compressionMethod
static uint8_t GetSize(bool zip64)