Quickly see if a file is a ZIP file by checking the magic number. The filename argument may be a file or file-like object too.
(filename)
| 252 | return False |
| 253 | |
| 254 | def is_zipfile(filename): |
| 255 | """Quickly see if a file is a ZIP file by checking the magic number. |
| 256 | |
| 257 | The filename argument may be a file or file-like object too. |
| 258 | """ |
| 259 | result = False |
| 260 | try: |
| 261 | if hasattr(filename, "read"): |
| 262 | pos = filename.tell() |
| 263 | result = _check_zipfile(fp=filename) |
| 264 | filename.seek(pos) |
| 265 | else: |
| 266 | with open(filename, "rb") as fp: |
| 267 | result = _check_zipfile(fp) |
| 268 | except (OSError, BadZipFile): |
| 269 | pass |
| 270 | return result |
| 271 | |
| 272 | def _handle_prepended_data(endrec, debug=0): |
| 273 | size_cd = endrec[_ECD_SIZE] # bytes in central directory |
nothing calls this directly
no test coverage detected
searching dependent graphs…