Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions avrokit/url/google.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,12 @@ def open(self) -> IO[Any]:
self._current_local = tmpfile
self._current_local_stream = self._current_local
# Download to file if r/rb mode, or if append mode (to preserve existing content on failure)
if "r" in self.mode or "a" in self.mode:
# N.b. always writes in binary mode
if "r" in self.mode or ("a" in self.mode and blob.exists()):
blob.download_to_file(tmpfile)
tmpfile.seek(0)
if "a" in self.mode:
tmpfile.seek(0, 2) # Seek to end for append mode
if "b" not in self.mode:
# So if the user wants to read text, we need to decode it
self._current_local_stream = io.TextIOWrapper(tmpfile, encoding="utf-8")
elif ("w" in self.mode or "a" in self.mode) and "b" not in self.mode:
# Same thing when we're writing text
if "a" in self.mode:
tmpfile.seek(0, 2)
if "b" not in self.mode:
self._current_local_stream = io.TextIOWrapper(tmpfile, encoding="utf-8")
stream = cast(IO[Any], self._current_local_stream)
return stream
Expand Down
13 changes: 4 additions & 9 deletions avrokit/url/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,12 @@ def open(self) -> IO[Any]:
self._current_local = tmpfile
self._current_local_stream = self._current_local
# Download to file if "r"/"rb" mode, or if append mode (to preserve existing content on failure)
if "r" in self.mode or "a" in self.mode:
# N.b. always writes in binary mode
if "r" in self.mode or ("a" in self.mode and self.exists()):
client.download_fileobj(self.bucket, self.path, tmpfile)
tmpfile.seek(0)
if "a" in self.mode:
tmpfile.seek(0, 2) # Seek to end for append mode
if "b" not in self.mode:
# So if the user wants to read text, we need to decode it
self._current_local_stream = io.TextIOWrapper(tmpfile, encoding="utf-8")
elif ("w" in self.mode or "a" in self.mode) and "b" not in self.mode:
# Same thing when we're writing text
if "a" in self.mode:
tmpfile.seek(0, 2)
if "b" not in self.mode:
self._current_local_stream = io.TextIOWrapper(tmpfile, encoding="utf-8")
stream = cast(IO[Any], self._current_local_stream)
return stream
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[tool.poetry]
name = "avrokit"
version = "0.0.3"
version = "0.0.4"
description = "Python utilities for working with Avro data files"
authors = ["Greg Brandt <brandt.greg@gmail.com>"]
license = "Apache-2.0"
Expand Down