(fp)
| 233 | |
| 234 | |
| 235 | def _check_zipfile(fp): |
| 236 | try: |
| 237 | endrec = _EndRecData(fp) |
| 238 | if endrec: |
| 239 | if endrec[_ECD_ENTRIES_TOTAL] == 0 and endrec[_ECD_SIZE] == 0 and endrec[_ECD_OFFSET] == 0: |
| 240 | return True # Empty zipfiles are still zipfiles |
| 241 | elif endrec[_ECD_DISK_NUMBER] == endrec[_ECD_DISK_START]: |
| 242 | # Central directory is on the same disk |
| 243 | fp.seek(sum(_handle_prepended_data(endrec))) |
| 244 | if endrec[_ECD_SIZE] >= sizeCentralDir: |
| 245 | data = fp.read(sizeCentralDir) # CD is where we expect it to be |
| 246 | if len(data) == sizeCentralDir: |
| 247 | centdir = struct.unpack(structCentralDir, data) # CD is the right size |
| 248 | if centdir[_CD_SIGNATURE] == stringCentralDir: |
| 249 | return True # First central directory entry has correct magic number |
| 250 | except OSError: |
| 251 | pass |
| 252 | return False |
| 253 | |
| 254 | def is_zipfile(filename): |
| 255 | """Quickly see if a file is a ZIP file by checking the magic number. |
no test coverage detected
searching dependent graphs…