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

Classes

struct  ArchiveEntry
 Metadata for a single entry in an archive. More...
 
struct  ArchiveStats
 Summary statistics for an archive. More...
 

Typedefs

using ProgressCallback = std::function< bool(qint64 bytesProcessed, qint64 totalBytes)>
 
using EntryFilter = std::function< bool(const ArchiveEntry &entry)>
 

Enumerations

enum class  Error {
  None , FileNotFound , PermissionDenied , InvalidArchive ,
  UnsupportedFormat , SizeLimitExceeded , Cancelled , FileNotInArchive ,
  IoError , InternalError
}
 Error codes for decompression operations. More...
 
enum class  Format {
  Auto , ZIP , SEVENZ , GZIP ,
  XZ , ZSTD , BZIP2 , LZ4 ,
  TAR , TAR_GZ , TAR_XZ , TAR_ZSTD ,
  TAR_BZ2 , TAR_LZ4
}
 Archive and compression format types (for decompression) More...
 
enum class  CompressionLevel { None = 0 , Fast = 1 , Default = 6 , Best = 9 }
 

Functions

Error lastError ()
 Get the error code from the last operation (thread-local)
 
QString lastErrorString ()
 Get a human-readable error message from the last operation (thread-local)
 
QString errorName (Error error)
 Get a human-readable name for an error code.
 
QString detectedFormatName ()
 
QString detectedFilterName ()
 
static bool validateFileInput (const QString &filePath, Format &format)
 
static bool validateArchiveInput (const QString &archivePath, Format &format)
 Validate archive input: file exists, format detected, and is archive format.
 
static bool validateDeviceInput (QIODevice *device)
 Validate device input for streaming operations.
 
static void captureFormatInfo ()
 Capture format detection info from QGClibarchive after an operation.
 
static Format detectFormatFromExtension (const QString &filePath)
 Extension-based format detection (internal helper)
 
Format detectFormat (const QString &filePath, bool useContentFallback)
 
Format detectFormatFromFile (const QString &filePath)
 
Format detectFormatFromData (const QByteArray &data)
 
QString formatExtension (Format format)
 Get file extension for a format.
 
QString formatName (Format format)
 Get human-readable name for a format.
 
bool isArchiveFormat (Format format)
 Check if format is an archive (contains multiple files)
 
bool isCompressionFormat (Format format)
 Check if format is a compression format (single stream)
 
QString strippedPath (const QString &filePath)
 
bool decompressFile (const QString &inputPath, const QString &outputPath, Format format, ProgressCallback progress, qint64 maxDecompressedBytes)
 
QString decompressIfNeeded (const QString &filePath, const QString &outputPath, bool removeOriginal)
 
QByteArray decompressData (const QByteArray &data, Format format, qint64 maxDecompressedBytes)
 
bool extractArchive (const QString &archivePath, const QString &outputDirectoryPath, Format format, ProgressCallback progress, qint64 maxDecompressedBytes)
 
bool extractArchiveAtomic (const QString &archivePath, const QString &outputDirectoryPath, Format format, ProgressCallback progress, qint64 maxDecompressedBytes)
 
bool extractArchiveFiltered (const QString &archivePath, const QString &outputDirectoryPath, EntryFilter filter, ProgressCallback progress, qint64 maxDecompressedBytes)
 
QStringList listArchive (const QString &archivePath, Format format)
 
QList< ArchiveEntrylistArchiveDetailed (const QString &archivePath, Format format)
 
ArchiveStats getArchiveStats (const QString &archivePath, Format format)
 
bool validateArchive (const QString &archivePath, Format format)
 
bool fileExists (const QString &archivePath, const QString &fileName, Format format)
 
bool extractFile (const QString &archivePath, const QString &fileName, const QString &outputPath, Format format)
 
QByteArray extractFileData (const QString &archivePath, const QString &fileName, Format format)
 
bool extractFiles (const QString &archivePath, const QStringList &fileNames, const QString &outputDirectoryPath, Format format)
 
bool extractByPattern (const QString &archivePath, const QStringList &patterns, const QString &outputDirectoryPath, QStringList *extractedFiles, Format format)
 
bool decompressFromDevice (QIODevice *device, const QString &outputPath, ProgressCallback progress, qint64 maxDecompressedBytes)
 
QByteArray decompressFromDevice (QIODevice *device, qint64 maxDecompressedBytes)
 
bool extractFromDevice (QIODevice *device, const QString &outputDirectoryPath, ProgressCallback progress, qint64 maxDecompressedBytes)
 
QByteArray extractFileDataFromDevice (QIODevice *device, const QString &fileName)
 
QByteArray compress (const QByteArray &data, CompressionLevel level)
 
QByteArray uncompress (const QByteArray &data)
 
QByteArray compressData (const QByteArray &data, CompressionLevel level, int minSize)
 
QByteArray uncompressData (const QByteArray &data, qint64 maxDecompressedSize)
 
bool isDataCompressed (const QByteArray &data)
 Check if data has the compressed framing header.
 
int lastCompressionRatio ()
 Compression ratio from the last compressData() call (thread-local, percentage of original size).
 
QByteArray readFile (const QString &filePath, QString *errorString=nullptr, qint64 maxBytes=0)
 Read file contents, transparently decompressing .gz/.xz/.zst/.bz2/.lz4 files.
 
QString computeFileHash (const QString &filePath, QCryptographicHash::Algorithm algorithm=QCryptographicHash::Sha256)
 Hash file contents post-decompression.
 
bool looksLikeCompressedData (const QByteArray &data)
 
QJsonDocument parseCompressedJson (const QByteArray &data, QJsonParseError *error=nullptr)
 Parse JSON from data that may be compressed. Auto-detects gzip/xz/zstd/bzip2/lz4.
 
bool isCompressedFile (const QString &filePath)
 Check if file path indicates a compressed file (.gz, .xz, .zst)
 
bool isArchiveFile (const QString &filePath)
 Check if file path indicates an archive file (.zip, .tar, .tar.gz, etc.)
 

Variables

static constexpr quint8 kHeaderUncompressed = 0x00
 
static constexpr quint8 kHeaderCompressed = 0x01
 
static thread_local int s_lastCompressionRatio = 100
 
constexpr quint32 kDefaultFilePermissions = 0644
 Default Unix permissions for extracted files (rw-r–r–)
 

Detailed Description

Unified decompression interface for archives and single-file compression Uses libarchive for all operations (ZIP, GZIP, XZ, ZSTD, TAR, etc.) NOTE: This module is decompression-only; QGC does not create compressed files

Typedef Documentation

◆ EntryFilter

using QGCCompression::EntryFilter = typedef std::function<bool(const ArchiveEntry &entry)>

Entry filter callback for selective extraction Called for each entry before extraction; return true to extract, false to skip

Parameters
entryMetadata for the archive entry
Returns
true to extract this entry, false to skip it

Definition at line 53 of file QGCCompressionTypes.h.

◆ ProgressCallback

using QGCCompression::ProgressCallback = typedef std::function<bool(qint64 bytesProcessed, qint64 totalBytes)>

Progress callback for long-running operations

Parameters
bytesProcessedBytes processed so far
totalBytesTotal bytes to process (0 if unknown)
Returns
true to continue, false to cancel operation

Definition at line 21 of file QGCCompressionTypes.h.

Enumeration Type Documentation

◆ CompressionLevel

Enumerator
None 
Fast 
Default 
Best 

Definition at line 315 of file QGCCompression.h.

◆ Error

enum class QGCCompression::Error
strong

Error codes for decompression operations.

Enumerator
None 

No error (success)

FileNotFound 

Input file does not exist.

PermissionDenied 

Cannot read input or write output.

InvalidArchive 

Archive is corrupt or invalid.

UnsupportedFormat 

Format not recognized or not supported.

SizeLimitExceeded 

Decompressed size exceeded limit.

Cancelled 

Operation cancelled by progress callback.

FileNotInArchive 

Requested file not found in archive.

IoError 

General I/O error (read/write failure)

InternalError 

Unexpected internal error.

Definition at line 23 of file QGCCompression.h.

◆ Format

enum class QGCCompression::Format
strong

Archive and compression format types (for decompression)

Enumerator
Auto 

Auto-detect from file extension or magic bytes.

ZIP 

ZIP archive (multiple files)

SEVENZ 

