Files
asteria-qt/src/backend/ZipUtils.h
T
2026-03-29 20:49:45 +02:00

28 lines
667 B
C++

#pragma once
#include <QByteArray>
#include <minizip/unzip.h>
namespace ZipUtils {
// Read a single file from an open unzFile handle by name.
// Returns empty QByteArray on failure.
inline QByteArray readZipEntry(unzFile zf, const char *entryName)
{
if (unzLocateFile(zf, entryName, 0) != UNZ_OK)
return {};
if (unzOpenCurrentFile(zf) != UNZ_OK)
return {};
QByteArray result;
char buf[4096];
int bytesRead;
while ((bytesRead = unzReadCurrentFile(zf, buf, sizeof(buf))) > 0)
result.append(buf, bytesRead);
unzCloseCurrentFile(zf);
return (bytesRead == 0) ? result : QByteArray{};
}
} // namespace ZipUtils