CBMC
mz_zip_archivet Class Referencefinal

Thin object-oriented wrapper around the MZ Zip library Zip file reader and extractor. More...

#include <mz_zip_archive.h>

+ Collaboration diagram for mz_zip_archivet:

Public Member Functions

 mz_zip_archivet (const std::string &filename)
 Open a zip archive. More...
 
 mz_zip_archivet (const void *data, size_t size)
 Loads a zip buffer. More...
 
 mz_zip_archivet (const mz_zip_archivet &)=delete
 
mz_zip_archivetoperator= (const mz_zip_archivet &)=delete
 
 mz_zip_archivet (mz_zip_archivet &&other)
 Move constructor. Doesn't throw. Leaves other object invalidated. More...
 
mz_zip_archivetoperator= (mz_zip_archivet &&other)
 Move assignment. More...
 
 ~mz_zip_archivet ()
 
size_t get_num_files ()
 Get number of files in the archive. More...
 
std::string get_filename (size_t index)
 Get file name of nth file in the archive. More...
 
std::string extract (size_t index)
 Get contents of nth file in the archive. More...
 
void extract_to_file (size_t index, const std::string &path)
 Write contents of nth file in the archive to a file. More...
 

Private Attributes

std::unique_ptr< mz_zip_archive_statetm_state
 

Detailed Description

Thin object-oriented wrapper around the MZ Zip library Zip file reader and extractor.

Not thread safe. Move only.

Definition at line 20 of file mz_zip_archive.h.

Constructor & Destructor Documentation

◆ mz_zip_archivet() [1/4]

mz_zip_archivet::mz_zip_archivet ( const std::string &  filename)
explicit

Open a zip archive.

Parameters
filenamePath of the zip archive
Exceptions
Throwsstd::runtime_error if file cannot be opened

Definition at line 47 of file mz_zip_archive.cpp.

◆ mz_zip_archivet() [2/4]

mz_zip_archivet::mz_zip_archivet ( const void *  data,
size_t  size 
)

Loads a zip buffer.

Parameters
datapointer to the memory buffer
sizesize of the buffer
Exceptions
Throwsstd::runtime_error if data is not in correct format

Definition at line 50 of file mz_zip_archive.cpp.

◆ mz_zip_archivet() [3/4]

mz_zip_archivet::mz_zip_archivet ( const mz_zip_archivet )
delete

◆ mz_zip_archivet() [4/4]

mz_zip_archivet::mz_zip_archivet ( mz_zip_archivet &&  other)

Move constructor. Doesn't throw. Leaves other object invalidated.

Definition at line 54 of file mz_zip_archive.cpp.

◆ ~mz_zip_archivet()

mz_zip_archivet::~mz_zip_archivet ( )
default

Member Function Documentation

◆ extract()

std::string mz_zip_archivet::extract ( size_t  index)

Get contents of nth file in the archive.

Parameters
indexid of the file in the archive
Exceptions
Throwsstd::runtime_error if file cannot be extracted
Returns
Contents of the file in the archive

Definition at line 87 of file mz_zip_archive.cpp.

◆ extract_to_file()

void mz_zip_archivet::extract_to_file ( size_t  index,
const std::string &  path 
)

Write contents of nth file in the archive to a file.

Parameters
indexid of the file in the archive
pathpath to which to write the contents of the file
Exceptions
Throwsstd::runtime_error if file cannot be written

Definition at line 105 of file mz_zip_archive.cpp.

◆ get_filename()

std::string mz_zip_archivet::get_filename ( size_t  index)

Get file name of nth file in the archive.

Parameters
indexid of the file in the archive
Returns
Name of the file in the archive

Definition at line 72 of file mz_zip_archive.cpp.

◆ get_num_files()

size_t mz_zip_archivet::get_num_files ( )

Get number of files in the archive.

Definition at line 67 of file mz_zip_archive.cpp.

◆ operator=() [1/2]

mz_zip_archivet& mz_zip_archivet::operator= ( const mz_zip_archivet )
delete

◆ operator=() [2/2]

mz_zip_archivet & mz_zip_archivet::operator= ( mz_zip_archivet &&  other)

Move assignment.

Doesn't throw. Replaces this object's state with other object's state. Invalidates other object.

Definition at line 61 of file mz_zip_archive.cpp.

Member Data Documentation

◆ m_state

std::unique_ptr<mz_zip_archive_statet> mz_zip_archivet::m_state
private

Definition at line 61 of file mz_zip_archive.h.


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