diff options
author | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2008-09-16 11:45:14 +0000 |
---|---|---|
committer | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2008-09-16 11:45:14 +0000 |
commit | 1fd5453afc40a8a9a4eb2a3591b684681c9500b9 (patch) | |
tree | 06ea5776238f4100b87295cd06edfb0ad8864c0d /fs/zipfs.py | |
parent | 6aac4de5322bd5ab164ced1d953e8b7dd77c61ce (diff) | |
download | pyfilesystem-git-1fd5453afc40a8a9a4eb2a3591b684681c9500b9.tar.gz |
Added optimized getcontents method
Diffstat (limited to 'fs/zipfs.py')
-rw-r--r-- | fs/zipfs.py | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/fs/zipfs.py b/fs/zipfs.py index abc76da..98f9e6b 100644 --- a/fs/zipfs.py +++ b/fs/zipfs.py @@ -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: |