static
| 104 | |
| 105 | // static |
| 106 | void ZipFileReader::UnzipFile(std::string const & zipContainer, std::string const & fileInZip, Delegate & delegate) |
| 107 | { |
| 108 | auto zip = unzip::Open(zipContainer); |
| 109 | if (!zip) |
| 110 | MYTHROW(OpenZipException, ("Can't get zip file handle", zipContainer)); |
| 111 | SCOPE_GUARD(zipGuard, std::bind(&unzip::Close, zip)); |
| 112 | |
| 113 | if (unzip::Code::Ok != unzip::GoToFile(zip, fileInZip)) |
| 114 | MYTHROW(LocateZipException, ("Can't locate file inside zip", fileInZip)); |
| 115 | |
| 116 | if (unzip::Code::Ok != unzip::OpenCurrentFile(zip)) |
| 117 | MYTHROW(LocateZipException, ("Can't open file inside zip", fileInZip)); |
| 118 | SCOPE_GUARD(currentFileGuard, std::bind(&unzip::CloseCurrentFile, zip)); |
| 119 | |
| 120 | unzip::FileInfo fileInfo; |
| 121 | if (unzip::Code::Ok != unzip::GetCurrentFileInfo(zip, fileInfo)) |
| 122 | MYTHROW(LocateZipException, ("Can't get uncompressed file size inside zip", fileInZip)); |
| 123 | |
| 124 | std::array<char, unzip::kFileBufferSize> buf; |
| 125 | int readBytes = 0; |
| 126 | |
| 127 | delegate.OnStarted(); |
| 128 | do |
| 129 | { |
| 130 | readBytes = unzip::ReadCurrentFile(zip, buf); |
| 131 | if (readBytes < 0) |
| 132 | MYTHROW(InvalidZipException, ("Error", readBytes, "while unzipping", fileInZip, "from", zipContainer)); |
| 133 | |
| 134 | delegate.OnBlockUnzipped(static_cast<size_t>(readBytes), buf.data()); |
| 135 | } |
| 136 | while (readBytes != 0); |
| 137 | delegate.OnCompleted(); |
| 138 | } |
| 139 | |
| 140 | // static |
| 141 | void ZipFileReader::UnzipFile(std::string const & zipContainer, std::string const & fileInZip, |
nothing calls this directly
no test coverage detected