Return True if name points to a tar archive that we are able to handle, else return False. 'name' should be a string, file, or file-like object.
(name)
| 3014 | #-------------------- |
| 3015 | |
| 3016 | def is_tarfile(name): |
| 3017 | """Return True if name points to a tar archive that we |
| 3018 | are able to handle, else return False. |
| 3019 | |
| 3020 | 'name' should be a string, file, or file-like object. |
| 3021 | """ |
| 3022 | try: |
| 3023 | if hasattr(name, "read"): |
| 3024 | pos = name.tell() |
| 3025 | t = open(fileobj=name) |
| 3026 | name.seek(pos) |
| 3027 | else: |
| 3028 | t = open(name) |
| 3029 | t.close() |
| 3030 | return True |
| 3031 | except TarError: |
| 3032 | return False |
| 3033 | |
| 3034 | open = TarFile.open |
| 3035 |