Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix_s3_ignore_seeks_to_current_position #782

Merged
11 changes: 9 additions & 2 deletions smart_open/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ def __init__(
self._buffer = smart_open.bytebuffer.ByteBuffer(buffer_size)
self._eof = False
self._line_terminator = line_terminator
self._seek_initialized = False

#
# This member is part of the io.BufferedIOBase interface.
Expand Down Expand Up @@ -677,10 +678,16 @@ def seek(self, offset, whence=constants.WHENCE_START):
whence = constants.WHENCE_START
offset += self._current_pos

self._current_pos = self._raw_reader.seek(offset, whence)
if not self._seek_initialized or not (
whence == constants.WHENCE_START and offset == self._current_pos
):
self._current_pos = self._raw_reader.seek(offset, whence)

self._buffer.empty()

self._buffer.empty()
self._eof = self._current_pos == self._raw_reader._content_length

self._seek_initialized = True
return self._current_pos

def tell(self):
Expand Down
Loading