MCPcopy Create free account
hub / github.com/FastLED/FastLED / _get_remote_file_size

Function _get_remote_file_size

ci/compiler/platformio_cache.py:106–124  ·  view source on GitHub ↗

Get file size from URL using HEAD request.

(url: str)

Source from the content-addressed store, hash-verified

104
105
106def _get_remote_file_size(url: str) -> Optional[int]:
107 """Get file size from URL using HEAD request."""
108 try:
109 parsed_url = urllib.parse.urlparse(url)
110 if parsed_url.scheme in ("http", "https"):
111 with httpx.Client(follow_redirects=True) as client:
112 response = client.head(
113 url, headers={"User-Agent": "PlatformIO-Cache/1.0"}
114 )
115 response.raise_for_status()
116 content_length = response.headers.get("Content-Length")
117 if content_length:
118 return int(content_length)
119 except KeyboardInterrupt as ki:
120 handle_keyboard_interrupt(ki)
121 raise
122 except Exception as e:
123 logger.debug(f"Failed to get file size for {url}: {e}")
124 return None
125
126
127def _format_file_size(size_bytes: Optional[int]) -> str:

Callers 1

download_artifactMethod · 0.85

Calls 4

headMethod · 0.80
debugMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected