|
2 | 2 |
|
3 | 3 | import requests |
4 | 4 |
|
| 5 | +from ..asyn import get_loop, sync |
5 | 6 | from ..spec import AbstractFileSystem |
6 | 7 | from ..utils import infer_storage_options |
| 8 | +from .http import HTTPFile, HTTPFileSystem |
7 | 9 | from .memory import MemoryFile |
8 | 10 |
|
9 | 11 | # TODO: add GIST backend, would be very similar |
@@ -64,6 +66,11 @@ def __init__( |
64 | 66 | self.root = sha |
65 | 67 | self.ls("") |
66 | 68 |
|
| 69 | + # prepare elements needed to return HTTPFile |
| 70 | + self.http_fs = HTTPFileSystem(**kwargs) |
| 71 | + self.loop = get_loop() |
| 72 | + self.session = sync(self.loop, self.http_fs.set_session) |
| 73 | + |
67 | 74 | @property |
68 | 75 | def kw(self): |
69 | 76 | if self.username: |
@@ -245,9 +252,16 @@ def _open( |
245 | 252 |
|
246 | 253 | # we land here if the content was not present in the first response |
247 | 254 | # (regular file over 1MB or git-lfs tracked file) |
248 | | - # in this case, we get the content from the download_url |
249 | | - r = requests.get(content_json["download_url"], timeout=self.timeout, **self.kw) |
250 | | - if r.status_code == 404: |
251 | | - raise FileNotFoundError(path) |
252 | | - r.raise_for_status() |
253 | | - return MemoryFile(None, None, r.content) |
| 255 | + # in this case, we get return an HTTPFile object wrapping the |
| 256 | + # download_url |
| 257 | + return HTTPFile( |
| 258 | + self.http_fs, |
| 259 | + content_json["download_url"], |
| 260 | + session=self.session, |
| 261 | + block_size=block_size, |
| 262 | + autocommit=autocommit, |
| 263 | + cache_options=cache_options, |
| 264 | + size=content_json["size"], |
| 265 | + loop=self.loop, |
| 266 | + **kwargs, |
| 267 | + ) |
0 commit comments