| 220 | class MappedZipArchive { |
| 221 | public: |
| 222 | explicit MappedZipArchive(const std::string& path) : fileName(path) { |
| 223 | if (!GetFileFreshnessCacheKey(path, &cacheKey)) { |
| 224 | throw FileNotFound(path); |
| 225 | } |
| 226 | #if defined(_WIN32) || defined(_WIN64) |
| 227 | buffer = ReadBinaryFile(path); |
| 228 | data = buffer.empty() ? nullptr : buffer.data(); |
| 229 | size = buffer.size(); |
| 230 | #else |
| 231 | fd = open(path.c_str(), O_RDONLY); |
| 232 | if (fd < 0) { |
| 233 | throw FileNotFound(path); |
| 234 | } |
| 235 | struct stat info; |
| 236 | if (fstat(fd, &info) != 0 || info.st_size < 0) { |
| 237 | close(fd); |
| 238 | fd = -1; |
| 239 | throw FileNotFound(path); |
| 240 | } |
| 241 | size = static_cast<size_t>(info.st_size); |
| 242 | if (size == 0) { |
| 243 | close(fd); |
| 244 | fd = -1; |
| 245 | data = nullptr; |
| 246 | return; |
| 247 | } |
| 248 | void* mapped = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0); |
| 249 | if (mapped == MAP_FAILED) { |
| 250 | close(fd); |
| 251 | fd = -1; |
| 252 | throw FileNotFound(path); |
| 253 | } |
| 254 | data = static_cast<const unsigned char*>(mapped); |
| 255 | #endif |
| 256 | } |
| 257 | |
| 258 | MappedZipArchive(const MappedZipArchive&) = delete; |
| 259 | MappedZipArchive& operator=(const MappedZipArchive&) = delete; |
nothing calls this directly
no test coverage detected