QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCCompression.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <QtCore/QByteArray>
6#include <QtCore/QIODevice>
7#include <QtCore/QString>
8#include <QtCore/QStringList>
9
13namespace QGCCompression {
14
15// ============================================================================
16// Error Handling
17// ============================================================================
18
32
35
37QString lastErrorString();
38
40QString errorName(Error error);
41
42// ============================================================================
43// Format Definitions
44// ============================================================================
45
47enum class Format {
48 Auto,
49 ZIP,
50 SEVENZ,
51 GZIP,
52 XZ,
53 ZSTD,
54 BZIP2,
55 LZ4,
56 TAR,
57 TAR_GZ,
58 TAR_XZ,
59 TAR_ZSTD,
60 TAR_BZ2,
61 TAR_LZ4,
62};
63
64// ============================================================================
65// Format Detection
66// ============================================================================
67
74Format detectFormat(const QString &filePath, bool useContentFallback = true);
75
80Format detectFormatFromFile(const QString &filePath);
81
85Format detectFormatFromData(const QByteArray &data);
86
88QString formatExtension(Format format);
89
91QString formatName(Format format);
92
94bool isArchiveFormat(Format format);
95
97bool isCompressionFormat(Format format);
98
100inline bool isCompressedFile(const QString &filePath) {
101 return isCompressionFormat(detectFormat(filePath));
102}
103
105inline bool isArchiveFile(const QString &filePath) {
106 return isArchiveFormat(detectFormat(filePath));
107}
108
111QString strippedPath(const QString &filePath);
112
116QString detectedFormatName();
117
121QString detectedFilterName();
122
123// ============================================================================
124// Single-File Decompression
125// ============================================================================
126
134bool decompressFile(const QString &inputPath, const QString &outputPath = QString(),
135 Format format = Format::Auto,
136 ProgressCallback progress = nullptr,
137 qint64 maxDecompressedBytes = 0);
138
144QString decompressIfNeeded(const QString &filePath,
145 const QString &outputPath = QString(),
146 bool removeOriginal = false);
147
153QByteArray decompressData(const QByteArray &data, Format format = Format::Auto,
154 qint64 maxDecompressedBytes = 0);
155
156// ============================================================================
157// Archive Extraction (Multiple Files)
158// ============================================================================
159
167bool extractArchive(const QString &archivePath, const QString &outputDirectoryPath,
168 Format format = Format::Auto,
169 ProgressCallback progress = nullptr,
170 qint64 maxDecompressedBytes = 0);
171
181bool extractArchiveAtomic(const QString &archivePath, const QString &outputDirectoryPath,
182 Format format = Format::Auto,
183 ProgressCallback progress = nullptr,
184 qint64 maxDecompressedBytes = 0);
185
193bool extractArchiveFiltered(const QString &archivePath, const QString &outputDirectoryPath,
194 EntryFilter filter,
195 ProgressCallback progress = nullptr,
196 qint64 maxDecompressedBytes = 0);
197
202QStringList listArchive(const QString &archivePath, Format format = Format::Auto);
203
208QList<ArchiveEntry> listArchiveDetailed(const QString &archivePath, Format format = Format::Auto);
209
214ArchiveStats getArchiveStats(const QString &archivePath, Format format = Format::Auto);
215
220bool validateArchive(const QString &archivePath, Format format = Format::Auto);
221
227bool fileExists(const QString &archivePath, const QString &fileName,
228 Format format = Format::Auto);
229
236bool extractFile(const QString &archivePath, const QString &fileName,
237 const QString &outputPath = QString(),
238 Format format = Format::Auto);
239
245QByteArray extractFileData(const QString &archivePath, const QString &fileName,
246 Format format = Format::Auto);
247
254bool extractFiles(const QString &archivePath, const QStringList &fileNames,
255 const QString &outputDirectoryPath,
256 Format format = Format::Auto);
257
266bool extractByPattern(const QString &archivePath, const QStringList &patterns,
267 const QString &outputDirectoryPath,
268 QStringList *extractedFiles = nullptr,
269 Format format = Format::Auto);
270
271// ============================================================================
272// QIODevice-based Operations (streaming)
273// ============================================================================
274
282bool decompressFromDevice(QIODevice *device, const QString &outputPath,
283 ProgressCallback progress = nullptr,
284 qint64 maxDecompressedBytes = 0);
285
290QByteArray decompressFromDevice(QIODevice *device, qint64 maxDecompressedBytes = 0);
291
298bool extractFromDevice(QIODevice *device, const QString &outputDirectoryPath,
299 ProgressCallback progress = nullptr,
300 qint64 maxDecompressedBytes = 0);
301
306QByteArray extractFileDataFromDevice(QIODevice *device, const QString &fileName);
307
308} // namespace QGCCompression
Shared type definitions for compression/archive operations.
QString formatName
Error error
std::function< void(int)> ProgressCallback
bool isCompressionFormat(Format format)
Check if format is a compression format (single stream)
bool fileExists(const QString &archivePath, const QString &fileName, Format format)
QByteArray decompressData(const QByteArray &data, Format format, qint64 maxDecompressedBytes)
bool extractArchiveAtomic(const QString &archivePath, const QString &outputDirectoryPath, Format format, ProgressCallback progress, qint64 maxDecompressedBytes)
bool extractArchive(const QString &archivePath, const QString &outputDirectoryPath, Format format, ProgressCallback progress, qint64 maxDecompressedBytes)
bool decompressFile(const QString &inputPath, const QString &outputPath, Format format, ProgressCallback progress, qint64 maxDecompressedBytes)
bool isArchiveFile(const QString &filePath)
Check if file path indicates an archive file (.zip, .tar, .tar.gz, etc.)
std::function< bool(const ArchiveEntry &entry)> EntryFilter
QStringList listArchive(const QString &archivePath, Format format)
bool extractArchiveFiltered(const QString &archivePath, const QString &outputDirectoryPath, EntryFilter filter, ProgressCallback progress, qint64 maxDecompressedBytes)
bool isArchiveFormat(Format format)
Check if format is an archive (contains multiple files)
bool extractByPattern(const QString &archivePath, const QStringList &patterns, const QString &outputDirectoryPath, QStringList *extractedFiles, Format format)
Format detectFormatFromData(const QByteArray &data)
QString lastErrorString()
Get a human-readable error message from the last operation (thread-local)
QString strippedPath(const QString &filePath)
QString detectedFilterName()
bool isCompressedFile(const QString &filePath)
Check if file path indicates a compressed file (.gz, .xz, .zst)
QString errorName(Error error)
Get a human-readable name for an error code.
bool decompressFromDevice(QIODevice *device, const QString &outputPath, ProgressCallback progress, qint64 maxDecompressedBytes)
Format
Archive and compression format types (for decompression)
@ Auto
Auto-detect from file extension or magic bytes.
@ TAR_ZSTD
TAR + Zstandard (.tar.zst)
@ TAR_BZ2
TAR + BZip2 (.tar.bz2, .tbz2)
@ XZ
XZ/LZMA compression (single file, .xz)
@ ZIP
ZIP archive (multiple files)
@ TAR_XZ
TAR + XZ (.tar.xz, .txz)
@ SEVENZ
7-Zip archive (.7z)
@ TAR_LZ4
TAR + LZ4 (.tar.lz4)
@ BZIP2
BZip2 compression (single file, .bz2)
@ ZSTD
Zstandard compression (single file, .zst)
@ TAR_GZ
TAR + GZIP (.tar.gz, .tgz)
@ LZ4
LZ4 compression (single file, .lz4)
@ TAR
TAR archive (uncompressed, multiple files)
@ GZIP
GZIP compression (single file, .gz)
QByteArray extractFileData(const QString &archivePath, const QString &fileName, Format format)
ArchiveStats getArchiveStats(const QString &archivePath, Format format)
QList< ArchiveEntry > listArchiveDetailed(const QString &archivePath, Format format)
Error
Error codes for decompression operations.
@ FileNotFound
Input file does not exist.
@ FileNotInArchive
Requested file not found in archive.
@ PermissionDenied
Cannot read input or write output.
@ InvalidArchive
Archive is corrupt or invalid.
@ None
No error (success)
@ InternalError
Unexpected internal error.
@ Cancelled
Operation cancelled by progress callback.
@ SizeLimitExceeded
Decompressed size exceeded limit.
@ UnsupportedFormat
Format not recognized or not supported.
@ IoError
General I/O error (read/write failure)
bool validateArchive(const QString &archivePath, Format format)
bool extractFile(const QString &archivePath, const QString &fileName, const QString &outputPath, Format format)
Error lastError()
Get the error code from the last operation (thread-local)
bool extractFromDevice(QIODevice *device, const QString &outputDirectoryPath, ProgressCallback progress, qint64 maxDecompressedBytes)
QByteArray extractFileDataFromDevice(QIODevice *device, const QString &fileName)
bool extractFiles(const QString &archivePath, const QStringList &fileNames, const QString &outputDirectoryPath, Format format)
QString detectedFormatName()
QString decompressIfNeeded(const QString &filePath, const QString &outputPath, bool removeOriginal)
QString formatExtension(Format format)
Get file extension for a format.
Format detectFormatFromFile(const QString &filePath)
Format detectFormat(const QString &filePath, bool useContentFallback)