QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGClibarchive Namespace Reference

Classes

class  ArchiveReader
 RAII wrapper for libarchive reader with automatic cleanup. More...
 

Typedefs

using ProgressCallback = QGCCompression::ProgressCallback
 
using ArchiveEntry = QGCCompression::ArchiveEntry
 
using ArchiveStats = QGCCompression::ArchiveStats
 
using EntryFilter = QGCCompression::EntryFilter
 

Enumerations

enum class  ReaderMode { AllFormats , RawFormat }
 Mode for ArchiveReader format support. More...
 

Functions

QString lastDetectedFormatName ()
 
QString lastDetectedFilterName ()
 
la_ssize_t deviceReadCallback (struct archive *, void *clientData, const void **buffer)
 
la_int64_t deviceSkipCallback (struct archive *, void *clientData, la_int64_t request)
 
int deviceCloseCallback (struct archive *, void *)
 
la_int64_t deviceSeekCallback (struct archive *, void *clientData, la_int64_t offset, int whence)
 
ArchiveEntry toArchiveEntry (struct archive_entry *entry)
 
bool openArchiveForReading (struct archive *a, const QString &filePath, QByteArray &resourceData)
 
bool extractAnyArchive (const QString &archivePath, const QString &outputDirectoryPath, ProgressCallback progress, qint64 maxBytes)
 
bool extractArchiveAtomic (const QString &archivePath, const QString &outputDirectoryPath, ProgressCallback progress, qint64 maxBytes)
 
bool extractSingleFile (const QString &archivePath, const QString &fileName, const QString &outputPath)
 
QByteArray extractFileToMemory (const QString &archivePath, const QString &fileName)
 
bool extractMultipleFiles (const QString &archivePath, const QStringList &fileNames, const QString &outputDirectoryPath)
 
bool extractByPattern (const QString &archivePath, const QStringList &patterns, const QString &outputDirectoryPath, QStringList *extractedFiles)
 
bool validateArchive (const QString &archivePath)
 
bool fileExistsInArchive (const QString &archivePath, const QString &fileName)
 
QStringList listArchiveEntries (const QString &archivePath)
 
QList< ArchiveEntrylistArchiveEntriesDetailed (const QString &archivePath)
 
ArchiveStats getArchiveStats (const QString &archivePath)
 
bool extractWithFilter (const QString &archivePath, const QString &outputDirectoryPath, EntryFilter filter, ProgressCallback progress, qint64 maxBytes)
 
bool decompressSingleFile (const QString &inputPath, const QString &outputPath, ProgressCallback progress, qint64 maxBytes)
 
QByteArray decompressDataFromMemory (const QByteArray &data, qint64 maxBytes)
 
bool extractFromDevice (QIODevice *device, const QString &outputDirectoryPath, ProgressCallback progress, qint64 maxBytes)
 
QByteArray extractFileDataFromDevice (QIODevice *device, const QString &fileName)
 
bool decompressFromDevice (QIODevice *device, const QString &outputPath, ProgressCallback progress, qint64 maxBytes)
 
QByteArray decompressDataFromDevice (QIODevice *device, qint64 maxBytes)
 

Typedef Documentation

◆ ArchiveEntry

Definition at line 27 of file QGClibarchive.h.

◆ ArchiveStats

Definition at line 28 of file QGClibarchive.h.

◆ EntryFilter

Definition at line 29 of file QGClibarchive.h.

◆ ProgressCallback

Enumeration Type Documentation

◆ ReaderMode

enum class QGClibarchive::ReaderMode
strong

Mode for ArchiveReader format support.

Enumerator
AllFormats 

Support all archive formats (ZIP, TAR, 7z, etc.)

RawFormat 

Raw format for single-file decompression (.gz, .xz, etc.)

Definition at line 38 of file QGClibarchive.h.

Function Documentation

◆ decompressDataFromDevice()

QByteArray QGClibarchive::decompressDataFromDevice ( QIODevice *  device,
qint64  maxBytes = 0 
)

Decompress single-file format from QIODevice to memory

Parameters
deviceQIODevice to read from (must be open and readable)
maxBytesMaximum decompressed bytes (0 = unlimited)
Returns
Decompressed data, or empty QByteArray on failure or size limit exceeded

