Public Member Functions | List of all members
Unzipper Class Reference

Random access to the entries in a zip archive. More...

#include <Zip.hpp>

Inheritance diagram for Unzipper:
[legend]
Collaboration diagram for Unzipper:
[legend]

Public Member Functions

virtual ~Unzipper ()
 Destroy the unzipper, closing the archive if it is open. More...
 
virtual void close ()
 Close the archive. More...
 
long long entryCount () const
 Get the number of entries in the original archive if one exists. More...
 
std::vector< std::string > entryNames () const
 Get the entry names in the original archive if one exists. More...
 
long long getEntryIndex (const std::string &name) const
 Get the index of the entry that corresponds to the supplied name. More...
 
void getEntryInfo (const std::string &name, ZipEntryInfo &info) const
 Get information on the entry with the specified name. More...
 
void getEntryInfo (long long index, ZipEntryInfo &info) const
 Get information on the entry with the specified index. More...
 
std::string getEntryName (long long index) const
 Get the name of the entry that corresponds to the supplied index. More...
 
Resource::File getPath () const
 Get the file URI that this unzipper accesses. More...
 
bool hasEntry (const std::string &name) const
 Does the original archive have an entry with the specified name? More...
 
bool isOpen () const
 Is an archive currently open? More...
 
virtual void open (const Resource::File &path_, bool verify)
 Open the specified archive for reading. More...
 
virtual void open (const Resource::File &path_, bool verify, const std::string &pw)
 Open the specified archive for reading. More...
 
std::string readArchiveComment () const
 Get the comment on the archive if one exists. More...
 
std::vector< char > readEntryAsBytes (const std::string &name) const
 Get the contents of the specified entry in the original archive if one exists. More...
 
std::vector< char > readEntryAsBytes (long long index) const
 Get the contents of the specified entry in the original archive if one exists. More...
 
std::string readEntryAsString (const std::string &name) const
 Get the contents of the specified entry in the original archive if one exists. More...
 
std::string readEntryAsString (long long index) const
 Get the contents of the specified entry in the original archive if one exists. More...
 
std::string readEntryComment (const std::string &name) const
 Get the comment on the entry if one exists. More...
 
std::string readEntryComment (long long index) const
 Get the comment on the entry if one exists. More...
 

Detailed Description

Random access to the entries in a zip archive.

Zip archive entries can be accessed via their names or their indices.

Unzipper instances are not thread safe and thus must be used in a single thread.

Constructor & Destructor Documentation

◆ ~Unzipper()

virtual ~Unzipper ( )
virtual

Destroy the unzipper, closing the archive if it is open.

Member Function Documentation

◆ close()

virtual void close ( )
virtual

Close the archive.

In order to continue using the instance, a subsequent call to open() is necessary.

If close is called without a corresponding previous call to open(), the result will be a NOP.

Reimplemented in Zipper.

◆ entryCount()

long long entryCount ( ) const

Get the number of entries in the original archive if one exists.

If the archive is being written to (via Zipper) and is new, this will return zero.

Returns
the number of entries in the original archive if one exists or zero
Exceptions
ZipExceptionif the archive is not open

◆ entryNames()

std::vector<std::string> entryNames ( ) const

Get the entry names in the original archive if one exists.

If the archive is being written to (via Zipper) and is new, this will return an empty vector.

Returns
the entry names in the original archive if one exists or an empty vector
Exceptions
ZipExceptionif the archive is not open

◆ getEntryIndex()

long long getEntryIndex ( const std::string &  name) const

Get the index of the entry that corresponds to the supplied name.

Parameters
namethe name of the entry
Returns
the index of the entry that corresponds to the supplied name
Exceptions
ZipExceptionif there is no such entry
ZipExceptionif the archive is not open

◆ getEntryInfo() [1/2]

void getEntryInfo ( const std::string &  name,
ZipEntryInfo info 
) const

Get information on the entry with the specified name.

A valid entry name must first be obtained by calling getEntryPaths().

Parameters
namethe name of the entry
infothe zip entry info structure that will be filled with the info
Exceptions
ZipExceptionif the entry info could not be obtained
ZipExceptionif the archive is not open

◆ getEntryInfo() [2/2]

void getEntryInfo ( long long  index,
ZipEntryInfo info 
) const

