| 1048 | } |
| 1049 | |
| 1050 | int32_t ExtractToWriter(ZipArchiveHandle handle, ZipEntry* entry, zip_archive_lkchan::Writer* writer) { |
| 1051 | ZipArchive* archive = reinterpret_cast<ZipArchive*>(handle); |
| 1052 | const uint16_t method = entry->method; |
| 1053 | |
| 1054 | // this should default to kUnknownCompressionMethod. |
| 1055 | int32_t return_value = -1; |
| 1056 | uint64_t crc = 0; |
| 1057 | if (method == kCompressStored) { |
| 1058 | return_value = CopyEntryToWriter(archive->mapped_zip, entry, writer, &crc); |
| 1059 | } else if (method == kCompressDeflated) { |
| 1060 | return_value = InflateEntryToWriter(archive->mapped_zip, entry, writer, &crc); |
| 1061 | } |
| 1062 | |
| 1063 | if (!return_value && entry->has_data_descriptor) { |
| 1064 | return_value = ValidateDataDescriptor(archive->mapped_zip, entry); |
| 1065 | if (return_value) { |
| 1066 | return return_value; |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | // Validate that the CRC matches the calculated value. |
| 1071 | if (kCrcChecksEnabled && (entry->crc32 != static_cast<uint32_t>(crc))) { |
| 1072 | //chensenhua ALOGW("Zip: crc mismatch: expected %" PRIu32 ", was %" PRIu64, entry->crc32, crc); |
| 1073 | return kInconsistentInformation; |
| 1074 | } |
| 1075 | |
| 1076 | return return_value; |
| 1077 | } |
| 1078 | |
| 1079 | int32_t ExtractToMemory(ZipArchiveHandle handle, ZipEntry* entry, uint8_t* begin, uint32_t size) { |
| 1080 | MemoryWriter writer(begin, size); |
no test coverage detected