| 175 | } |
| 176 | |
| 177 | static cc_result ZipWriter_FixupLocalFile(struct Stream* s, struct ResourceZipEntry* e) { |
| 178 | int filenameLen = String_Length(e->filename); |
| 179 | cc_uint8 tmp[2048]; |
| 180 | cc_uint32 dataBeg, dataEnd; |
| 181 | cc_uint32 i, crc, toRead, read; |
| 182 | cc_result res; |
| 183 | |
| 184 | dataBeg = e->offset + 30 + filenameLen; |
| 185 | if ((res = s->Position(s, &dataEnd))) return res; |
| 186 | e->size = dataEnd - dataBeg; |
| 187 | |
| 188 | /* work out the CRC 32 */ |
| 189 | crc = 0xffffffffUL; |
| 190 | if ((res = s->Seek(s, dataBeg))) return res; |
| 191 | |
| 192 | for (; dataBeg < dataEnd; dataBeg += read) { |
| 193 | toRead = dataEnd - dataBeg; |
| 194 | toRead = min(toRead, sizeof(tmp)); |
| 195 | |
| 196 | if ((res = s->Read(s, tmp, toRead, &read))) return res; |
| 197 | if (!read) return ERR_END_OF_STREAM; |
| 198 | |
| 199 | for (i = 0; i < read; i++) { |
| 200 | crc = Utils_Crc32Table[(crc ^ tmp[i]) & 0xFF] ^ (crc >> 8); |
| 201 | } |
| 202 | } |
| 203 | e->crc32 = crc ^ 0xffffffffUL; |
| 204 | |
| 205 | /* then fixup the header */ |
| 206 | if ((res = s->Seek(s, e->offset))) return res; |
| 207 | if ((res = ZipWriter_LocalFile(s, e))) return res; |
| 208 | return s->Seek(s, dataEnd); |
| 209 | } |
| 210 | |
| 211 | static cc_result ZipWriter_WriteData(struct Stream* dst, struct ResourceZipEntry* e) { |
| 212 | cc_uint8* data = e->value.data; |
no test coverage detected