LibArchive(3)

LibArchive(3) Library Functions Manual LibArchive(3)

NAME

LibArchive - The LibArchive class.

SYNOPSIS

#include <LibArchive.h>

Inherited by ArchiveParser, InpxLoader, and RemoveBook.

Public Member Functions


LibArchive (const std::shared_ptr< MLBookProc > &mlbp)
LibArchive constructor. void listFilesInArchive (const std::filesystem::path &archive_path, std::vector< std::tuple< std::string, uint64_t, uint64_t > > &result)
void listFilesInArchiveBuffer (const std::string &buffer, std::vector< std::tuple< std::string, uint64_t, uint64_t > > &result)
void listFilesInZip (const std::filesystem::path &archive_path, std::vector< std::tuple< std::string, uint64_t, uint64_t > > &result)
void listFilesInZipBuffer (const std::string &buffer, std::vector< std::tuple< std::string, uint64_t, uint64_t > > &result)
std::filesystem::path unpackFileToDirectory (const std::filesystem::path &archive_path, const std::string &filename, const std::filesystem::path &directory, const size_t &offset=size_t(0))
std::filesystem::path unpackBufferFileToDirectory (const std::string &buffer, const std::string &filename, const std::filesystem::path &directory, const size_t &offset=size_t(0))
std::filesystem::path unpackZipFileToDirectory (const std::filesystem::path &archive_path, const std::string &filename, const std::filesystem::path &directory)
std::filesystem::path unpackZipBufferFileToDirectory (const std::string &buffer, const std::string &filename, const std::filesystem::path &directory)
std::string unpackFileToBuffer (const std::filesystem::path &archive_path, const std::string &filename, const size_t &offset=size_t(0))
std::string unpackBufferFileToBuffer (const std::string &buffer, const std::string &filename, const size_t &offset=size_t(0))
std::string unpackZipFileToBuffer (const std::filesystem::path &archive_path, const std::string &filename)
std::string unpackZipBufferFileToBuffer (const std::string &buffer, const std::string &filename)
void writeToArchive (const std::filesystem::path &source_object, const std::filesystem::path &archive_path, std::string name_in_archive, const std::filesystem::perms &perms=std::filesystem::perms::none, const bool &overwrite_existing=true)
void writeBufferObjectToArchive (const std::string &buffer, const std::filesystem::path &archive_path, std::string name_in_archive, const std::filesystem::perms &perms, const bool &overwrite_existing)

Protected Member Functions


std::shared_ptr< archive > initForReading (const std::shared_ptr< LibArchiveFileData > &fd)
std::shared_ptr< archive > initForWriting (const std::shared_ptr< LibArchiveFileData > &fd)
void archiveError (const std::shared_ptr< archive > &a, const std::string &message)
std::filesystem::path unpackToDirectory (std::shared_ptr< LibArchiveFileData > fd, const std::string &filename, const std::filesystem::path &directory)
void unpackToBuffer (std::shared_ptr< LibArchiveFileData > fd, const std::string &filename, std::string &result)
void unpackEntryToDirectory (std::shared_ptr< archive > a, std::shared_ptr< archive_entry > e, const std::filesystem::path &file_path)
std::string unpackEntryToBuffer (std::shared_ptr< archive > a, std::shared_ptr< archive_entry > e)
void writeFile (std::shared_ptr< archive > a, const std::filesystem::path &path, std::string name_in_archive, const std::filesystem::perms &perms)
void writeBufferToArchive (std::shared_ptr< archive > a, std::shared_ptr< archive_entry > e, const std::string &buf)
std::filesystem::perms getPermissionsFromEntry (const std::shared_ptr< archive_entry > &e)
void setUsernameGroupname (std::shared_ptr< archive_entry > e)

Static Protected Member Functions


static int openCallBack (archive *a, void *client_data)
static la_ssize_t readCallBack (archive *a, void *client_data, const void **buffer)
static la_int64_t skipCallback (archive *a, void *client_data, la_int64_t request)
static int closeCallback (archive *a, void *client_data)
static la_int64_t seekCallback (archive *a, void *client_data, la_int64_t offset, int whence)
static la_ssize_t writeCallback (archive *a, void *client_data, const void *buffer, size_t length)

Protected Attributes


std::shared_ptr< MLBookProc > mlbp

Detailed Description

