xrootd
Loading...
Searching...
No Matches
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
XrdCl::ZipArchive Class Reference

#include <XrdClZipArchive.hh>

Collaboration diagram for XrdCl::ZipArchive:
Collaboration graph
[legend]

Classes

struct  NewFile
 LFH of a newly appended file (in case it needs to be overwritten) More...
 

Public Member Functions

 ZipArchive (bool enablePlugIns=true)
 Constructor.
 
virtual ~ZipArchive ()
 Destructor.
 
XRootDStatus OpenArchive (const std::string &url, OpenFlags::Flags flags, ResponseHandler *handler, uint16_t timeout=0)
 
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)
 
XRootDStatus PgRead (uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus ReadFrom (const std::string &fn, uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus PgReadFrom (const std::string &fn, uint64_t offset, uint32_t size, void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus Write (uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus UpdateMetadata (uint32_t crc32)
 
XRootDStatus AppendFile (const std::string &fn, uint32_t crc32, uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout=0)
 
XRootDStatus Stat (const std::string &fn, StatInfo *&info)
 
XRootDStatus Stat (StatInfo *&info)
 
XRootDStatus GetCRC32 (const std::string &fn, uint32_t &cksum)
 
XRootDStatus GetOffset (const std::string &fn, uint64_t &offset)
 
XRootDStatus CloseArchive (ResponseHandler *handler, uint16_t timeout=0)
 Create the central directory at the end of ZIP archive and close it.
 
XRootDStatus CloseFile ()
 
XRootDStatus List (DirectoryList *&list)
 
bool IsOpen ()
 
bool IsSecure ()
 Check if the underlying file is using an encrypted connection.
 
bool SetProperty (const std::string &name, const std::string &value)
 Set property on the underlying File object.
 
bool GetProperty (const std::string &name, std::string &value)
 Get property on the underlying File object.
 
FileGetFile ()
 Get the underlying File object.
 

Private Types

enum  OpenStages {
  None = 0 , HaveEocdBlk , HaveZip64EocdlBlk , HaveZip64EocdBlk ,
  HaveCdRecords , Done , Error , NotParsed
}
 Stages of opening and parsing a ZIP archive. More...
 
typedef std::unordered_map< std::string, ZipCachezipcache_t
 Type that maps file name to its cache.
 
typedef std::unordered_map< std::string, NewFilenew_files_t
 

Private Member Functions

XRootDStatus WriteImpl (uint32_t size, const void *buffer, ResponseHandler *handler, uint16_t timeout)
 
XRootDStatus OpenOnly (const std::string &url, bool update, ResponseHandler *handler, uint16_t timeout=0)
 
buffer_t GetCD ()
 
void SetCD (const buffer_t &buffer)
 
StatInfomake_stat (const std::string &fn)
 
void Clear ()
 Clear internal ZipArchive objects.
 

Static Private Member Functions

template<typename Response >
static AnyObjectPkgRsp (Response *rsp)
 
template<typename Response >
static void Free (XRootDStatus *st, Response *rsp)
 Free status and response.
 
template<typename Response >
static void Schedule (ResponseHandler *handler, XRootDStatus *st, Response *rsp=nullptr)
 
static StatInfomake_stat (const StatInfo &starch, uint64_t size)
 
static XRootDStatusmake_status (const XRootDStatus &status=XRootDStatus())
 Allocate new XRootDStatus object.
 

Private Attributes

File archive
 
uint64_t archsize
 
bool cdexists
 
bool updated
 
std::unique_ptr< char[]> buffer
 
std::unique_ptr< EOCDeocd
 
cdvec_t cdvec
 
cdmap_t cdmap
 
uint64_t cdoff
 
uint32_t orgcdsz
 
uint32_t orgcdcnt
 
buffer_t orgcdbuf
 
std::unique_ptr< ZIP64_EOCDzip64eocd
 
OpenStages openstage
 
std::string openfn
 
zipcache_t zipcache
 
std::unique_ptr< LFHlfh
 
bool ckpinit
 
new_files_t newfiles
 

Friends

class XrdEc::StrmWriter
 
class XrdEc::Reader
 
template<bool >
class XrdEc::OpenOnlyImpl
 
class ::MicroTest
 
class ::XrdEcTests
 
template<typename RSP >
XRootDStatus ReadFromImpl (ZipArchive &, const std::string &, uint64_t, uint32_t, void *, ResponseHandler *, uint16_t)
 

Member Typedef Documentation

◆ new_files_t

typedef std::unordered_map<std::string, NewFile> XrdCl::ZipArchive::new_files_t
private

◆ zipcache_t

typedef std::unordered_map<std::string, ZipCache> XrdCl::ZipArchive::zipcache_t
private

Type that maps file name to its cache.

Member Enumeration Documentation

◆ OpenStages

Stages of opening and parsing a ZIP archive.

Enumerator
None 
HaveEocdBlk 
HaveZip64EocdlBlk 
HaveZip64EocdBlk 
HaveCdRecords 
Done 
Error 
NotParsed 

Constructor & Destructor Documentation

◆ ZipArchive()

XrdCl::ZipArchive::ZipArchive ( bool  enablePlugIns = true)

Constructor.

◆ ~ZipArchive()

virtual XrdCl::ZipArchive::~ZipArchive ( )
virtual

Destructor.

Member Function Documentation

◆ AppendFile()

XRootDStatus XrdCl::ZipArchive::AppendFile ( const std::string &  fn,
uint32_t  crc32,
uint32_t  size,
const void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)

Create a new file in the ZIP archive and append the data

Parameters
fn: the name of the new file to be created
crc32: the crc32 of the file
size: the size of the file
buffer: the buffer with the data
handler: user callback
timeout: operation timeout
Returns
: the status of the operation

◆ Clear()

void XrdCl::ZipArchive::Clear ( )
inlineprivate

Clear internal ZipArchive objects.

References buffer, cdmap, cdvec, eocd, None, openstage, and zip64eocd.

◆ CloseArchive()

XRootDStatus XrdCl::ZipArchive::CloseArchive ( ResponseHandler handler,
uint16_t  timeout = 0 
)

Create the central directory at the end of ZIP archive and close it.

Parameters
handler: user callback
timeout: operation timeout
Returns
: the status of the operation

◆ CloseFile()

XRootDStatus XrdCl::ZipArchive::CloseFile ( )
inline

Close an open file within the ZIP archive

Returns
: the status of the operation

References Done, XrdCl::errInvalidOp, lfh, openfn, openstage, and XrdCl::stError.

◆ Free()

template<typename Response >
static void XrdCl::ZipArchive::Free ( XRootDStatus st,
Response *  rsp 
)
inlinestaticprivate

Free status and response.

Referenced by Schedule().

◆ GetCD()

buffer_t XrdCl::ZipArchive::GetCD ( )
private

Get a buffer with central directory of the ZIP archive

Returns
: buffer with central directory

◆ GetCRC32()

XRootDStatus XrdCl::ZipArchive::GetCRC32 ( const std::string &  fn,
uint32_t &  cksum 
)
inline

Get crc32 for a given file

Parameters
fn: file name
cksum: output parameter
Returns
: the status of the operation

References cdmap, cdvec, Done, XrdCl::errInvalidOp, XrdCl::errNotFound, openstage, and XrdCl::stError.

◆ GetFile()

File & XrdCl::ZipArchive::GetFile ( )
inline

Get the underlying File object.

References archive.

◆ GetOffset()

XRootDStatus XrdCl::ZipArchive::GetOffset ( const std::string &  fn,
uint64_t &  offset 
)
inline

◆ GetProperty()

bool XrdCl::ZipArchive::GetProperty ( const std::string &  name,
std::string &  value 
)
inline

Get property on the underlying File object.

References archive, and XrdCl::File::GetProperty().

◆ IsOpen()

bool XrdCl::ZipArchive::IsOpen ( )
inline
Returns
: true if ZIP archive has been successfully opened

References Done, and openstage.

◆ IsSecure()

bool XrdCl::ZipArchive::IsSecure ( )
inline

Check if the underlying file is using an encrypted connection.

References archive, and XrdCl::File::IsSecure().

◆ List()

XRootDStatus XrdCl::ZipArchive::List ( DirectoryList *&  list)

List files in the ZIP archive

Returns
: the status of the operation

◆ make_stat() [1/2]

static StatInfo * XrdCl::ZipArchive::make_stat ( const StatInfo starch,
uint64_t  size 
)
inlinestaticprivate

Create a StatInfo object from ZIP archive stat info and the file size.

Parameters
starch: ZIP archive stat info
size: file size
Returns
: StatInfo object

References XrdCl::StatInfo::GetFlags(), XrdCl::StatInfo::IsWritable, XrdCl::StatInfo::SetFlags(), and XrdCl::StatInfo::SetSize().

Referenced by make_stat(), and Stat().

◆ make_stat() [2/2]

StatInfo * XrdCl::ZipArchive::make_stat ( const std::string &  fn)
inlineprivate

Create a StatInfo object for a given file within the ZIP archive.

Parameters
fn: file name
Returns
: StatInfo object for the given file

References archive, cdmap, cdvec, XrdCl::Status::IsOK(), make_stat(), and XrdCl::File::Stat().

◆ make_status()

static XRootDStatus * XrdCl::ZipArchive::make_status ( const XRootDStatus status = XRootDStatus())
inlinestaticprivate

Allocate new XRootDStatus object.

◆ OpenArchive()

XRootDStatus XrdCl::ZipArchive::OpenArchive ( const std::string &  url,
OpenFlags::Flags  flags,
ResponseHandler handler,
uint16_t  timeout = 0 
)

Open ZIP Archive (and parse the Central Directory)

Parameters
url: the URL of the ZIP archive
flags: open flags to be used when openning the file
handler: user callback
timeout: operation timeout
Returns
: the status of the operation

◆ OpenFile()

XRootDStatus XrdCl::ZipArchive::OpenFile ( const std::string &  fn,
OpenFlags::Flags  flags = OpenFlags::None,
uint64_t  size = 0,
uint32_t  crc32 = 0 
)

Open a file within the ZIP Archive

Parameters
fn: file name to be opened
flags: open flags (either 'Read' or 'New | Write')
size: file size (to be included in the LFH)
crc32: file crc32 (to be included in the LFH)
Returns
: the status of the operation

◆ OpenOnly()

XRootDStatus XrdCl::ZipArchive::OpenOnly ( const std::string &  url,
bool  update,
ResponseHandler handler,
uint16_t  timeout = 0 
)
private

Open the ZIP archive in read-only mode without parsing the central directory.

Parameters
url: url of the ZIP archive
handler: user callback
timeout: operation timeout
Returns
: operation status

◆ PgRead()

XRootDStatus XrdCl::ZipArchive::PgRead ( uint64_t  offset,
uint32_t  size,
void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)
inline

PgRead data from an open file

Parameters
offset: offset within the file to read at
size: number of bytes to be read
buffer: the buffer for the data
handler: user callback
timeout: operation timeout
Returns
: the status of the operation

References buffer, XrdCl::errInvalidOp, openfn, PgReadFrom(), and XrdCl::stError.

◆ PgReadFrom()

XRootDStatus XrdCl::ZipArchive::PgReadFrom ( const std::string &  fn,
uint64_t  offset,
uint32_t  size,
void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)

PgRead data from a given file

Parameters
fn: the name of the file from which we are going to read
offset: offset within the file to read at
size: number of bytes to be read
buffer: the buffer for the data
handler: user callback
timeout: operation timeout
Returns
: the status of the operation

Referenced by PgRead().

◆ PkgRsp()

template<typename Response >
static AnyObject * XrdCl::ZipArchive::PkgRsp ( Response *  rsp)
inlinestaticprivate

Package a response into AnyObject (erase the type)

Parameters
rsp: the response to be packaged
Returns
: AnyObject with the response

References XrdCl::AnyObject::Set().

Referenced by Schedule().

◆ Read()

XRootDStatus XrdCl::ZipArchive::Read ( uint64_t  offset,
uint32_t  size,
void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)
inline

Read data from an open file

Parameters
offset: offset within the file to read at
size: number of bytes to be read
buffer: the buffer for the data
handler: user callback
timeout: operation timeout
Returns
: the status of the operation

References buffer, XrdCl::errInvalidOp, openfn, ReadFrom(), and XrdCl::stError.

◆ ReadFrom()

XRootDStatus XrdCl::ZipArchive::ReadFrom ( const std::string &  fn,
uint64_t  offset,
uint32_t  size,
void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)

Read data from a given file

Parameters
fn: the name of the file from which we are going to read
offset: offset within the file to read at
size: number of bytes to be read
buffer: the buffer for the data
handler: user callback
timeout: operation timeout
Returns
: the status of the operation

Referenced by Read().

◆ Schedule()

template<typename Response >
static void XrdCl::ZipArchive::Schedule ( ResponseHandler handler,
XRootDStatus st,
Response *  rsp = nullptr 
)
inlinestaticprivate

Schedule a user callback to be executed in the thread-pool with given status and response.

Parameters
handler: user callback to be scheduled
st: status to be passed to the callback
rsp: response to be passed to the callback

References Free(), XrdCl::PostMaster::GetJobManager(), XrdCl::DefaultEnv::GetPostMaster(), PkgRsp(), and XrdCl::JobManager::QueueJob().

◆ SetCD()

void XrdCl::ZipArchive::SetCD ( const buffer_t buffer)
private

Set central directory for the ZIP archive

Parameters
buffer: a buffer with the central directory to be set

◆ SetProperty()

bool XrdCl::ZipArchive::SetProperty ( const std::string &  name,
const std::string &  value 
)
inline

Set property on the underlying File object.

References archive, and XrdCl::File::SetProperty().

◆ Stat() [1/2]

XRootDStatus XrdCl::ZipArchive::Stat ( const std::string &  fn,
StatInfo *&  info 
)
inline

Get stat info for given file

Parameters
fn: the name of the file
info: output parameter
Returns
: the status of the operation

References cdmap, Done, XrdCl::errInvalidOp, XrdCl::errNotFound, make_stat(), openstage, and XrdCl::stError.

Referenced by Stat().

◆ Stat() [2/2]

XRootDStatus XrdCl::ZipArchive::Stat ( StatInfo *&  info)
inline

Get stat info for an open file

Parameters
info: output parameter
Returns
: the status of the operation

References XrdCl::errInvalidOp, openfn, Stat(), and XrdCl::stError.

◆ UpdateMetadata()

XRootDStatus XrdCl::ZipArchive::UpdateMetadata ( uint32_t  crc32)

Update the metadata of the currently open file

Parameters
crc32: the crc32 checksum
Returns
: the status of the operation

◆ Write()

XRootDStatus XrdCl::ZipArchive::Write ( uint32_t  size,
const void *  buffer,
ResponseHandler handler,
uint16_t  timeout = 0 
)
inline

Append data to a new file

Parameters
size: number of bytes to be appended
buffer: the buffer with the data to be appended
handler: user callback
timeout: operation timeout
Returns
: the status of the operation

References buffer, Done, XrdCl::errInvalidOp, openfn, openstage, and XrdCl::stError.

◆ WriteImpl()

XRootDStatus XrdCl::ZipArchive::WriteImpl ( uint32_t  size,
const void *  buffer,
ResponseHandler handler,
uint16_t  timeout 
)
private

Append data to a new file, implementation

Parameters
size: number of bytes to be appended
buffer: the buffer with the data to be appended
handler: user callback
timeout: operation timeout
Returns
: the status of the operation

Friends And Related Symbol Documentation

◆ ::MicroTest

friend class ::MicroTest
friend

◆ ::XrdEcTests

friend class ::XrdEcTests
friend

◆ ReadFromImpl

template<typename RSP >
XRootDStatus ReadFromImpl ( ZipArchive ,
const std::string &  ,
uint64_t  ,
uint32_t  ,
void *  ,
ResponseHandler ,
uint16_t   
)
friend

◆ XrdEc::OpenOnlyImpl

template<bool >
friend class XrdEc::OpenOnlyImpl
friend

◆ XrdEc::Reader

friend class XrdEc::Reader
friend

◆ XrdEc::StrmWriter

friend class XrdEc::StrmWriter
friend

Member Data Documentation

◆ archive

File XrdCl::ZipArchive::archive
private

◆ archsize

uint64_t XrdCl::ZipArchive::archsize
private

◆ buffer

std::unique_ptr<char[]> XrdCl::ZipArchive::buffer
private

Referenced by Clear(), PgRead(), Read(), and Write().

◆ cdexists

bool XrdCl::ZipArchive::cdexists
private

◆ cdmap

cdmap_t XrdCl::ZipArchive::cdmap
private

◆ cdoff

uint64_t XrdCl::ZipArchive::cdoff
private

◆ cdvec

cdvec_t XrdCl::ZipArchive::cdvec
private

Referenced by Clear(), GetCRC32(), GetOffset(), and make_stat().

◆ ckpinit

bool XrdCl::ZipArchive::ckpinit
private

◆ eocd

std::unique_ptr<EOCD> XrdCl::ZipArchive::eocd
private

Referenced by Clear(), and GetOffset().

◆ lfh

std::unique_ptr<LFH> XrdCl::ZipArchive::lfh
private

Referenced by CloseFile().

◆ newfiles

new_files_t XrdCl::ZipArchive::newfiles
private

◆ openfn

std::string XrdCl::ZipArchive::openfn
private

Referenced by CloseFile(), PgRead(), Read(), Stat(), and Write().

◆ openstage

OpenStages XrdCl::ZipArchive::openstage
private

◆ orgcdbuf

buffer_t XrdCl::ZipArchive::orgcdbuf
private

◆ orgcdcnt

uint32_t XrdCl::ZipArchive::orgcdcnt
private

◆ orgcdsz

uint32_t XrdCl::ZipArchive::orgcdsz
private

◆ updated

bool XrdCl::ZipArchive::updated
private

◆ zip64eocd

std::unique_ptr<ZIP64_EOCD> XrdCl::ZipArchive::zip64eocd
private

Referenced by Clear(), and GetOffset().

◆ zipcache

zipcache_t XrdCl::ZipArchive::zipcache
private

The documentation for this class was generated from the following file: