Horizon
Classes | Public Types | Public Member Functions | List of all members
libzip::archive Class Reference

Safe wrapper on the struct zip structure. More...

#include <zip.hpp>

Classes

class  iterator
 Base iterator class. More...
 

Public Types

using value_type = libzip::stat
 Iterator conversion to Stat.
 
using reference = libzip::stat
 Reference is a copy of Stat.
 
using const_reference = libzip::stat
 Const reference is a copy of Stat.
 
using pointer = stat_ptr
 Pointer is a small wrapper.
 
using size_type = unsigned
 Type of difference.
 
using const_iterator = iterator
 Const random access iterator.
 

Public Member Functions

 archive (const std::string &path, flags_t flags=0)
 Open an archive on the disk. More...
 
 archive (archive &&other) noexcept=default
 Move constructor defaulted. More...
 
archiveoperator= (archive &&other) noexcept=default
 Move operator defaulted. More...
 
iterator begin () noexcept
 Get an iterator to the beginning. More...
 
const_iterator begin () const noexcept
 Overloaded function. More...
 
const_iterator cbegin () const noexcept
 Overloaded function. More...
 
iterator end () noexcept
 Get an iterator to the end. More...
 
const_iterator end () const noexcept
 Overloaded function. More...
 
const_iterator cend () const noexcept
 Overloaded function. More...
 
void set_file_comment (uint64_t index, const std::string &text="", flags_t flags=0)
 Set a comment on a file. More...
 
std::string file_comment (uint64_t index, flags_t flags=0) const
 Get a comment from a file. More...
 
void set_comment (const std::string &comment)
 Set the archive comment. More...
 
std::string comment (flags_t flags=0) const
 Get the archive comment. More...
 
bool exists (const std::string &name, flags_t flags=0) const noexcept
 Check if a file exists on the archive. More...
 
int64_t find (const std::string &name, flags_t flags=0) const
 Locate a file on the archive. More...
 
libzip::stat stat (const std::string &name, flags_t flags=0) const
 Get information about a file. More...
 
libzip::stat stat (uint64_t index, flags_t flags=0) const
 Get information about a file. More...
 
int64_t add (const source &source, const std::string &name, flags_t flags=0)
 Add a file to the archive. More...
 
int64_t mkdir (const std::string &directory, flags_t flags=0)
 Create a directory in the archive. More...
 
void replace (const source &source, uint64_t index, flags_t flags=0)
 Replace an existing file in the archive. More...
 
file open (const std::string &name, flags_t flags=0, const std::string &password="")
 Open a file in the archive. More...
 
file open (uint64_t index, flags_t flags=0, const std::string &password="")
 Open a file in the archive. More...
 
void rename (uint64_t index, const std::string &name, flags_t flags=0)
 Rename an existing entry in the archive. More...
 
void set_file_compression (uint64_t index, int32_t comp, uint32_t flags=0)
 Set file compression. More...
 
void remove (uint64_t index)
 Delete a file from the archive. More...
 
int64_t num_entries (flags_t flags=0) const noexcept
 Get the number of entries in the archive. More...
 
void unchange (uint64_t index)
 Revert changes on the file. More...
 
void unchange_all ()
 Revert all changes. More...
 
void unchange_archive ()
 Revert changes to archive. More...
 
void set_default_password (const std::string &password="")
 Set the defaut password. More...
 
void set_flag (flags_t flag, int value)
 Set an archive flag. More...
 
int flag (flags_t which, flags_t flags=0) const
 Get an archive flag. More...
 

Detailed Description

Safe wrapper on the struct zip structure.

Constructor & Destructor Documentation

◆ archive() [1/2]

libzip::archive::archive ( const std::string &  path,
flags_t  flags = 0 
)
inline

Open an archive on the disk.

Parameters
paththe path
flagsthe optional flags
Exceptions
std::runtime_erroron errors

◆ archive() [2/2]

libzip::archive::archive ( archive &&  other)
defaultnoexcept

Move constructor defaulted.

Parameters
otherthe other archive

Member Function Documentation

◆ add()

int64_t libzip::archive::add ( const source source,
const std::string &  name,
flags_t  flags = 0 
)
inline

Add a file to the archive.

Parameters
sourcethe source
namethe name entry in the archive
flagsthe optional flags
Returns
the new index in the archive
Exceptions
std::runtime_erroron errors
See also
source::file
source::buffer

◆ begin() [1/2]

const_iterator libzip::archive::begin ( ) const
inlinenoexcept

Overloaded function.

Returns
the iterator

◆ begin() [2/2]

iterator libzip::archive::begin ( )
inlinenoexcept

Get an iterator to the beginning.

Returns
the iterator

◆ cbegin()

const_iterator libzip::archive::cbegin ( ) const
inlinenoexcept

Overloaded function.

Returns
the iterator

◆ cend()

const_iterator libzip::archive::cend ( ) const
inlinenoexcept

Overloaded function.

Returns
the iterator

◆ comment()

std::string libzip::archive::comment ( flags_t  flags = 0) const
inline

Get the archive comment.

Parameters
flagsthe optional flags
Returns
the comment
Exceptions
std::runtime_erroron errors

◆ end() [1/2]

const_iterator libzip::archive::end ( ) const
inlinenoexcept

Overloaded function.

Returns
the iterator

◆ end() [2/2]

iterator libzip::archive::end ( )
inlinenoexcept

Get an iterator to the end.

Returns
the iterator

◆ exists()

