Skip to content

Commit

Permalink
Rename 'open' function and avoid failing to EOF scan very large files
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcvey3 committed Jan 9, 2025
1 parent 8c54773 commit e9dd268
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions mhkit/dolfyn/io/nortek2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from ..time import epoch2dt64, _fill_time_gaps


int32_max = np.iinfo(np.int32).max


def read_signature(
filename,
userdata=True,
Expand Down Expand Up @@ -163,7 +166,7 @@ def __init__(
debug=debug,
dp=dual_profile,
)
self._reopen(bufsize)
self._open(bufsize)
self.filehead_config = self._read_filehead_config_string()
self._ens_pos = self._index["pos"][
lib._boolarray_firstensemble_ping(self._index)
Expand All @@ -183,7 +186,7 @@ def _calc_lastblock_iswhole(
return (self._eof - self._ens_pos[-1]) == standard_blocksize

def _check_nortek(self, endian):
self._reopen(10)
self._open(10)
byts = self.f.read(2)
if endian is None:
if unpack("<" + "BB", byts) == (165, 10):
Expand All @@ -205,8 +208,12 @@ def find_all(s, c):
yield idx
idx = s.find(c, idx + 1)

# Open the entire file
self._reopen(self._eof)
# Open the entire file to find start header
if self._eof >= int32_max:
init_buffer = int32_max
else:
init_buffer = self._eof
self._open(init_buffer)
pk = self.f.peek(1)
# Search for multiple saved headers
found = [i for i in find_all(pk, b"GETCLOCKSTR")]
Expand All @@ -216,7 +223,7 @@ def find_all(s, c):
start_idx = found[-1] - 11
return start_idx

def _reopen(self, bufsize=None):
def _open(self, bufsize=None):
if bufsize is None:
bufsize = 1000000
try:
Expand Down

0 comments on commit e9dd268

Please sign in to comment.