Skip to content

Commit

Permalink
Small fix to checkout/in functions to seek(0) before reading the file…
Browse files Browse the repository at this point in the history
… on checkint (#86)
davidparks21 authored and atspaeth committed Jun 7, 2024
1 parent 922c390 commit 77d177c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/braingeneers/utils/common_utils.py
Original file line number Diff line number Diff line change
@@ -255,15 +255,17 @@ def checkin(self, update_file: Union[str, bytes, io.IOBase]):
raise TypeError('File must be a string, bytes, or file object.')
if isinstance(update_file, str) or isinstance(update_file, io.StringIO):
if self.isbinary:
raise ValueError(
'Cannot check in a string or text file when checkout is specified for binary mode.')
raise ValueError('Cannot check in a string or text file when checkout is specified for binary mode.')
if isinstance(update_file, bytes) or isinstance(update_file, io.BytesIO):
if not self.isbinary:
raise ValueError('Cannot check in bytes or a binary file when checkout is specified for text mode.')

if isinstance(update_file, io.IOBase):
update_file.seek(0)
update_str_or_bytes = update_file if not isinstance(update_file, io.IOBase) else update_file.read()
mode = 'w' if not self.isbinary else 'wb'
with smart_open.open(self.s3_path_str, mode=mode) as f:
f.write(update_file if not isinstance(update_file, io.IOBase) else update_file.read())
f.write(update_str_or_bytes)

def __init__(self, s3_path_str: str, isbinary: bool = False):
# TODO: avoid circular import

0 comments on commit 77d177c

Please sign in to comment.