bool libzip::archive::exists ( const std::string &  name,
flags_t  flags = 0 
) const
inlinenoexcept

Check if a file exists on the archive.

Parameters
namethe name
flagsthe optional flags
Returns
if the file exists

◆ file_comment()

std::string libzip::archive::file_comment ( uint64_t  index,
flags_t  flags = 0 
) const
inline

Get a comment from a file.

Parameters
indexthe file index in the archive
flagsthe optional flags
Returns
the comment
Exceptions
std::runtime_erroron errors

◆ find()

int64_t libzip::archive::find ( const std::string &  name,
flags_t  flags = 0 
) const
inline

Locate a file on the archive.

Parameters
namethe name
flagsthe optional flags
Returns
the index
Exceptions
std::runtime_erroron errors

◆ flag()

int libzip::archive::flag ( flags_t  which,
flags_t  flags = 0 
) const
inline

Get an archive flag.

Parameters
whichwhich flag
flagsthe optional flags
Returns
the value
Exceptions
std::runtime_erroron errors

◆ mkdir()

int64_t libzip::archive::mkdir ( const std::string &  directory,
flags_t  flags = 0 
)
inline

Create a directory in the archive.

Parameters
directorythe directory name
flagsthe optional flags
Returns
the new index in the archive
Exceptions
std::runtime_erroron errors

◆ num_entries()

int64_t libzip::archive::num_entries ( flags_t  flags = 0) const
inlinenoexcept

Get the number of entries in the archive.

Parameters
flagsthe optional flags
Returns
the number of entries

◆ open() [1/2]

file libzip::archive::open ( const std::string &  name,
flags_t  flags = 0,
const std::string &  password = "" 
)
inline

Open a file in the archive.

Parameters
namethe name
flagsthe optional flags
passwordthe optional password
Returns
the opened file
Exceptions
std::runtime_erroron errors

◆ open() [2/2]

file libzip::archive::open ( uint64_t  index,
flags_t  flags = 0,
const std::string &  password = "" 
)
inline

Open a file in the archive.

Overloaded function.

Parameters
indexthe file index in the archive
flagsthe optional flags
passwordthe optional password
Returns
the opened file
Exceptions
std::runtime_erroron errors

◆ operator=()

archive& libzip::archive::operator= ( archive &&  other)
defaultnoexcept

Move operator defaulted.

Parameters
otherthe other archive
Returns
*this

◆ remove()

void libzip::archive::remove ( uint64_t  index)
inline

Delete a file from the archive.

Parameters
indexthe file index in the archive
Exceptions
std::runtime_erroron errors

◆ rename()

void libzip::archive::rename ( uint64_t  index,
const std::string &  name,
flags_t  flags = 0 
)
inline

Rename an existing entry in the archive.

Parameters
indexthe file index in the archive
namethe new name
flagsthe optional flags
Exceptions
std::runtime_erroron errors

◆ replace()

void libzip::archive::replace ( const source source,
uint64_t  index,
flags_t  flags = 0 
)
inline

Replace an existing file in the archive.

Parameters
sourcethe source
indexthe file index in the archiev
flagsthe optional flags
Exceptions
std::runtime_erroron errors

◆ set_comment()

void libzip::archive::set_comment ( const std::string &  comment)
inline

Set the archive comment.

Parameters
commentthe comment
Exceptions
std::runtime_erroron errors

◆ set_default_password()

void libzip::archive::set_default_password ( const std::string &  password = "")
inline

Set the defaut password.

Parameters
passwordthe password or empty to unset it
Exceptions
std::runtime_erroron errors

◆ set_file_comment()

void libzip::archive::set_file_comment ( uint64_t  index,
const std::string &  text = "",
flags_t  flags = 0 
)
inline

Set a comment on a file.

Parameters
indexthe file index in the archive
textthe text or empty to remove the comment
flagsthe optional flags
Exceptions
std::runtime_erroron errors

◆ set_file_compression()

void libzip::archive::set_file_compression ( uint64_t  index,
int32_t  comp,
uint32_t  flags = 0 
)
inline

Set file compression.

Parameters
indexthe file index in the archive
compthe compression
flagsthe optional flags
Exceptions
std::runtime_erroron errors

◆ set_flag()

void libzip::archive::set_flag ( flags_t  flag,
int  value 
)
inline

Set an archive flag.

Parameters
flagthe flag to set
valuethe value
Exceptions
std::runtime_erroron errors

◆ stat() [1/2]

libzip::stat libzip::archive::stat ( const std::string &  name,
flags_t  flags = 0 
) const
inline

Get information about a file.

Parameters
namethe name
flagsthe optional flags
Returns
the structure
Exceptions
std::runtime_erroron errors

◆ stat() [2/2]

libzip::stat libzip::archive::stat ( uint64_t  index,
flags_t  flags = 0 
) const
inline

Get information about a file.

Overloaded function.

Parameters
indexthe file index in the archive
flagsthe optional flags
Returns
the structure
Exceptions
std::runtime_erroron errors

◆ unchange()

void libzip::archive::unchange ( uint64_t  index)
inline

Revert changes on the file.

Parameters
indexthe index
Exceptions
std::runtime_erroron errors

◆ unchange_all()

void libzip::archive::unchange_all ( )
inline

Revert all changes.

Exceptions
std::runtime_erroron errors

◆ unchange_archive()

void libzip::archive::unchange_archive ( )
inline

Revert changes to archive.

Exceptions
std::runtime_erroron errors

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