7-Zip archive (.7z)

GZIP 

GZIP compression (single file, .gz)

XZ 

XZ/LZMA compression (single file, .xz)

ZSTD 

Zstandard compression (single file, .zst)

BZIP2 

BZip2 compression (single file, .bz2)

LZ4 

LZ4 compression (single file, .lz4)

TAR 

TAR archive (uncompressed, multiple files)

TAR_GZ 

TAR + GZIP (.tar.gz, .tgz)

TAR_XZ 

TAR + XZ (.tar.xz, .txz)

TAR_ZSTD 

TAR + Zstandard (.tar.zst)

TAR_BZ2 

TAR + BZip2 (.tar.bz2, .tbz2)

TAR_LZ4 

TAR + LZ4 (.tar.lz4)

Definition at line 50 of file QGCCompression.h.

Function Documentation

◆ captureFormatInfo()

◆ compress()

QByteArray QGCCompression::compress ( const QByteArray &  data,
CompressionLevel  level = CompressionLevel::Default 
)

Compress data using qCompress (4-byte size header + zlib payload).

Parameters
dataRaw data to compress
levelCompression level
Returns
Compressed data in qCompress format, or empty on failure

Definition at line 909 of file QGCCompression.cc.

References compress().

Referenced by compress().

◆ compressData()

QByteArray QGCCompression::compressData ( const QByteArray &  data,
CompressionLevel  level = CompressionLevel::Default,
int  minSize = 256 
)

Compress data in memory with a framing header byte. Returns header(1) + payload. If compression doesn't reduce size, returns uncompressed with header.

Parameters
dataRaw data to compress
levelCompression level
minSizeMinimum data size to attempt compression (smaller data returned uncompressed)

Definition at line 930 of file QGCCompression.cc.

References compressData(), kHeaderCompressed, kHeaderUncompressed, and s_lastCompressionRatio.

Referenced by compressData().

◆ computeFileHash()

QString QGCCompression::computeFileHash ( const QString &  filePath,
QCryptographicHash::Algorithm  algorithm 
)

Hash file contents post-decompression.

Definition at line 1023 of file QGCCompression.cc.

References QGCArchiveDeviceBase::close(), QGCFileHelper::computeFileHash(), computeFileHash(), isCompressedFile(), and QGCDecompressDevice::open().

Referenced by computeFileHash().

◆ decompressData()

QByteArray QGCCompression::decompressData ( const QByteArray &  data,
Format  format = Format::Auto,
qint64  maxDecompressedBytes = 0 
)

Decompress data in memory

Parameters
dataCompressed input data
formatCompression format (Auto = detect from magic bytes)
maxDecompressedBytesMaximum decompressed size in bytes (0 = unlimited)
Returns
Decompressed data, or empty on failure or if size limit exceeded

Definition at line 620 of file QGCCompression.cc.

References captureFormatInfo(), decompressData(), QGClibarchive::decompressDataFromMemory(), detectFormatFromData(), formatName, and isCompressionFormat().

Referenced by decompressData(), and parseCompressedJson().

◆ decompressFile()

bool QGCCompression::decompressFile ( const QString &  inputPath,
const QString &  outputPath = QString(),
Format  format = Format::Auto,
ProgressCallback  progress = nullptr,
qint64  maxDecompressedBytes = 0 
)

Decompress a single file

Parameters
inputPathPath to compressed file (or Qt resource path :/)
outputPathPath for decompressed output (if empty, strips compression extension)
formatCompression format (Auto = detect from inputPath)
progressOptional progress callback (return false to cancel)
maxDecompressedBytesMaximum decompressed size in bytes (0 = unlimited)
Returns
true on success, false on failure or if size limit exceeded

Definition at line 555 of file QGCCompression.cc.

References captureFormatInfo(), decompressFile(), QGClibarchive::decompressSingleFile(), extractArchive(), formatExtension(), formatName, isArchiveFormat(), isCompressionFormat(), and validateFileInput().

Referenced by decompressFile(), QGCCompressionJob::decompressFile(), QGCCompressionJob::decompressFileAsync(), and decompressIfNeeded().

◆ decompressFromDevice() [1/2]

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

Decompress from QIODevice to file Enables streaming decompression from QNetworkReply, QBuffer, etc.

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

