MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / getDataOffset

Method getDataOffset

lib/ZipFile/ZipFile.cpp:190–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

188}
189
190long ZipFile::getDataOffset(const FileStatSlim& fileStat) {
191 const ScopedOpenClose zip{*this};
192 if (!zip) return -1;
193
194 constexpr auto localHeaderSize = 30;
195
196 uint8_t pLocalHeader[localHeaderSize];
197 const uint64_t fileOffset = fileStat.localHeaderOffset;
198
199 file.seek(fileOffset);
200 const size_t read = file.read(pLocalHeader, localHeaderSize);
201
202 if (read != localHeaderSize) {
203 LOG_ERR("ZIP", "Something went wrong reading the local header");
204 return -1;
205 }
206
207 if (pLocalHeader[0] + (pLocalHeader[1] << 8) + (pLocalHeader[2] << 16) + (pLocalHeader[3] << 24) !=
208 0x04034b50 /* ZIP local file header signature */) {
209 LOG_ERR("ZIP", "Not a valid zip file header");
210 return -1;
211 }
212
213 const uint16_t filenameLength = pLocalHeader[26] + (pLocalHeader[27] << 8);
214 const uint16_t extraOffset = pLocalHeader[28] + (pLocalHeader[29] << 8);
215 return fileOffset + localHeaderSize + filenameLength + extraOffset;
216}
217
218bool ZipFile::loadZipDetails() {
219 if (zipDetails.isSet) {

Callers

nothing calls this directly

Calls 2

seekMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected