Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pysus/api/dadosgov/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pathlib
from collections.abc import Callable

import anyio
from datetime import datetime
from typing import TYPE_CHECKING, Annotated, Any, Optional

Expand Down Expand Up @@ -295,9 +297,9 @@ async def download(
response.raise_for_status()
total = int(response.headers.get("Content-Length", 0))
downloaded = 0
with open(output, "wb") as f:
async with await anyio.open_file(output, "wb") as f:
async for chunk in response.aiter_bytes():
f.write(chunk)
await f.write(chunk)
downloaded += len(chunk)
if callback:
callback(downloaded, total)
Expand Down