Definition at line 842 of file QGCCompression.cc.

References captureFormatInfo(), QGClibarchive::decompressFromDevice(), decompressFromDevice(), and validateDeviceInput().

Referenced by decompressFromDevice(), and decompressFromDevice().

◆ decompressFromDevice() [2/2]

QByteArray QGCCompression::decompressFromDevice ( QIODevice *  device,
qint64  maxDecompressedBytes = 0 
)

Decompress from QIODevice to memory

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

Definition at line 857 of file QGCCompression.cc.

References captureFormatInfo(), QGClibarchive::decompressDataFromDevice(), decompressFromDevice(), and validateDeviceInput().

◆ decompressIfNeeded()

QString QGCCompression::decompressIfNeeded ( const QString &  filePath,
const QString &  outputPath = QString(),
bool  removeOriginal = false 
)

Decompress file if it's a compressed format, otherwise return original path

Parameters
filePathInput file (may or may not be compressed)
outputPathOutput path (if empty, uses strippedPath)
removeOriginalRemove compressed file after successful decompression (default: false)
Returns
Path to result file (decompressed or original), empty string on failure

Definition at line 597 of file QGCCompression.cc.

References decompressFile(), decompressIfNeeded(), isCompressedFile(), and strippedPath().

Referenced by decompressIfNeeded().

◆ detectedFilterName()

QString QGCCompression::detectedFilterName ( )

Get the detected compression filter name from the last operation (thread-local) Returns names like "gzip", "xz", "zstd", "bzip2", "none", etc. Empty string if no filter was detected

Definition at line 197 of file QGCCompression.cc.

References detectedFilterName().

Referenced by detectedFilterName().

◆ detectedFormatName()

QString QGCCompression::detectedFormatName ( )

Get the detected archive format name from the last operation (thread-local) Returns names like "ZIP 2.0", "POSIX ustar", "RAW", etc. Empty string if no format was detected

Definition at line 192 of file QGCCompression.cc.

References detectedFormatName().

Referenced by detectedFormatName().

◆ detectFormat()

Format QGCCompression::detectFormat ( const QString &  filePath,
bool  useContentFallback = true 
)

Detect format from file path (extension-based, with content fallback) First tries extension-based detection; if that fails, reads file content and uses magic bytes and Qt MIME detection as fallback

Parameters
filePathPath to file
useContentFallbackIf true (default), read file content when extension fails
Returns
Detected format, or Format::Auto if detection failed

Definition at line 320 of file QGCCompression.cc.

References detectFormat(), detectFormatFromExtension(), detectFormatFromFile(), QGCFileHelper::exists(), and formatName.

Referenced by detectFormat(), isArchiveFile(), isCompressedFile(), strippedPath(), and validateFileInput().

◆ detectFormatFromData()

Format QGCCompression::detectFormatFromData ( const QByteArray &  data)

Detect format from data (magic bytes + MIME detection)

Parameters
dataRaw file data (at least first 512 bytes recommended)
Returns
Detected format, or Format::Auto if detection failed

Definition at line 370 of file QGCCompression.cc.

References detectFormatFromData(), and formatName.

Referenced by decompressData(), detectFormatFromData(), detectFormatFromFile(), and looksLikeCompressedData().

◆ detectFormatFromExtension()

static Format QGCCompression::detectFormatFromExtension ( const QString &  filePath)
static

Extension-based format detection (internal helper)

Definition at line 270 of file QGCCompression.cc.

References detectFormatFromExtension().

Referenced by detectFormat(), and detectFormatFromExtension().

◆ detectFormatFromFile()

Format QGCCompression::detectFormatFromFile ( const QString &  filePath)

Detect format from file content only (ignores extension) Reads file and uses magic bytes + Qt MIME detection

Parameters
filePathPath to file
Returns
Detected format, or Format::Auto if detection failed

Definition at line 339 of file QGCCompression.cc.

References detectFormatFromData(), detectFormatFromFile(), formatName, and QGCFileHelper::isQtResource().

Referenced by detectFormat(), and detectFormatFromFile().

◆ errorName()

QString QGCCompression::errorName ( Error  error)

Get a human-readable name for an error code.