The LibArchive class.

This class contains methods to work with archives.

Constructor & Destructor Documentation

LibArchive::LibArchive (const std::shared_ptr< MLBookProc > & mlbp)

LibArchive constructor.

Parameters

mlbp Smart pointer to MLBookProc object.

Member Function Documentation

void LibArchive::archiveError (const std::shared_ptr< archive > & a, const std::string & message) [protected]

Handles libarchive errors.

This method throws std::exception in all cases.

Parameters

a Smart pointer to archive object (see libarchive documentation for details).
message Message to be prepended to libarchive error message.

int LibArchive::closeCallback (archive * a, void * client_data) [static], [protected]

Close callback function for libarchive.

Parameters

a Pointer to archive object (see libarchive documentation for details).
client_data Pointer to client data.

Returns

ARCHIVE_OK in case of success, ARCHIVE_FATAL otherwise.

std::filesystem::perms LibArchive::getPermissionsFromEntry (const std::shared_ptr< archive_entry > & e) [protected]

Returns permissions read from entry.

Parameters

e Smart pointer to archive_entry object (see libarchive documentation for details).

Returns

std::shared_ptr< archive > LibArchive::initForReading (const std::shared_ptr< LibArchiveFileData > & fd) [protected]

Initializes archive for reading.

Note

This method can throw std::exception in case of errors.

Parameters

fd Smart pointer to LibArchiveFileData object.

Returns

Smart pointer to archive object (see libarchive documentation for details).

std::shared_ptr< archive > LibArchive::initForWriting (const std::shared_ptr< LibArchiveFileData > & fd) [protected]

Initializes archive for writing.

Note

This method can throw std::exception in case of errors.

Parameters

fd Smart pointer to LibArchiveFileData object.

Returns

Smart pointer to archive object (see libarchive documentation for details).

void LibArchive::listFilesInArchive (const std::filesystem::path & archive_path, std::vector< std::tuple< std::string, uint64_t, uint64_t > > & result)

Obtains entries from archive.

Note

This method can throw std::exception in case of errors.

Parameters

archive_path Path to archive.
result Vector of obtained entries. First element of tuple - name of object in archive, second - size of unpacked object, third - offset of entry in archive file (this method sets to 0 in all cases).

void LibArchive::listFilesInArchiveBuffer (const std::string & buffer, std::vector< std::tuple< std::string, uint64_t, uint64_t > > & result)

Same as listFilesInArchive(), but obtains entiries from archive placed in buffer.

Note

This method can throw std::exception in case of errors.

Parameters

buffer Archive file content.
result Vector of obtained entries. First element of tuple - name of object in archive, second - size of unpacked object, third - offset of entry in archive file (this method sets to 0 in all cases).

void LibArchive::listFilesInZip (const std::filesystem::path & archive_path, std::vector< std::tuple< std::string, uint64_t, uint64_t > > & result)

Same as listFilesInArchive(), but designed specially for zip archives. This method can be used to other archives also, but it uses listFilesInArchive() in those cases.

Note

This method can throw std::exception in case of errors.

Parameters

archive_path Path to archive.
result Vector of obtained entries. First element of tuple - name of object in archive, second - size of unpacked object, third - offset of entry in archive file (will be set to 0 in case of non zip archives).

void LibArchive::listFilesInZipBuffer (const std::string & buffer, std::vector< std::tuple< std::string, uint64_t, uint64_t > > & result)

Same as listFilesInZip(), but but obtains entiries from archive placed in buffer.

Note

This method can throw std::exception in case of errors.

Parameters

buffer Archive file content.
result Vector of obtained entries. First element of tuple - name of object in archive, second - size of unpacked object, third - offset of entry in archive file (will be set to 0 in case of non zip archives).

int LibArchive::openCallBack (archive * a, void * client_data) [static], [protected]

Open callback function for libarchive.

Parameters

a Pointer to archive object (see libarchive documentation for details).
client_data Pointer to client data.

Returns

ARCHIVE_OK if the underlying file or data source is successfully opened. If the open fails, returns ARCHIVE_FATAL.

la_ssize_t LibArchive::readCallBack (archive * a, void * client_data, const void ** buffer) [static], [protected]

Read callback function for libarchive.

Parameters

a Pointer to archive object (see libarchive documentation for details).
client_data Pointer to client data.
buffer Pointer to buffer.

