Skip to content

Commit

Permalink
handle encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Feb 10, 2018
1 parent b1f37d8 commit 804536b
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions fs/tarfs.py
Expand Up @@ -86,7 +86,10 @@ def __new__(cls,
encoding="utf-8",
temp_fs="temp://__tartemp__"):

filename = getattr(file, 'name', file)
if isinstance(file, (six.text_type, six.binary_type)):
filename = file
else:
filename = getattr(file, 'name', '')
if not hasattr(file, 'read'):
file = os.path.expanduser(file)

Expand All @@ -102,8 +105,8 @@ def __new__(cls,
compression=compression,
encoding=encoding,
temp_fs=temp_fs)
# else:
return ReadTarFS(file, encoding=encoding)
else:
return ReadTarFS(file, encoding=encoding)


@six.python_2_unicode_compatible
Expand Down Expand Up @@ -209,17 +212,9 @@ def __init__(self, file, encoding='utf-8'):
self._tar = tarfile.open(fileobj=file, mode='r')
else:
self._tar = tarfile.open(file, mode='r')
def _decode(s):
return (
s.decode(self.encoding, 'replace')
if isinstance(s, bytes) else s
)
# _directory = (
# _get_member_info(info, self.encoding) for info in self._tar
# )

self._directory = {
relpath(_decode(info.name)).rstrip('/'): info
relpath(self._decode(info.name)).rstrip('/'): info
for info in self._tar
}

Expand Down

0 comments on commit 804536b

Please sign in to comment.