Definition at line 1398 of file QGClibarchive.cc.

References QGClibarchive::ArchiveReader::handle(), QGClibarchive::ArchiveReader::open(), and RawFormat.

Referenced by QGCCompression::decompressFromDevice().

◆ decompressDataFromMemory()

QByteArray QGClibarchive::decompressDataFromMemory ( const QByteArray &  data,
qint64  maxBytes = 0 
)

Decompress data in memory

Parameters
dataCompressed input data
maxBytesMaximum decompressed bytes (0 = unlimited)
Returns
Decompressed data, or empty on failure or size limit exceeded

Definition at line 1291 of file QGClibarchive.cc.

Referenced by QGCCompression::decompressData().

◆ decompressFromDevice()

bool QGClibarchive::decompressFromDevice ( QIODevice *  device,
const QString &  outputPath,
ProgressCallback  progress = nullptr,
qint64  maxBytes = 0 
)

Decompress single-file format from QIODevice to disk

Parameters
deviceQIODevice to read from (must be open and readable)
outputPathOutput file path
progressOptional progress callback
maxBytesMaximum decompressed bytes (0 = unlimited)
Returns
true on success, false on failure or size limit exceeded

Definition at line 1377 of file QGClibarchive.cc.

References QGCFileHelper::ensureParentExists(), QGClibarchive::ArchiveReader::handle(), QGClibarchive::ArchiveReader::open(), and RawFormat.

Referenced by QGCCompression::decompressFromDevice().

◆ decompressSingleFile()

bool QGClibarchive::decompressSingleFile ( const QString &  inputPath,
const QString &  outputPath,
ProgressCallback  progress = nullptr,
qint64  maxBytes = 0 
)

Decompress a single compressed file (.gz, .xz, .zst, etc.) to disk

Parameters
inputPathPath to compressed file (or Qt resource path)
outputPathPath for decompressed output
progressOptional progress callback
maxBytesMaximum decompressed bytes (0 = unlimited)
Returns
true on success, false on failure or size limit exceeded

Definition at line 1271 of file QGClibarchive.cc.

References QGClibarchive::ArchiveReader::dataSize(), QGCFileHelper::ensureParentExists(), QGClibarchive::ArchiveReader::handle(), QGClibarchive::ArchiveReader::open(), and RawFormat.

Referenced by QGCCompression::decompressFile().

◆ deviceCloseCallback()

int QGClibarchive::deviceCloseCallback ( struct archive *  a,
void *  clientData 
)

Close callback for QIODevice streaming (does not close device)

Parameters
clientDataQIODevice pointer
Returns
ARCHIVE_OK

Definition at line 114 of file QGClibarchive.cc.

Referenced by QGClibarchive::ArchiveReader::open(), and QGCArchiveDeviceBase::openArchive().

◆ deviceReadCallback()

la_ssize_t QGClibarchive::deviceReadCallback ( struct archive *  a,
void *  clientData,
const void **  buffer 
)

Read callback for QIODevice streaming

Parameters
clientDataQIODevice pointer
bufferOutput pointer to buffer
Returns
Bytes read, or ARCHIVE_FATAL on error

Definition at line 75 of file QGClibarchive.cc.

References QGCFileHelper::kBufferSizeMax.

Referenced by QGClibarchive::ArchiveReader::open(), and QGCArchiveDeviceBase::openArchive().

◆ deviceSeekCallback()

la_int64_t QGClibarchive::deviceSeekCallback ( struct archive *  a,
void *  clientData,
la_int64_t  offset,
int  whence 
)

Seek callback for random-access QIODevice (improves ZIP performance)

Parameters
clientDataQIODevice pointer
offsetSeek offset
whenceSEEK_SET, SEEK_CUR, or SEEK_END
Returns
New position, or ARCHIVE_FATAL on error

Definition at line 120 of file QGClibarchive.cc.

Referenced by QGClibarchive::ArchiveReader::open(), and QGCArchiveDeviceBase::openArchive().

◆ deviceSkipCallback()

la_int64_t QGClibarchive::deviceSkipCallback ( struct archive *  a,
void *  clientData,
la_int64_t  request 
)

Skip callback for QIODevice streaming

Parameters
clientDataQIODevice pointer
requestBytes to skip
Returns
Bytes actually skipped