Definition at line 165 of file QGCCompression.cc.

References error, and errorName().

Referenced by errorName(), and lastErrorString().

◆ extractArchive()

bool QGCCompression::extractArchive ( const QString &  archivePath,
const QString &  outputDirectoryPath,
Format  format = Format::Auto,
ProgressCallback  progress = nullptr,
qint64  maxDecompressedBytes = 0 
)

Extract an archive to a directory

Parameters
archivePathPath to archive file (or Qt resource path :/)
outputDirectoryPathOutput directory path
formatArchive format (Auto = detect from archivePath)
progressOptional progress callback (return false to cancel)
maxDecompressedBytesMaximum total decompressed size in bytes (0 = unlimited)
Returns
true on success, false on failure or if size limit exceeded

Definition at line 653 of file QGCCompression.cc.

References captureFormatInfo(), QGClibarchive::extractAnyArchive(), extractArchive(), formatName, and validateArchiveInput().

Referenced by decompressFile(), extractArchive(), QGCCompressionJob::extractArchive(), and QGCCompressionJob::extractArchiveAsync().

◆ extractArchiveAtomic()

bool QGCCompression::extractArchiveAtomic ( const QString &  archivePath,
const QString &  outputDirectoryPath,
Format  format = Format::Auto,
ProgressCallback  progress = nullptr,
qint64  maxDecompressedBytes = 0 
)

Extract an archive to a directory atomically (all-or-nothing) Uses staged extraction and an atomic directory swap on success. If extraction or commit fails, the pre-existing output directory is restored.

Parameters
archivePathPath to archive file (or Qt resource path :/)
outputDirectoryPathOutput directory path
formatArchive format (Auto = detect from archivePath)
progressOptional progress callback (return false to cancel)
maxDecompressedBytesMaximum total decompressed size in bytes (0 = unlimited)
Returns
true on success, false on failure or if size limit exceeded

Definition at line 672 of file QGCCompression.cc.

References captureFormatInfo(), extractArchiveAtomic(), QGClibarchive::extractArchiveAtomic(), formatName, and validateArchiveInput().

Referenced by extractArchiveAtomic(), and QGCCompressionJob::extractArchiveAtomic().

◆ extractArchiveFiltered()

bool QGCCompression::extractArchiveFiltered ( const QString &  archivePath,
const QString &  outputDirectoryPath,
EntryFilter  filter,
ProgressCallback  progress = nullptr,
qint64  maxDecompressedBytes = 0 
)

Extract an archive with per-entry filtering

Parameters
archivePathPath to archive file (or Qt resource path :/)
outputDirectoryPathOutput directory path
filterCallback to decide which entries to extract (return true to extract)
progressOptional progress callback (return false to cancel)
maxDecompressedBytesMaximum total decompressed size in bytes (0 = unlimited)
Returns
true on success (even if filter skipped all entries), false on failure

Definition at line 691 of file QGCCompression.cc.

References captureFormatInfo(), extractArchiveFiltered(), QGClibarchive::extractWithFilter(), and validateArchiveInput().

Referenced by extractArchiveFiltered().

◆ extractByPattern()

bool QGCCompression::extractByPattern ( const QString &  archivePath,
const QStringList &  patterns,
const QString &  outputDirectoryPath,
QStringList *  extractedFiles = nullptr,
Format  format = Format::Auto 
)

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

Parameters
archivePathPath to archive file (or Qt resource path :/)
patternsGlob patterns to match (e.g., "*.json", "subdir/*", "file.txt")
outputDirectoryPathOutput directory (files extracted with their archive names)
extractedFilesOptional output list of files that were extracted
formatArchive format (Auto = detect from archivePath)
Returns
true if at least one file matched and extracted, false on error or no matches

Definition at line 820 of file QGCCompression.cc.

References QGClibarchive::extractByPattern(), extractByPattern(), and validateArchiveInput().

Referenced by extractByPattern().

◆ extractFile()

bool QGCCompression::extractFile ( const QString &  archivePath,
const QString &  fileName,
const QString &  outputPath = QString(),
Format  format = Format::Auto 
)

Extract a single file from an archive to disk

