| 256 | // [tom, 1/23/2007] Maybe. |
| 257 | |
| 258 | bool EndOfCentralDir::findInStream(Stream *stream) |
| 259 | { |
| 260 | U32 initialPos = stream->getPosition(); |
| 261 | U32 size = stream->getStreamSize(); |
| 262 | U32 pos; |
| 263 | if(size == 0) |
| 264 | return false; |
| 265 | |
| 266 | if(! stream->setPosition(size - mRecordSize)) |
| 267 | goto hell; |
| 268 | |
| 269 | U32 sig; |
| 270 | stream->read(&sig); |
| 271 | |
| 272 | if(sig == mEOCDSignature) |
| 273 | { |
| 274 | stream->setPosition(size - mRecordSize); |
| 275 | return true; |
| 276 | } |
| 277 | |
| 278 | // OK, so we couldn't find the EOCD where we expected it. The zip file |
| 279 | // either has comments or isn't a zip file. We need to search the last |
| 280 | // 64Kb of the file for the EOCD. |
| 281 | |
| 282 | pos = size > mEOCDSearchSize ? size - mEOCDSearchSize : 0; |
| 283 | if(! stream->setPosition(pos)) |
| 284 | goto hell; |
| 285 | |
| 286 | while(pos < (size - 4)) |
| 287 | { |
| 288 | stream->read(&sig); |
| 289 | |
| 290 | if(sig == mEOCDSignature) |
| 291 | { |
| 292 | stream->setPosition(pos); |
| 293 | return true; |
| 294 | } |
| 295 | |
| 296 | pos++; |
| 297 | if(! stream->setPosition(pos)) |
| 298 | goto hell; |
| 299 | } |
| 300 | |
| 301 | hell: |
| 302 | stream->setPosition(initialPos); |
| 303 | return false; |
| 304 | } |
| 305 | |
| 306 | //----------------------------------------------------------------------------- |
| 307 |
no test coverage detected