Definition at line 89 of file QGClibarchive.cc.

References QGCFileHelper::kBufferSizeMax.

Referenced by QGClibarchive::ArchiveReader::open(), and QGCArchiveDeviceBase::openArchive().

◆ extractAnyArchive()

bool QGClibarchive::extractAnyArchive ( const QString &  archivePath,
const QString &  outputDirectoryPath,
ProgressCallback  progress = nullptr,
qint64  maxBytes = 0 
)

Extract any supported archive format using libarchive's auto-detection Supports: ZIP, 7z, TAR (all variants), cpio, ar, xar, etc.

Parameters
archivePathPath to the archive file (or Qt resource path)
outputDirectoryPathPath where files will be extracted
progressOptional progress callback (return false to cancel)
maxBytesMaximum total decompressed bytes (0 = unlimited)
Returns
true on success, false on failure or size limit exceeded

Definition at line 747 of file QGClibarchive.cc.

References AllFormats, QGClibarchive::ArchiveReader::dataSize(), QGCFileHelper::ensureDirectoryExists(), getArchiveStats(), QGCFileHelper::hasSufficientDiskSpace(), QGClibarchive::ArchiveReader::open(), QGClibarchive::ArchiveReader::release(), and QGCCompression::ArchiveStats::totalUncompressedSize.

Referenced by QGCCompression::extractArchive().

◆ extractArchiveAtomic()

bool QGClibarchive::extractArchiveAtomic ( const QString &  archivePath,
const QString &  outputDirectoryPath,
ProgressCallback  progress = nullptr,
qint64  maxBytes = 0 
)

Extract archive atomically using a temporary staging directory Provides all-or-nothing semantics: if extraction fails, no partial files remain. Uses a staging directory and atomic rename/swap in the output parent directory.

Parameters
archivePathPath to the archive file (or Qt resource path)
outputDirectoryPathPath where files will be extracted
progressOptional progress callback (return false to cancel)
maxBytesMaximum total decompressed bytes (0 = unlimited)
Returns
true on success, false on failure (no partial files left on failure)
Note
Requires ~2x disk space during extraction for staging

Definition at line 771 of file QGClibarchive.cc.

References AllFormats, QGClibarchive::ArchiveReader::dataSize(), QGCFileHelper::ensureDirectoryExists(), getArchiveStats(), QGCFileHelper::hasSufficientDiskSpace(), QGCFileHelper::joinPath(), QGClibarchive::ArchiveReader::open(), QGClibarchive::ArchiveReader::release(), QGCCompression::ArchiveStats::totalEntries, and QGCCompression::ArchiveStats::totalUncompressedSize.

Referenced by QGCCompression::extractArchiveAtomic().

◆ extractByPattern()

bool QGClibarchive::extractByPattern ( const QString &  archivePath,
const QStringList &  patterns,
const QString &  outputDirectoryPath,
QStringList *  extractedFiles = nullptr 
)

Extract files matching glob patterns from archive (uses libarchive archive_match) Supports wildcards: * (any chars), ? (single char), [...] (char class)

Parameters
archivePathPath to the archive file (or Qt resource path)
patternsGlob patterns to match (e.g., "*.json", "dir/*", "file.txt")
outputDirectoryPathOutput directory
extractedFilesOptional output list of files that were extracted
Returns
true if at least one file matched and extracted, false on error or no matches

Definition at line 994 of file QGClibarchive.cc.

References AllFormats, QGCFileHelper::ensureDirectoryExists(), QGCFileHelper::ensureParentExists(), QGClibarchive::ArchiveReader::handle(), QGCFileHelper::joinPath(), and QGClibarchive::ArchiveReader::open().

Referenced by QGCCompression::extractByPattern().

◆ extractFileDataFromDevice()

QByteArray QGClibarchive::extractFileDataFromDevice ( QIODevice *  device,
const QString &  fileName 
)

Extract a single file from archive device directly to memory

Parameters
deviceQIODevice to read from (must be open and readable)
fileNameName of file inside archive
Returns
File contents, or empty QByteArray if not found

Definition at line 1349 of file QGClibarchive.cc.

References AllFormats, QGClibarchive::ArchiveReader::handle(), and QGClibarchive::ArchiveReader::open().

