This repository was archived by the owner on Dec 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 328
Expand file tree
/
Copy pathZipReader.cpp
More file actions
66 lines (55 loc) · 1.39 KB
/
ZipReader.cpp
File metadata and controls
66 lines (55 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "stdafx.h"
#include <string.h>
#include <sstream>
#include "ZipReader.h"
ZipReader::ZipReader()
{
memset(&_zipArchive, 0, sizeof(mz_zip_archive));
}
ZipReader::~ZipReader()
{
if(_initialized) {
mz_zip_reader_end(&_zipArchive);
}
}
bool ZipReader::InternalLoadArchive(void* buffer, size_t size)
{
if(_initialized) {
mz_zip_reader_end(&_zipArchive);
memset(&_zipArchive, 0, sizeof(mz_zip_archive));
_initialized = false;
}
return mz_zip_reader_init_mem(&_zipArchive, buffer, size, 0) != 0;
}
vector<string> ZipReader::InternalGetFileList()
{
vector<string> fileList;
if(_initialized) {
for(int i = 0, len = (int)mz_zip_reader_get_num_files(&_zipArchive); i < len; i++) {
mz_zip_archive_file_stat file_stat;
if(!mz_zip_reader_file_stat(&_zipArchive, i, &file_stat)) {
std::cout << "mz_zip_reader_file_stat() failed!" << std::endl;
}
fileList.push_back(file_stat.m_filename);
}
}
return fileList;
}
bool ZipReader::ExtractFile(string filename, vector<uint8_t> &output)
{
if(_initialized) {
size_t uncompSize;
void *p = mz_zip_reader_extract_file_to_heap(&_zipArchive, filename.c_str(), &uncompSize, 0);
if(!p) {
#ifdef _DEBUG
std::cout << "mz_zip_reader_extract_file_to_heap() failed!" << std::endl;
#endif
return false;
}
output = vector<uint8_t>((uint8_t*)p, (uint8_t*)p + uncompSize);
// We're done.
mz_free(p);
return true;
}
return false;
}