@@ -181,8 +181,9 @@ class DryRunFileInfo:
181181 Args:
182182 commit_hash (`str`):
183183 The commit_hash related to the file.
184- file_size (`int`):
185- Size of the file. In case of an LFS file, contains the size of the actual LFS file, not the pointer.
184+ file_size (`int`, *optional*):
185+ Size of the file, if known. In case of an LFS file, contains the size of the actual LFS file, not the
186+ pointer.
186187 filename (`str`):
187188 Name of the file in the repo.
188189 is_cached (`bool`):
@@ -193,7 +194,7 @@ class DryRunFileInfo:
193194 """
194195
195196 commit_hash : str
196- file_size : int
197+ file_size : int | None
197198 filename : str
198199 local_path : str
199200 is_cached : bool
@@ -407,7 +408,9 @@ def http_get(
407408 resume_size = 0
408409
409410 total : int | None = _get_file_length_from_http_response (response )
410- if total is None :
411+ if expected_size is None :
412+ expected_size = total
413+ elif total is None :
411414 # Hub serves compressible text files (e.g. vocab.json) with `Content-Encoding: gzip` and
412415 # `Transfer-Encoding: chunked`, so the response carries no `Content-Length`. Fall back to the caller's
413416 # `expected_size` (always known from the metadata HEAD on the hf_hub path) so the progress bar, and any
@@ -1178,11 +1181,10 @@ def _hf_hub_download_to_cache_dir(
11781181 if head_call_error is not None :
11791182 _raise_on_head_call_error (head_call_error , force_download , local_files_only )
11801183
1181- # From now on, etag, commit_hash, url and size are not None.
1184+ # From now on, etag, commit_hash and url are not None.
11821185 assert etag is not None , "etag must have been retrieved from server"
11831186 assert commit_hash is not None , "commit_hash must have been retrieved from server"
11841187 assert url_to_download is not None , "file location must have been retrieved from server"
1185- assert expected_size is not None , "expected_size must have been retrieved from server"
11861188 blob_path = os .path .join (storage_folder , "blobs" , etag )
11871189 pointer_path = _get_pointer_path (storage_folder , commit_hash , relative_filename )
11881190
@@ -1384,11 +1386,10 @@ def _hf_hub_download_to_local_dir(
13841386 if head_call_error is not None :
13851387 _raise_on_head_call_error (head_call_error , force_download , local_files_only )
13861388
1387- # From now on, etag, commit_hash, url and size are not None.
1389+ # From now on, etag, commit_hash and url are not None.
13881390 assert etag is not None , "etag must have been retrieved from server"
13891391 assert commit_hash is not None , "commit_hash must have been retrieved from server"
13901392 assert url_to_download is not None , "file location must have been retrieved from server"
1391- assert expected_size is not None , "expected_size must have been retrieved from server"
13921393
13931394 # Local file exists => check if it's up-to-date
13941395 if not force_download and paths .file_path .is_file ():
@@ -1675,7 +1676,7 @@ def _get_metadata_or_catch_error(
16751676 |
16761677 # Or the metadata is returned as
16771678 # `(url_to_download, etag, commit_hash, expected_size, xet_file_data, None)`
1678- tuple [str , str , str , int , XetFileData | None , None ]
1679+ tuple [str , str , str , int | None , XetFileData | None , None ]
16791680):
16801681 """Get metadata for a file on the Hub, safely handling network issues.
16811682
@@ -1767,12 +1768,11 @@ def _get_metadata_or_catch_error(
17671768 "Distant resource does not have an ETag, we won't be able to reliably ensure reproducibility."
17681769 )
17691770
1770- # Size must exist
1771+ # Xet downloads require a known size, but regular HTTP downloads can recover it from the GET response.
17711772 expected_size = metadata .size
1772- if expected_size is None :
1773- raise FileMetadataError ("Distant resource does not have a Content-Length." )
1774-
17751773 xet_file_data = metadata .xet_file_data
1774+ if expected_size is None and xet_file_data is not None and is_xet_available ():
1775+ raise FileMetadataError ("Distant resource does not have a Content-Length." )
17761776
17771777 # In case of a redirect, save an extra redirect on the request.get call,
17781778 # and ensure we download the exact atomic version even if it changed
0 commit comments