Skip to content

Commit

Permalink
Fix change in behaviour in zipfile in Python 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Larralde committed Aug 7, 2018
1 parent c825252 commit 4389ba1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fs/archive/zipfs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@
from ...time import datetime_to_epoch
from ...path import forcedir, relpath, dirname, basename, abspath
from ...path import iteratepath, recursepath, frombase, join
from ...enums import ResourceType
from ...enums import ResourceType, Seek
from ...iotools import RawWrapper
from ..._fscompat import fsdecode, fsencode

from .. import base


class _ZipFileWrapper(RawWrapper):

def seek(self, offset, whence=Seek.set):
if whence == Seek.set and offset < 0:
raise ValueError('cannot seek to negative offset')
elif whence == Seek.end and offset > 0:
raise ValueError('cannot seek after end position')
return super(_ZipFileWrapper, self).seek(offset, whence)


class ZipReadFS(base.ArchiveReadFS):
"""A read-only filesystem within a ZIP archive.
"""
Expand Down Expand Up @@ -192,7 +202,7 @@ def openbin(self, path, mode='r', buffering=-1, **options): # noqa: D102
_path = _path.encode(self._encoding)

bin_file = self._zip.open(_path, 'r')
return RawWrapper(bin_file)
return _ZipFileWrapper(bin_file)

def close(self): # noqa: D102
if not self.isclosed():
Expand Down

0 comments on commit 4389ba1

Please sign in to comment.