mirror of
https://github.com/wassname/segpy.git
synced 2026-07-08 01:54:50 +08:00
25 lines
545 B
Python
25 lines
545 B
Python
import os
|
|
from util import file_length
|
|
|
|
|
|
def seekable(fh):
|
|
"""Determine whether a file-like object supports seeking.
|
|
|
|
Args:
|
|
fh: The file-like-object to be tested.
|
|
|
|
Returns:
|
|
True if the file supports seeking, otherwise False.
|
|
"""
|
|
try:
|
|
return fh.seekable()
|
|
except AttributeError:
|
|
try:
|
|
pos = fh.tell()
|
|
try:
|
|
fh.seek(0, os.SEEK_END)
|
|
finally:
|
|
fh.seek(pos)
|
|
except AttributeError:
|
|
return False
|
|
return True |