MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / extractFileFromZip

Method extractFileFromZip

source/io/fszip.cpp:234–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232}
233
234bool FsZip::extractFileFromZip(BString zipFile, BString file, BString path) {
235 unzFile z = unzOpen(zipFile.c_str());
236 unz_global_info global_info = {};
237 if (!z) {
238 return false;
239 }
240 if (unzGetGlobalInfo( z, &global_info ) != UNZ_OK) {
241 unzClose( z );
242 return false;
243 }
244 for (U32 i = 0; i < global_info.number_entry; ++i) {
245 unz_file_info file_info;
246 char tmp[MAX_FILEPATH_LEN];
247
248 if ( unzGetCurrentFileInfo(z, &file_info, tmp, MAX_FILEPATH_LEN, nullptr, 0, nullptr, 0 ) != UNZ_OK ) {
249 unzClose( z );
250 return false;
251 }
252
253 if (file == tmp) {
254 unzOpenCurrentFile(z);
255 if (!Fs::doesNativePathExist(path)) {
256 Fs::makeNativeDirs(path);
257 }
258 BString outPath = path.stringByApppendingPath(Fs::getFileNameFromPath(file));
259 FILE* f = fopen(outPath.c_str(), "wb");
260 if (f) {
261 U32 totalRead = 0;
262 U8 buffer[4096] = {};
263
264 while (totalRead<file_info.uncompressed_size) {
265 U32 read = unzReadCurrentFile(z, buffer, sizeof(buffer));
266 if (!read) {
267 break;
268 }
269 totalRead += read;
270 fwrite(buffer, read, 1, f);
271 }
272 fclose(f);
273 unzCloseCurrentFile(z);
274 unzClose(z);
275 return totalRead==file_info.uncompressed_size;
276 } else {
277 unzCloseCurrentFile(z);
278 unzClose(z);
279 return false;
280 }
281 }
282 unzGoToNextFile(z);
283 }
284 unzClose(z);
285 return false;
286}
287
288bool FsZip::iterateFiles(BString zipFile, std::function<void(BString)> it) {
289 unzFile z = unzOpen(zipFile.c_str());

Callers

nothing calls this directly

Calls 10

unzOpenFunction · 0.85
unzGetGlobalInfoFunction · 0.85
unzCloseFunction · 0.85
unzGetCurrentFileInfoFunction · 0.85
unzOpenCurrentFileFunction · 0.85
unzReadCurrentFileFunction · 0.85
unzCloseCurrentFileFunction · 0.85
unzGoToNextFileFunction · 0.85
c_strMethod · 0.45

Tested by

no test coverage detected