Parameters
archivePathPath to archive file (or Qt resource path :/)
fileNameName of file inside archive (as shown by listArchive)
outputPathOutput file path (if empty, extracts to current directory)
formatArchive format (Auto = detect from archivePath)
Returns
true on success, false if file not found or extraction failed

Definition at line 779 of file QGCCompression.cc.

References extractFile(), QGClibarchive::extractSingleFile(), and validateArchiveInput().

Referenced by QGCCompressionJob::extractFile(), and extractFile().

◆ extractFileData()

QByteArray QGCCompression::extractFileData ( const QString &  archivePath,
const QString &  fileName,
Format  format = Format::Auto 
)

Extract a single file from an archive directly to memory

Parameters
archivePathPath to archive file (or Qt resource path :/)
fileNameName of file inside archive (as shown by listArchive)
formatArchive format (Auto = detect from archivePath)
Returns
File contents, or empty QByteArray if not found or extraction failed

Definition at line 794 of file QGCCompression.cc.

References extractFileData(), QGClibarchive::extractFileToMemory(), and validateArchiveInput().

Referenced by extractFileData().

◆ extractFileDataFromDevice()

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

Extract a single file from archive device 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 886 of file QGCCompression.cc.

References captureFormatInfo(), extractFileDataFromDevice(), QGClibarchive::extractFileDataFromDevice(), and validateDeviceInput().

Referenced by extractFileDataFromDevice().

◆ extractFiles()

bool QGCCompression::extractFiles ( const QString &  archivePath,
const QStringList &  fileNames,
const QString &  outputDirectoryPath,
Format  format = Format::Auto 
)

Extract multiple files from an archive in one pass

Parameters
archivePathPath to archive file (or Qt resource path :/)
fileNamesNames of files inside archive
outputDirectoryPathOutput directory (files extracted with their archive names)
formatArchive format (Auto = detect from archivePath)
Returns
true if all files found and extracted, false otherwise

Definition at line 807 of file QGCCompression.cc.

References extractFiles(), QGClibarchive::extractMultipleFiles(), and validateArchiveInput().

Referenced by QGCCompressionJob::extractFiles(), and extractFiles().

◆ extractFromDevice()

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

Extract archive from QIODevice to directory

Parameters
deviceQIODevice to read from (must be open and readable)
outputDirectoryPathOutput directory path
progressOptional progress callback
maxDecompressedBytesMaximum total decompressed size in bytes (0 = unlimited)
Returns
true on success, false on failure or if size limit exceeded

Definition at line 871 of file QGCCompression.cc.

References captureFormatInfo(), QGClibarchive::extractFromDevice(), extractFromDevice(), and validateDeviceInput().

Referenced by extractFromDevice().

◆ fileExists()

bool QGCCompression::fileExists ( const QString &  archivePath,
const QString &  fileName,
Format  format = Format::Auto 
)

Check if a file exists in an archive without extracting

Parameters
archivePathPath to archive file (or Qt resource path :/)
fileNameName of file to check for (as shown by listArchive)
formatArchive format (Auto = detect from archivePath)
Returns
true if file exists in archive

Definition at line 767 of file QGCCompression.cc.

References fileExists(), QGClibarchive::fileExistsInArchive(), and validateArchiveInput().

Referenced by fileExists().

◆ formatExtension()

QString QGCCompression::formatExtension ( Format  format)

Get file extension for a format.

Definition at line 435 of file QGCCompression.cc.

References formatExtension().

Referenced by decompressFile(), formatExtension(), and strippedPath().

◆ formatName()

QString QGCCompression::formatName ( Format  format)

Get human-readable name for a format.

Definition at line 470 of file QGCCompression.cc.

◆ getArchiveStats()

ArchiveStats QGCCompression::getArchiveStats ( const QString &  archivePath,
Format  format = Format::Auto 
)

Get summary statistics for an archive without extracting

Parameters
archivePathPath to archive file (or Qt resource path :/)
formatArchive format (Auto = detect from archivePath)
Returns
ArchiveStats struct (all zeros on failure)

Definition at line 750 of file QGCCompression.cc.

References QGClibarchive::getArchiveStats(), getArchiveStats(), and validateArchiveInput().

Referenced by getArchiveStats().

◆ isArchiveFile()

bool QGCCompression::isArchiveFile ( const QString &  filePath)
inline

