Skip to content

Commit 742a103

Browse files
authored
Make zip write use the remote path it should (#1046)
1 parent 2633445 commit 742a103

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

Diff for: fsspec/implementations/zip.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import datetime
44
import zipfile
55

6-
from fsspec import open_files
6+
import fsspec
77
from fsspec.archive import AbstractArchiveFileSystem
88
from fsspec.utils import DEFAULT_BLOCK_SIZE
99

@@ -46,15 +46,9 @@ def __init__(
4646
"""
4747
super().__init__(self, **kwargs)
4848
if isinstance(fo, str):
49-
files = open_files(
49+
fo = fsspec.open(
5050
fo, mode=mode + "b", protocol=target_protocol, **(target_options or {})
5151
)
52-
if len(files) != 1:
53-
raise ValueError(
54-
'Path "{}" did not resolve to exactly'
55-
'one file: "{}"'.format(fo, files)
56-
)
57-
fo = files[0]
5852
self.of = fo
5953
self.fo = fo.__enter__() # the whole instance is a context
6054
self.zip = zipfile.ZipFile(self.fo, mode=mode)
@@ -68,7 +62,11 @@ def _strip_protocol(cls, path):
6862

6963
def __del__(self):
7064
if hasattr(self, "zip"):
71-
self.zip.close()
65+
self.close()
66+
67+
def close(self):
68+
"Commits any write changes to the file. Done on ``del`` too."
69+
self.zip.close()
7270

7371
def _get_dirs(self):
7472
if self.dir_cache is None:
@@ -78,7 +76,7 @@ def _get_dirs(self):
7876
for dirname in self._all_dirnames(self.zip.namelist())
7977
}
8078
for z in files:
81-
f = {s: getattr(z, s) for s in zipfile.ZipInfo.__slots__}
79+
f = {s: getattr(z, s, None) for s in zipfile.ZipInfo.__slots__}
8280
f.update(
8381
{
8482
"name": z.filename,

0 commit comments

Comments
 (0)