Skip to content

Commit

Permalink
refactor get_url_size
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahAlidoost committed Oct 22, 2024
1 parent 49637d1 commit c24bbf7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/zampy/datasets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ def download_url(url: str, fpath: Path, overwrite: bool) -> None:
print(f"File '{fpath.name}' already exists, skipping...")


def get_url_size(url: str) -> int:
def get_url_size(url: str) -> int | None:
"""Return the size (bytes) of a given URL."""
response = requests.head(url)
return int(response.headers["Content-Length"])
content_length = response.headers.get("Content-Length")
if content_length:
return int(content_length)
return None


def get_file_size(fpath: Path) -> int:
Expand Down

0 comments on commit c24bbf7

Please sign in to comment.