Commit 1fd5453a by willmcgugan

Added optimized getcontents method

parent 6aac4de5
......@@ -44,8 +44,8 @@ class _ExceptionProxy(object):
class ZipFS(FS):
def __init__(self, zip_file, mode="r", compression="deflated", allowZip64=False):
FS.__init__(self, thread_syncronize=True)
def __init__(self, zip_file, mode="r", compression="deflated", allowZip64=False, thread_syncronize=True):
FS.__init__(self, thread_syncronize=thread_syncronize)
if compression == "deflated":
compression_type = ZIP_DEFLATED
elif compression == "stored":
......@@ -134,6 +134,20 @@ class ZipFS(FS):
finally:
self._lock.release()
def getcontents(self, path):
self._lock.acquire()
try:
if not exists(path):
raise ResourceNotFoundError("NO_FILE", path)
path = normpath(path)
try:
contents = self.zf.read(path)
except KeyError:
raise ResourceNotFoundError("NO_FILE", path)
return contents
finally:
self._lock.release()
def _on_write_close(self, filename):
self._lock.acquire()
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment