Skip to content

Commit

Permalink
Handle binary open mode in S3Path.
Browse files Browse the repository at this point in the history
  • Loading branch information
takacsd committed Nov 22, 2023
1 parent 81af233 commit 49c91ad
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions visidata/loaders/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,10 @@ def fs(self):
def fs(self, val):
self._fs = val

def open(self, *args, **kwargs):
def open(self, mode='r', **kwargs):
"""Open the current S3 path, decompressing along the way if needed."""

# Default to text mode unless we have a compressed file
mode = "rb" if self.compression else "r"

fp = self.fs.open(self.given, mode=mode, version_id=self.version_id)
fp = self.fs.open(self.given, mode="rb" if self.compression else mode, version_id=self.version_id)

# Workaround for https://github.com/ajkerrigan/visidata-plugins/issues/12
if hasattr(fp, "cache") and fp.cache.size != fp.size:
Expand All @@ -79,17 +76,17 @@ def open(self, *args, **kwargs):
if self.compression == "gz":
import gzip

return gzip.open(fp, *args, **kwargs)
return gzip.open(fp, mode, **kwargs)

if self.compression == "bz2":
import bz2

return bz2.open(fp, *args, **kwargs)
return bz2.open(fp, mode, **kwargs)

if self.compression == "xz":
import lzma

return lzma.open(fp, *args, **kwargs)
return lzma.open(fp, mode, **kwargs)

return fp

Expand Down

0 comments on commit 49c91ad

Please # to comment.