@@ -91,10 +91,10 @@ def is_correct_format(cls, fileobj):
91
91
otherwise returns False.
92
92
"""
93
93
with Opener (fileobj ) as f :
94
- magic_number = asstr ( f . fobj . read (len (cls .MAGIC_NUMBER ) ))
94
+ magic_number = f . read (len (cls .MAGIC_NUMBER ))
95
95
f .seek (- len (cls .MAGIC_NUMBER ), os .SEEK_CUR )
96
96
97
- return magic_number . strip ( ) == cls .MAGIC_NUMBER
97
+ return asstr ( magic_number ) == cls .MAGIC_NUMBER
98
98
99
99
@classmethod
100
100
def create_empty_header (cls ):
@@ -312,25 +312,25 @@ def _read_header(cls, fileobj):
312
312
with Opener (fileobj ) as f :
313
313
314
314
# Record start position
315
- start_position = f .fobj . tell ()
315
+ start_position = f .tell ()
316
316
317
317
# Make sure we are at the beginning of the file
318
- f .fobj . seek (0 , os .SEEK_SET )
318
+ f .seek (0 , os .SEEK_SET )
319
319
320
320
# Read magic number
321
- magic_number = asstr ( f . fobj . read (len (cls .MAGIC_NUMBER ) ))
321
+ magic_number = f . read (len (cls .MAGIC_NUMBER ))
322
322
323
- if magic_number != cls .MAGIC_NUMBER :
323
+ if asstr ( magic_number ) != cls .MAGIC_NUMBER :
324
324
raise HeaderError (f"Invalid magic number: { magic_number } " )
325
325
326
326
hdr [Field .MAGIC_NUMBER ] = magic_number
327
327
328
- f .fobj . seek (1 , os .SEEK_CUR ) # Skip \n
328
+ f .seek (1 , os .SEEK_CUR ) # Skip \n
329
329
330
330
found_end = False
331
331
332
332
# Read all key-value pairs contained in the header, stop at EOF
333
- for n_line , line in enumerate (f . fobj , 1 ):
333
+ for n_line , line in enumerate (f , 1 ):
334
334
line = asstr (line ).strip ()
335
335
336
336
if not line : # Skip empty lines
@@ -353,7 +353,7 @@ def _read_header(cls, fileobj):
353
353
354
354
# Set the file position where it was, in case it was previously open
355
355
if start_position is not None :
356
- f .fobj . seek (start_position , os .SEEK_SET )
356
+ f .seek (start_position , os .SEEK_SET )
357
357
358
358
# Check integrity of TCK header.
359
359
if 'datatype' not in hdr :
0 commit comments