Get information on the entry with the specified index.

Parameters
indexthe index of the entry
infothe zip entry info structure that will be filled with the info
Exceptions
ZipExceptionif the entry info could not be obtained
ZipExceptionif the archive is not open

◆ getEntryName()

std::string getEntryName ( long long  index) const

Get the name of the entry that corresponds to the supplied index.

Parameters
indexthe index of the entry
Returns
the name of the entry that corresponds to the supplied index
Exceptions
ZipExceptionif the entry name could not be obtained
ZipExceptionif the archive is not open

◆ getPath()

Resource::File getPath ( ) const
inline

Get the file URI that this unzipper accesses.

Returns
the file URI that this unzipper accesses

◆ hasEntry()

bool hasEntry ( const std::string &  name) const

Does the original archive have an entry with the specified name?

If the archive being written to is new, this will always return false.

Parameters
namethe name of the entry
Returns
true if the original archive has an entry with the specified name
Exceptions
ZipExceptionif the archive is not open

◆ isOpen()

bool isOpen ( ) const
inline

Is an archive currently open?

Returns
true if the archive is currently open

◆ open() [1/2]

virtual void open ( const Resource::File path_,
bool  verify 
)
virtual

Open the specified archive for reading.

Parameters
path_the path to the archive
verifyif true, the implementation will first verify the archive
Exceptions
InvalidArchiveExceptionif verify is true and the archive is deemed to be invalid

Reimplemented in Zipper.

◆ open() [2/2]

virtual void open ( const Resource::File path_,
bool  verify,
const std::string &  pw 
)
virtual

Open the specified archive for reading.

Parameters
path_the path to the archive
verifyif true, the implementation will first verify the archive
pwthe archive's password if encryption was used when writing
Exceptions
InvalidArchiveExceptionif verify is true and the archive is deemed to be invalid

Reimplemented in Zipper.

◆ readArchiveComment()

std::string readArchiveComment ( ) const

Get the comment on the archive if one exists.

If the archive is being written to (via Zipper) and is new, this will return an empty string.

Returns
the comment on the archive if one exists or empty string
Exceptions
ZipExceptionif the archive is not open

◆ readEntryAsBytes() [1/2]

std::vector<char> readEntryAsBytes ( const std::string &  name) const

Get the contents of the specified entry in the original archive if one exists.

A valid entry name must first be obtained by calling getEntryPaths().

Parameters
namethe name of the entry
Returns
the contents of the specified entry as a char vector
Exceptions
ZipExceptionif the entry could not be obtained
ZipExceptionif the archive is not open

◆ readEntryAsBytes() [2/2]

std::vector<char> readEntryAsBytes ( long long  index) const

Get the contents of the specified entry in the original archive if one exists.

Parameters
indexthe index of the entry
Returns
the contents of the specified entry as a char vector
Exceptions
ZipExceptionif the entry could not be obtained
ZipExceptionif the archive is not open

◆ readEntryAsString() [1/2]

std::string readEntryAsString ( const std::string &  name) const

Get the contents of the specified entry in the original archive if one exists.

A valid entry name must first be obtained by calling getEntryPaths().

Parameters
namethe name of the entry
Returns
the contents of the specified entry as a UTF-8 string
Exceptions
ZipExceptionif the entry could not be obtained
ZipExceptionif the archive is not open

◆ readEntryAsString() [2/2]

std::string readEntryAsString ( long long  index) const

Get the contents of the specified entry in the original archive if one exists.

Parameters
indexthe index of the entry
Returns
the contents of the specified entry as a UTF-8 string
Exceptions
ZipExceptionif the entry could not be obtained
ZipExceptionif the archive is not open

◆ readEntryComment() [1/2]

std::string readEntryComment ( const std::string &  name) const

Get the comment on the entry if one exists.

A valid entry name must first be obtained by calling getEntryPaths().

Returns
the comment on the entry if one exists or an empty string
Exceptions
ZipExceptionif the entry comment could not be obtained
ZipExceptionif the archive is not open

◆ readEntryComment() [2/2]

std::string readEntryComment ( long long  index) const

Get the comment on the entry if one exists.

Returns
the comment on the entry if one exists or an empty string
Exceptions
ZipExceptionif the archive is not open
ZipExceptionif the entry comment could not be obtained

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