Referenced by QGCCompression::extractFileDataFromDevice().

◆ extractFileToMemory()

QByteArray QGClibarchive::extractFileToMemory ( const QString &  archivePath,
const QString &  fileName 
)

Extract a single file from any archive directly to memory

Parameters
archivePathPath to the archive file (or Qt resource path)
fileNameName of file inside archive
Returns
File contents, or empty QByteArray if not found or extraction failed

Definition at line 909 of file QGClibarchive.cc.

References AllFormats, QGClibarchive::ArchiveReader::handle(), and QGClibarchive::ArchiveReader::open().

Referenced by QGCCompression::extractFileData().

◆ extractFromDevice()

bool QGClibarchive::extractFromDevice ( QIODevice *  device,
const QString &  outputDirectoryPath,
ProgressCallback  progress = nullptr,
qint64  maxBytes = 0 
)

Extract archive from QIODevice to directory

Parameters
deviceQIODevice to read from (must be open and readable)
outputDirectoryPathPath where files will be extracted
progressOptional progress callback (return false to cancel)
maxBytesMaximum total decompressed bytes (0 = unlimited)
Returns
true on success, false on failure or size limit exceeded

Definition at line 1332 of file QGClibarchive.cc.

References AllFormats, QGCFileHelper::ensureDirectoryExists(), QGClibarchive::ArchiveReader::open(), and QGClibarchive::ArchiveReader::release().

Referenced by QGCCompression::extractFromDevice().

◆ extractMultipleFiles()

bool QGClibarchive::extractMultipleFiles ( const QString &  archivePath,
const QStringList &  fileNames,
const QString &  outputDirectoryPath 
)

Extract multiple files from any archive by name in one pass

Parameters
archivePathPath to the archive file (or Qt resource path)
fileNamesNames of files inside archive
outputDirectoryPathOutput directory
Returns
true if all files found and extracted

Definition at line 941 of file QGClibarchive.cc.

References AllFormats, QGCFileHelper::ensureDirectoryExists(), QGCFileHelper::ensureParentExists(), QGClibarchive::ArchiveReader::handle(), QGCFileHelper::joinPath(), and QGClibarchive::ArchiveReader::open().

Referenced by QGCCompression::extractFiles().

◆ extractSingleFile()

bool QGClibarchive::extractSingleFile ( const QString &  archivePath,
const QString &  fileName,
const QString &  outputPath 
)

Extract a single file from any archive by name

Parameters
archivePathPath to the archive file (or Qt resource path)
fileNameName of file inside archive
outputPathOutput file path
Returns
true on success, false if not found or extraction failed

Definition at line 885 of file QGClibarchive.cc.

References AllFormats, QGCFileHelper::ensureParentExists(), QGClibarchive::ArchiveReader::handle(), and QGClibarchive::ArchiveReader::open().

Referenced by QGCCompression::extractFile().

◆ extractWithFilter()

bool QGClibarchive::extractWithFilter ( const QString &  archivePath,
const QString &  outputDirectoryPath,
EntryFilter  filter,
ProgressCallback  progress = nullptr,
qint64  maxBytes = 0 
)

Extract archive with per-entry filtering

Parameters
archivePathPath to the archive file (or Qt resource path)
outputDirectoryPathPath where files will be extracted
filterCallback to decide which entries to extract
progressOptional progress callback (return false to cancel)
maxBytesMaximum total decompressed bytes (0 = unlimited)
Returns
true on success (even if all entries filtered out), false on failure

Definition at line 1188 of file QGClibarchive.cc.

References AllFormats, QGClibarchive::ArchiveReader::dataSize(), QGCFileHelper::ensureDirectoryExists(), QGCFileHelper::ensureParentExists(), getArchiveStats(), QGClibarchive::ArchiveReader::handle(), QGCFileHelper::hasSufficientDiskSpace(), QGCCompression::ArchiveEntry::isDirectory, QGCFileHelper::joinPath(), QGCCompression::ArchiveEntry::name, QGClibarchive::ArchiveReader::open(), QGCCompression::ArchiveEntry::size, toArchiveEntry(), and QGCCompression::ArchiveStats::totalUncompressedSize.

Referenced by QGCCompression::extractArchiveFiltered().

