| 118 | |
| 119 | |
| 120 | datablock zip_archive::uncompress_data(entry const &p_entry) |
| 121 | { |
| 122 | datablock uncompressed_data(p_entry.m_uncompressed_size); |
| 123 | |
| 124 | if (p_entry.m_offset_to_data == 0) |
| 125 | { |
| 126 | uint16_t local_filename_len, local_extra_field_len; |
| 127 | |
| 128 | // go to local header, and skip signature, required version, bit flag, compression |
| 129 | // method, last mod time & date, crc32, compressed & uncompressed size (all of this |
| 130 | // data is already present in the central directory) |
| 131 | m_input.seekg(p_entry.m_offset_to_local_header + 4 + 5*2 + 3*4, std::ios::beg); |
| 132 | |
| 133 | // skip local filename and extra fields |
| 134 | read_binary(m_input, local_filename_len); |
| 135 | read_binary(m_input, local_extra_field_len); |
| 136 | m_input.seekg(local_filename_len + local_extra_field_len, std::ios::cur); |
| 137 | |
| 138 | p_entry.m_offset_to_data = m_input.tellg(); |
| 139 | } |
| 140 | else |
| 141 | m_input.seekg(p_entry.m_offset_to_data, std::ios::beg); |
| 142 | |
| 143 | switch (p_entry.m_compression_method) |
| 144 | { |
| 145 | case 0: // no compression |
| 146 | { |
| 147 | m_input.read(reinterpret_cast < char* > (&uncompressed_data[0]), uncompressed_data.size()); |
| 148 | break; |
| 149 | } |
| 150 | |
| 151 | case 8: // deflate compression |
| 152 | { |
| 153 | datablock compressed_data(p_entry.m_compressed_size); |
| 154 | m_input.read(reinterpret_cast < char* > (&compressed_data[0]), compressed_data.size()); |
| 155 | |
| 156 | if (!inflate_data(compressed_data, uncompressed_data)) |
| 157 | { |
| 158 | LOG_MSG(error, "could not decompress data - returning empty datablock"); |
| 159 | return datablock(); |
| 160 | } |
| 161 | |
| 162 | break; |
| 163 | }; |
| 164 | |
| 165 | default: |
| 166 | // should not happen - compression methods other than 0 or 8 are filtered earlier |
| 167 | assert(0); |
| 168 | } |
| 169 | |
| 170 | return uncompressed_data; |
| 171 | } |
| 172 | |
| 173 | |
| 174 | void zip_archive::read_central_directory() |
no test coverage detected