| 253 | } |
| 254 | |
| 255 | bool ZipFile::getFileDataByChunks(const std::string& fileName, const std::function<bool(unsigned char*, int)>& handler) { |
| 256 | BLOCK_START { |
| 257 | BREAK_IF(!_file); |
| 258 | BREAK_IF(fileName.empty()); |
| 259 | auto archive = &_file->archive; |
| 260 | std::string searchName = getSearchName(fileName); |
| 261 | auto it = _file->fileList.find(searchName); |
| 262 | BREAK_IF(it == _file->fileList.end()); |
| 263 | auto zipIter = mz_zip_reader_extract_file_iter_new(archive, it->second.name.c_str(), 0); |
| 264 | uint8_t buf[DORA_COPY_BUFFER_SIZE]; |
| 265 | size_t nSize = 0, total = 0; |
| 266 | do { |
| 267 | nSize = mz_zip_reader_extract_iter_read(zipIter, buf, DORA_COPY_BUFFER_SIZE); |
| 268 | if (nSize > 0) { |
| 269 | if (handler(buf, nSize)) { |
| 270 | return false; |
| 271 | } |
| 272 | } |
| 273 | total += nSize; |
| 274 | } while (nSize != 0); |
| 275 | mz_zip_reader_extract_iter_free(zipIter); |
| 276 | if (total == 0 || total == (int)it->second.size) { |
| 277 | return true; |
| 278 | } else { |
| 279 | Error("ZipUtils: the file size is wrong: \"{}\".", fileName); |
| 280 | return false; |
| 281 | } |
| 282 | } |
| 283 | BLOCK_END |
| 284 | return false; |
| 285 | } |
no test coverage detected