Check if file path indicates an archive file (.zip, .tar, .tar.gz, etc.)

Definition at line 108 of file QGCCompression.h.

References detectFormat(), and isArchiveFormat().

Referenced by FTPController::browseArchive(), QGCMapEngineManager::importArchive(), and PlanMasterController::loadFromArchive().

◆ isArchiveFormat()

bool QGCCompression::isArchiveFormat ( Format  format)

Check if format is an archive (contains multiple files)

Definition at line 505 of file QGCCompression.cc.

References isArchiveFormat().

Referenced by decompressFile(), isArchiveFile(), isArchiveFormat(), and validateArchiveInput().

◆ isCompressedFile()

bool QGCCompression::isCompressedFile ( const QString &  filePath)
inline

Check if file path indicates a compressed file (.gz, .xz, .zst)

Definition at line 103 of file QGCCompression.h.

References detectFormat(), and isCompressionFormat().

Referenced by computeFileHash(), decompressIfNeeded(), and readFile().

◆ isCompressionFormat()

bool QGCCompression::isCompressionFormat ( Format  format)

Check if format is a compression format (single stream)

Definition at line 522 of file QGCCompression.cc.

References isCompressionFormat().

Referenced by decompressData(), decompressFile(), isCompressedFile(), isCompressionFormat(), looksLikeCompressedData(), and strippedPath().

◆ isDataCompressed()

bool QGCCompression::isDataCompressed ( const QByteArray &  data)

Check if data has the compressed framing header.

Definition at line 994 of file QGCCompression.cc.

References isDataCompressed(), and kHeaderCompressed.

Referenced by isDataCompressed().

◆ lastCompressionRatio()

int QGCCompression::lastCompressionRatio ( )

Compression ratio from the last compressData() call (thread-local, percentage of original size).

Definition at line 999 of file QGCCompression.cc.

References lastCompressionRatio(), and s_lastCompressionRatio.

Referenced by lastCompressionRatio().

◆ lastError()

Error QGCCompression::lastError ( )

Get the error code from the last operation (thread-local)

Definition at line 152 of file QGCCompression.cc.

References lastError().

Referenced by lastError().

◆ lastErrorString()

QString QGCCompression::lastErrorString ( )

Get a human-readable error message from the last operation (thread-local)

Definition at line 157 of file QGCCompression.cc.

References errorName(), and lastErrorString().

Referenced by lastErrorString().

◆ listArchive()

QStringList QGCCompression::listArchive ( const QString &  archivePath,
Format  format = Format::Auto 
)

List contents of an archive without extracting

Parameters
archivePathPath to archive file (or Qt resource path :/)
formatArchive format (Auto = detect from archivePath)
Returns
List of file paths in archive, empty list on failure

Definition at line 714 of file QGCCompression.cc.

References listArchive(), QGClibarchive::listArchiveEntries(), and validateArchiveInput().

Referenced by listArchive().

◆ listArchiveDetailed()

QList< ArchiveEntry > QGCCompression::listArchiveDetailed ( const QString &  archivePath,
Format  format = Format::Auto 
)

List contents of an archive with detailed metadata

Parameters
archivePathPath to archive file (or Qt resource path :/)
formatArchive format (Auto = detect from archivePath)
Returns
List of ArchiveEntry structs, empty list on failure

Definition at line 731 of file QGCCompression.cc.

References listArchiveDetailed(), QGClibarchive::listArchiveEntriesDetailed(), and validateArchiveInput().

Referenced by listArchiveDetailed().

◆ looksLikeCompressedData()

bool QGCCompression::looksLikeCompressedData ( const QByteArray &  data)

Quick check whether data begins with a recognized compression magic (gzip / xz / zstd / bzip2 / lz4). Wraps detectFormatFromData + isCompressionFormat.

Definition at line 1063 of file QGCCompression.cc.

References detectFormatFromData(), isCompressionFormat(), and looksLikeCompressedData().

Referenced by looksLikeCompressedData(), and parseCompressedJson().

◆ parseCompressedJson()

QJsonDocument QGCCompression::parseCompressedJson ( const QByteArray &  data,
QJsonParseError *  error 
)