Returns

Number of actually read bytes.

la_int64_t LibArchive::seekCallback (archive * a, void * client_data, la_int64_t offset, int whence) [static], [protected]

Seek callback function for libarchive.

Parameters

a Pointer to archive object (see libarchive documentation for details).
client_data Pointer to client data.
offset Requested offset.
whence The possibilities for the third argument to fseek.

Returns

Actual position in file or ARCHIVE_FATAL in case of errors.

void LibArchive::setUsernameGroupname (std::shared_ptr< archive_entry > e) [protected]

Sets user id, group id (only Linux), user name and group name to entry.

Parameters

e Smart pointer to archive_entry object (see libarchive documentation for details).

la_int64_t LibArchive::skipCallback (archive * a, void * client_data, la_int64_t request) [static], [protected]

Skip callback function for libarchive.

Parameters

a Pointer to archive object (see libarchive documentation for details).
client_data Pointer to client data.
request Number of bytes to skip.

Returns

Number of actually skipped bytes.

std::string LibArchive::unpackBufferFileToBuffer (const std::string & buffer, const std::string & filename, const size_t & offset = size_t(0))

Same as unpackFileToBuffer(), but uses buffered archive as source.

Note

This method can throw std::exception in case of errors.

Parameters

buffer Archive file content.
filename Name of file in archive.
offset Offset of file entry in archive (should be set only in case of zip archives).

Returns

Buffer containing unpacked file.

std::filesystem::path LibArchive::unpackBufferFileToDirectory (const std::string & buffer, const std::string & filename, const std::filesystem::path & directory, const size_t & offset = size_t(0))

Same as unpackFileToDirectory(), but uses buffered archive.

Note

This method can throw std::exception in case of errors.

Parameters

buffer Archive file content.
filename Name of file in archive.
directory Path to directory file should be unpacked to.
offset Offset of file entry in archive (should be set only in case of zip archives).

Returns

Absolute path to unpacked file.

std::string LibArchive::unpackEntryToBuffer (std::shared_ptr< archive > a, std::shared_ptr< archive_entry > e) [protected]

Unpacks single entry to buffer.

Parameters

a Smart pointer to archive object (see libarchive documentation for details).
e Smart pointer to archive_entry object (see libarchive documentation for details).

Returns

Buffer containing result (empty if entry is not a file).

void LibArchive::unpackEntryToDirectory (std::shared_ptr< archive > a, std::shared_ptr< archive_entry > e, const std::filesystem::path & file_path) [protected]

Unpacks single entry to directory.

Parameters

a Smart pointer to archive object (see libarchive documentation for details).
e Smart pointer to archive_entry object (see libarchive documentation for details).
file_path Path entry should be unpacked to.

std::string LibArchive::unpackFileToBuffer (const std::filesystem::path & archive_path, const std::string & filename, const size_t & offset = size_t(0))

Unpacks file to buffer.

Note

This method can throw std::exception in case of errors.

Parameters

archive_path Path to archive.
filename Name of file in archive.
offset Offset of file entry in archive (should be set only in case of zip archives).

Returns

Buffer containing unpacked file.

std::filesystem::path LibArchive::unpackFileToDirectory (const std::filesystem::path & archive_path, const std::string & filename, const std::filesystem::path & directory, const size_t & offset = size_t(0))

Unpacks single file from archive to given directory.

Note

This method can throw std::exception in case of errors.

Parameters

archive_path Path to archive.
filename Name of file in archive.
directory Path to directory file should be unpacked to.
offset Offset of file entry in archive (should be set only in case of zip archives).

Returns

Absolute path to unpacked file.

void LibArchive::unpackToBuffer (std::shared_ptr< LibArchiveFileData > fd, const std::string & filename, std::string & result) [protected]

Unpacks file to buffer.

Note

This method can throw std::exception in case of errors.

Parameters

fd Smart pointer to LibArchiveFileData object.
filename File to be unpacked.
result Buffer file to be unpacked to.

std::filesystem::path LibArchive::unpackToDirectory (std::shared_ptr< LibArchiveFileData > fd, const std::string & filename, const std::filesystem::path & directory) [protected]

Unpacks file to directory.

Note

This method can throw std::exception in case of errors.

Parameters

