2025-12-03 22:00:29 +11:00
|
|
|
#pragma once
|
2025-12-19 21:29:25 +01:00
|
|
|
#include <HardwareSerial.h>
|
2025-12-08 00:39:17 +11:00
|
|
|
#include <Print.h>
|
|
|
|
|
|
2025-12-19 21:29:25 +01:00
|
|
|
#include <cstddef>
|
2025-12-08 00:39:17 +11:00
|
|
|
#include <functional>
|
2025-12-03 22:00:29 +11:00
|
|
|
#include <string>
|
|
|
|
|
|
2025-12-08 00:39:17 +11:00
|
|
|
#include "miniz.h"
|
|
|
|
|
|
2025-12-03 22:00:29 +11:00
|
|
|
class ZipFile {
|
|
|
|
|
std::string filePath;
|
2025-12-19 21:29:25 +01:00
|
|
|
mutable mz_zip_archive zipArchive = {};
|
2025-12-08 00:39:17 +11:00
|
|
|
bool loadFileStat(const char* filename, mz_zip_archive_file_stat* fileStat) const;
|
|
|
|
|
long getDataOffset(const mz_zip_archive_file_stat& fileStat) const;
|
2025-12-03 22:00:29 +11:00
|
|
|
|
|
|
|
|
public:
|
2025-12-19 21:29:25 +01:00
|
|
|
explicit ZipFile(std::string filePath) : filePath(std::move(filePath)) {
|
|
|
|
|
const bool status = mz_zip_reader_init_file(&zipArchive, this->filePath.c_str(), 0);
|
|
|
|
|
|
|
|
|
|
if (!status) {
|
|
|
|
|
Serial.printf("[%lu] [ZIP] mz_zip_reader_init_file() failed for %s! Error: %s\n", millis(),
|
|
|
|
|
this->filePath.c_str(), mz_zip_get_error_string(zipArchive.m_last_error));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
~ZipFile() { mz_zip_reader_end(&zipArchive); }
|
2025-12-13 19:36:01 +11:00
|
|
|
bool getInflatedFileSize(const char* filename, size_t* size) const;
|
2025-12-03 22:00:29 +11:00
|
|
|
uint8_t* readFileToMemory(const char* filename, size_t* size = nullptr, bool trailingNullByte = false) const;
|
2025-12-08 00:39:17 +11:00
|
|
|
bool readFileToStream(const char* filename, Print& out, size_t chunkSize) const;
|
2025-12-03 22:00:29 +11:00
|
|
|
};
|