Skip to content

Commit

Permalink
fix: close local files after read
Browse files Browse the repository at this point in the history
Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed Mar 27, 2024
1 parent 13609ac commit fc15716
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/unearth/fetchers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def is_absolute_url(self) -> bool:
httpx.URL.is_absolute_url = property(is_absolute_url)


class FileByteStream(IteratorByteStream):
def close(self) -> None:
self._stream.close() # type: ignore[attr-defined]


class LocalFSTransport(httpx.BaseTransport):
def handle_request(self, request: httpx.Request) -> httpx.Response:
link = Link(str(request.url))
Expand All @@ -50,7 +55,7 @@ def handle_request(self, request: httpx.Request) -> httpx.Response:
return httpx.Response(
status_code=200,
headers=headers,
stream=IteratorByteStream(path.open("rb")),
stream=FileByteStream(path.open("rb")),
)


Expand Down

0 comments on commit fc15716

Please sign in to comment.