fd Smart pointer to LibArchiveFileData object.
filename File to be unpacked.
directory Directory file to be unpacked to.

Returns

Absolute path to unpacked file.

std::string LibArchive::unpackZipBufferFileToBuffer (const std::string & buffer, const std::string & filename)

Same as unpackZipFileToBuffer(), but uses buffered archive instead.

Note

This method can throw std::exception in case of errors.

Parameters

buffer Archive file content.
filename Name of file in archive.

Returns

Buffer containing unpacked file.

std::filesystem::path LibArchive::unpackZipBufferFileToDirectory (const std::string & buffer, const std::string & filename, const std::filesystem::path & directory)

Same as unpackZipFileToDirectory(), but uses buffered archive as source.

Note

This method can throw std::exception in case of errors.

Parameters

buffer Archive file content.
filename Name of file in archive.
directory Path to directory file should be unpacked to.

Returns

Absolute path to unpacked file.

std::string LibArchive::unpackZipFileToBuffer (const std::filesystem::path & archive_path, const std::string & filename)

Same as unpackFileToBuffer(), but designed for zip archives specially. This method can be used for other types of archives, but it uses unpackFileToBuffer() in those cases.

Note

This method can throw std::exception in case of errors.

Parameters

archive_path Path to archive.
filename Name of file in archive.

Returns

Buffer containing unpacked file.

std::filesystem::path LibArchive::unpackZipFileToDirectory (const std::filesystem::path & archive_path, const std::string & filename, const std::filesystem::path & directory)

Same as unpackFileToDirectory(), but designed for zip archives specially. This method can be used for other types of archives, but it uses unpackFileToDirectory() in those cases.

Note

This method can throw std::exception in case of errors.

Parameters

archive_path Path to archive.
filename Name of file in archive.
directory Path to directory file should be unpacked to.

Returns

Absolute path to unpacked file.

void LibArchive::writeBufferObjectToArchive (const std::string & buffer, const std::filesystem::path & archive_path, std::string name_in_archive, const std::filesystem::perms & perms, const bool & overwrite_existing)

Same as writeToArchive(), but uses buffer as source.

Note

This method can throw std::exception in case of errors.

Parameters

buffer Buffer to be packed to archive.
archive_path Path to archive.
name_in_archive Name of file in archive.
perms File permissions.
overwrite_existing If true archive will be overwritten. If false archive will be repacked and file will be appended to new archive.

void LibArchive::writeBufferToArchive (std::shared_ptr< archive > a, std::shared_ptr< archive_entry > e, const std::string & buf) [protected]

Writes buffer to archive.

Parameters

a Smart pointer to archive object (see libarchive documentation for details).
e Smart pointer to archive_entry object (see libarchive documentation for details).
buf Buffer to be packed.

la_ssize_t LibArchive::writeCallback (archive * a, void * client_data, const void * buffer, size_t length) [static], [protected]

Write callback function for libarchive.

Parameters

a Pointer to archive object (see libarchive documentation for details).
client_data Pointer to client data.
buffer Buffer to be written.
length Size of given buffer.

Returns

Number of actually written bytes.

void LibArchive::writeFile (std::shared_ptr< archive > a, const std::filesystem::path & path, std::string name_in_archive, const std::filesystem::perms & perms) [protected]

Writes file to archive.

Parameters

a Smart pointer to archive object (see libarchive documentation for details).
path Path to file to be packed.
name_in_archive Name of file in archive.
perms File permissions.

void LibArchive::writeToArchive (const std::filesystem::path & source_object, const std::filesystem::path & archive_path, std::string name_in_archive, const std::filesystem::perms & perms = std::filesystem::perms::none, const bool & overwrite_existing = true)

Writes file to archive.

Note

This method can throw std::exception in case of errors.

Parameters

source_object File to be written to archive.
archive_path Path to archive.
name_in_archive Name of file in archive.
perms File permissions. In case of std::filesystem::perms::none, source_object permissions will be used.
overwrite_existing If true archive will be overwritten. If false archive will be repacked and file will be appended to new archive.

Member Data Documentation

std::shared_ptr<MLBookProc> LibArchive::mlbp [protected]

Smart pointer to MLBookProc object.

Warning

Do not set or modify this object yourself.

Author

Generated automatically by Doxygen for MLBookProc from the source code.

Version 2.1 MLBookProc