7#include <archive_entry.h>
26 , _sourceDevice(source)
59 return _buffer.size() + QIODevice::bytesAvailable();
67 return QIODevice::errorString();
95 const qint64 bytesToCopy = qMin(
static_cast<qint64
>(
_buffer.size()), maxSize);
96 if (bytesToCopy > 0) {
97 std::memcpy(data,
_buffer.constData(),
static_cast<size_t>(bytesToCopy));
98 _buffer.remove(0,
static_cast<int>(bytesToCopy));
125 if (!resourceFile.open(QIODevice::ReadOnly)) {
130 resourceFile.close();
133 auto buffer = std::make_unique<QBuffer>();
135 if (!buffer->open(QIODevice::ReadOnly)) {
136 _errorString = QStringLiteral(
"Failed to open buffer for resource");
142 auto file = std::make_unique<QFile>(
_filePath);
143 if (!file->open(QIODevice::ReadOnly)) {
160 archive_read_support_filter_all(
_archive);
163 archive_read_support_format_all(
_archive);
165 archive_read_support_format_raw(
_archive);
172 _errorString = QStringLiteral(
"Source device is not ready");
187 if (result != ARCHIVE_OK) {
204 const la_ssize_t bytesRead = archive_read_data(
_archive, readBuffer,
sizeof(readBuffer));
208 qCWarning(QGCArchiveDeviceBaseLog) <<
"Read error:" <<
_errorString;
212 if (bytesRead == 0) {
217 _buffer.append(readBuffer,
static_cast<int>(bytesRead));
227 const char *fmt = archive_format_name(
_archive);
228 _formatName = fmt ? QString::fromUtf8(fmt) : QString();
230 const char *flt = archive_filter_name(
_archive, 0);
231 _filterName = flt ? QString::fromUtf8(flt) : QStringLiteral(
"none");
Base class for QIODevice wrappers using libarchive.
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Private implementation details for QGCCompression.
~QGCArchiveDeviceBase() override
void captureFormatInfo()
Capture format info from the archive after first header read.
virtual bool isReadyToRead() const =0
qint64 readData(char *data, qint64 maxSize) override
QIODevice * _sourceDevice
std::unique_ptr< QIODevice > _ownedSource
QGCArchiveDeviceBase(const QString &filePath, QObject *parent=nullptr)
struct archive * _archive
void configureArchiveFormats(bool allFormats)
QString errorString() const
virtual void resetState()
Reset all state (called by close())
qint64 writeData(const char *data, qint64 maxSize) override
bool initSourceFromPath()
qint64 bytesAvailable() const override
bool isQtResource(const QString &path)
constexpr size_t kBufferSizeMax
Maximum buffer size for I/O operations.
la_int64_t deviceSkipCallback(struct archive *, void *clientData, la_int64_t request)
la_ssize_t deviceReadCallback(struct archive *, void *clientData, const void **buffer)
la_int64_t deviceSeekCallback(struct archive *, void *clientData, la_int64_t offset, int whence)
int deviceCloseCallback(struct archive *, void *)