MCPcopy Create free account
hub / github.com/comaps/comaps / UnzipFile

Method UnzipFile

libs/coding/zip_reader.cpp:106–138  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

104
105// static
106void 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
141void ZipFileReader::UnzipFile(std::string const & zipContainer, std::string const & fileInZip,

Callers

nothing calls this directly

Calls 9

OpenFunction · 0.85
GoToFileFunction · 0.85
OpenCurrentFileFunction · 0.85
GetCurrentFileInfoFunction · 0.85
ReadCurrentFileFunction · 0.85
OnStartedMethod · 0.45
OnBlockUnzippedMethod · 0.45
dataMethod · 0.45
OnCompletedMethod · 0.45

Tested by

no test coverage detected