Parse JSON from data that may be compressed. Auto-detects gzip/xz/zstd/bzip2/lz4.

Definition at line 1068 of file QGCCompression.cc.

References decompressData(), error, looksLikeCompressedData(), and parseCompressedJson().

Referenced by TerrainTileCopernicus::getJsonFromData(), JsonParsing::isJsonFile(), JsonParsing::openInternalQGCJsonFile(), and parseCompressedJson().

◆ readFile()

QByteArray QGCCompression::readFile ( const QString &  filePath,
QString *  errorString,
qint64  maxBytes 
)

◆ strippedPath()

QString QGCCompression::strippedPath ( const QString &  filePath)

Get path with compression extension stripped (.gz, .xz, .zst removed) Returns original path if not a compressed file format

Definition at line 536 of file QGCCompression.cc.

References detectFormat(), formatExtension(), isCompressionFormat(), and strippedPath().

Referenced by decompressIfNeeded(), and strippedPath().

◆ uncompress()

QByteArray QGCCompression::uncompress ( const QByteArray &  data)

Decompress data using qUncompress (expects 4-byte size header + zlib payload).

Parameters
dataCompressed data in qCompress format
Returns
Decompressed data, or empty on failure

Definition at line 917 of file QGCCompression.cc.

References uncompress().

Referenced by uncompress().

◆ uncompressData()

QByteArray QGCCompression::uncompressData ( const QByteArray &  data,
qint64  maxDecompressedSize = 64LL *1024 *1024 
)

Decompress data produced by compressData().

Parameters
dataHeader byte + payload (as produced by compressData)
maxDecompressedSizeMaximum allowed decompressed size (0 = no limit)

Definition at line 960 of file QGCCompression.cc.

References kHeaderCompressed, kHeaderUncompressed, and uncompressData().

Referenced by uncompressData().

◆ validateArchive()

bool QGCCompression::validateArchive ( const QString &  archivePath,
Format  format = Format::Auto 
)

Validate an archive's integrity without extracting

Parameters
archivePathPath to archive file
formatArchive format (Auto = detect from archivePath)
Returns
true if archive is valid and all entries can be read

Definition at line 758 of file QGCCompression.cc.

References QGClibarchive::validateArchive(), validateArchive(), and validateArchiveInput().

Referenced by validateArchive().

◆ validateArchiveInput()

static bool QGCCompression::validateArchiveInput ( const QString &  archivePath,
Format format 
)
static

◆ validateDeviceInput()

static bool QGCCompression::validateDeviceInput ( QIODevice *  device)
static

Validate device input for streaming operations.

Definition at line 246 of file QGCCompression.cc.

References validateDeviceInput().

Referenced by decompressFromDevice(), decompressFromDevice(), extractFileDataFromDevice(), extractFromDevice(), and validateDeviceInput().

◆ validateFileInput()

static bool QGCCompression::validateFileInput ( const QString &  filePath,
Format format 
)
static

Validate file input: check existence and detect format

Parameters
filePathPath to validate
formatFormat to use/detect (modified if Auto)
Returns
true if file exists and format was detected

Definition at line 210 of file QGCCompression.cc.

References detectFormat(), QGCFileHelper::exists(), and validateFileInput().

Referenced by decompressFile(), validateArchiveInput(), and validateFileInput().

Variable Documentation

◆ kDefaultFilePermissions

constexpr quint32 QGCCompression::kDefaultFilePermissions = 0644
constexpr

Default Unix permissions for extracted files (rw-r–r–)

Definition at line 28 of file QGCCompressionTypes.h.

◆ kHeaderCompressed

constexpr quint8 QGCCompression::kHeaderCompressed = 0x01
staticconstexpr

Definition at line 926 of file QGCCompression.cc.

Referenced by compressData(), isDataCompressed(), and uncompressData().

◆ kHeaderUncompressed

constexpr quint8 QGCCompression::kHeaderUncompressed = 0x00
staticconstexpr

Definition at line 925 of file QGCCompression.cc.

Referenced by compressData(), and uncompressData().

◆ s_lastCompressionRatio

thread_local int QGCCompression::s_lastCompressionRatio = 100
static

Definition at line 928 of file QGCCompression.cc.

Referenced by compressData(), and lastCompressionRatio().