◆ fileExistsInArchive()

bool QGClibarchive::fileExistsInArchive ( const QString &  archivePath,
const QString &  fileName 
)

Check if a file exists in an archive without extracting

Parameters
archivePathPath to the archive file (or Qt resource path)
fileNameName of file to check for
Returns
true if file exists in archive

Definition at line 1096 of file QGClibarchive.cc.

References AllFormats, QGClibarchive::ArchiveReader::handle(), and QGClibarchive::ArchiveReader::open().

Referenced by QGCCompression::fileExists().

◆ getArchiveStats()

◆ lastDetectedFilterName()

QString QGClibarchive::lastDetectedFilterName ( )

Get the detected filter name from the last archive operation (thread-local)

Returns
Filter name like "gzip", "xz", "zstd", "none", or empty

Definition at line 62 of file QGClibarchive.cc.

Referenced by QGCCompression::captureFormatInfo().

◆ lastDetectedFormatName()

QString QGClibarchive::lastDetectedFormatName ( )

Get the detected format name from the last archive operation (thread-local)

Returns
Format name like "ZIP 2.0 (deflation)", "POSIX ustar", "RAW", or empty

Definition at line 57 of file QGClibarchive.cc.

Referenced by QGCCompression::captureFormatInfo().

◆ listArchiveEntries()

QStringList QGClibarchive::listArchiveEntries ( const QString &  archivePath)

List all entries in an archive

Parameters
archivePathPath to the archive file (or Qt resource path)
Returns
List of entry names, empty on failure

Definition at line 1118 of file QGClibarchive.cc.

References AllFormats, QGClibarchive::ArchiveReader::handle(), and QGClibarchive::ArchiveReader::open().

Referenced by QGCCompression::listArchive().

◆ listArchiveEntriesDetailed()

QList< ArchiveEntry > QGClibarchive::listArchiveEntriesDetailed ( const QString &  archivePath)

List all entries in an archive with detailed metadata

Parameters
archivePathPath to the archive file (or Qt resource path)
Returns
List of ArchiveEntry structs, empty on failure

Definition at line 1136 of file QGClibarchive.cc.

References AllFormats, QGClibarchive::ArchiveReader::handle(), QGClibarchive::ArchiveReader::open(), and toArchiveEntry().

Referenced by QGCCompression::listArchiveDetailed().

◆ openArchiveForReading()

bool QGClibarchive::openArchiveForReading ( struct archive *  a,
const QString &  filePath,
QByteArray &  resourceData 
)

Open an archive for reading, handling both Qt resources and regular files Qt resources are loaded into resourceData; regular files are streamed

Parameters
aInitialized archive reader (call archive_read_support_* first)
filePathPath to file (Qt resource :/ or filesystem path)
resourceDataOutput buffer for Qt resource data (must stay alive until archive is closed)
Returns
true on success

Definition at line 707 of file QGClibarchive.cc.

References QGCFileHelper::isQtResource(), and QGCFileHelper::optimalBufferSize().

Referenced by QGClibarchive::ArchiveReader::open().

◆ toArchiveEntry()

ArchiveEntry QGClibarchive::toArchiveEntry ( struct archive_entry *  entry)

Convert libarchive entry to ArchiveEntry struct

Parameters
entrylibarchive entry pointer (from archive_read_next_header)
Returns
Populated ArchiveEntry with name, size, modified time, isDirectory, permissions

Definition at line 154 of file QGClibarchive.cc.

References QGCCompression::ArchiveEntry::isDirectory, QGCCompression::ArchiveEntry::modified, QGCCompression::ArchiveEntry::name, QGCCompression::ArchiveEntry::permissions, and QGCCompression::ArchiveEntry::size.

Referenced by extractWithFilter(), and listArchiveEntriesDetailed().

◆ validateArchive()

bool QGClibarchive::validateArchive ( const QString &  archivePath)

Validate archive integrity by reading all entries

Parameters
archivePathPath to the archive file
Returns
true if archive is valid

Definition at line 1068 of file QGClibarchive.cc.

References AllFormats, QGClibarchive::ArchiveReader::handle(), QGCFileHelper::kBufferSizeMax, and QGClibarchive::ArchiveReader::open().

Referenced by QGCCompression::validateArchive().