|
MLBookProc 2.1
|
The LibArchive class. More...
#include <LibArchive.h>

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 |
The LibArchive class.
This class contains methods to work with archives.
| LibArchive::LibArchive | ( | const std::shared_ptr< MLBookProc > & | mlbp | ) |
LibArchive constructor.
| mlbp | Smart pointer to MLBookProc object. |
|
protected |
Handles libarchive errors.
This method throws std::exception in all cases.
| a | Smart pointer to archive object (see libarchive documentation for details). |
| message | Message to be prepended to libarchive error message. |
|
staticprotected |
Close callback function for libarchive.
| a | Pointer to archive object (see libarchive documentation for details). |
| client_data | Pointer to client data. |
|
protected |
Returns permissions read from entry.
| e | Smart pointer to archive_entry object (see libarchive documentation for details). |
|
protected |
Initializes archive for reading.
| fd | Smart pointer to LibArchiveFileData object. |
|
protected |
Initializes archive for writing.
| fd | Smart pointer to LibArchiveFileData object. |
| void LibArchive::listFilesInArchive | ( | const std::filesystem::path & | archive_path, |
| std::vector< std::tuple< std::string, uint64_t, uint64_t > > & | result ) |
Obtains entries from archive.
| 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.
| 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.
| 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.
| 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). |
|
staticprotected |
Open callback function for libarchive.
| a | Pointer to archive object (see libarchive documentation for details). |
| client_data | Pointer to client data. |
|
staticprotected |
Read callback function for libarchive.
| a | Pointer to archive object (see libarchive documentation for details). |
| client_data | Pointer to client data. |
| buffer | Pointer to buffer. |
|
staticprotected |
Seek callback function for libarchive.
| 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. |
|
protected |
Sets user id, group id (only Linux), user name and group name to entry.
| e | Smart pointer to archive_entry object (see libarchive documentation for details). |
|
staticprotected |
Skip callback function for libarchive.
| a | Pointer to archive object (see libarchive documentation for details). |
| client_data | Pointer to client data. |
| request | Number of bytes to skip. |
| 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.
| 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). |
| 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.
| 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). |
|
protected |
Unpacks single entry to buffer.
| a | Smart pointer to archive object (see libarchive documentation for details). |
| e | Smart pointer to archive_entry object (see libarchive documentation for details). |
|
protected |
Unpacks single entry to directory.
| 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.
| 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). |
| 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.
| 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). |
|
protected |
Unpacks file to buffer.
| fd | Smart pointer to LibArchiveFileData object. |
| filename | File to be unpacked. |
| result | Buffer file to be unpacked to. |
|
protected |
Unpacks file to directory.
| fd | Smart pointer to LibArchiveFileData object. |
| filename | File to be unpacked. |
| directory | Directory file to be unpacked to. |
| std::string LibArchive::unpackZipBufferFileToBuffer | ( | const std::string & | buffer, |
| const std::string & | filename ) |
Same as unpackZipFileToBuffer(), but uses buffered archive instead.
| buffer | Archive file content. |
| filename | Name of file in archive. |
| 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.
| buffer | Archive file content. |
| filename | Name of file in archive. |
| directory | Path to directory file should be unpacked to. |
| 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.
| archive_path | Path to archive. |
| filename | Name of file in archive. |
| 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.
| archive_path | Path to archive. |
| filename | Name of file in archive. |
| directory | Path to directory file should be unpacked to. |
| 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.
| 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. |
|
protected |
Writes buffer to archive.
| 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. |
|
staticprotected |
Write callback function for libarchive.
| 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. |
|
protected |
Writes file to archive.
| 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.
| 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. |
|
protected |
Smart pointer to MLBookProc object.