@@ -139,12 +139,19 @@ def mimetype(self) -> 'Mimetype':
139139
140140 def local_path (self , d : pathlib .Path = None ) -> Optional [pathlib .Path ]:
141141 """
142- :return: The expected path of the file in the directory `d`.
142+ :return: The expected path of the file in the directory `d` in the case of files \
143+ downloaded using the `downloadmedia` command. If `d` is a file it is accepted as full \
144+ local path if it has the same name as the filename in the URL.
143145 """
144146 if d is None :
145147 if self .scheme == 'file' :
146148 return self ._dsdir / urllib .parse .unquote (self .relpath )
147149 return None
150+ if d .is_file () and self .parsed_url :
151+ if d .name == pathlib .Path (self .parsed_url .path ).name :
152+ # Support the use case of files in zip archives, where the archives are available
153+ # locally, e.g. as download of a separate media file deposit from Zenodo.
154+ return d
148155 zip_ext = '.zip' if self .path_in_zip else (self .mimetype .extension or '' )
149156 return d .joinpath (f'{ self .id } { zip_ext } ' )
150157
@@ -155,14 +162,14 @@ def read_json(self, d=None):
155162
156163 def read (self , d : Optional [pathlib .Path ] = None ) -> Optional [StrOrBytes ]:
157164 """
158- :param d: A local directory where the file has been saved before. If `None`, the content \
159- will be read from the file's URL.
165+ :param d: A local path where the file has been saved before - as expected by `local_path`. \
166+ If `None`, the content will be read from the file's URL.
160167 """
161168 if self .path_in_zip :
162169 zipcontent = None
163170 if d :
164171 zipcontent = self .local_path (d ).read_bytes ()
165- if self .url :
172+ if zipcontent is None and self .url :
166173 zipcontent = self .url_reader [self .scheme ](
167174 self .parsed_url , Mimetype ('application/zip' ))
168175 if zipcontent :
0 commit comments