MCPcopy Create free account
hub / github.com/cosdata/cosdata / download_file

Function download_file

tests/test-dataset.py:114–139  ·  view source on GitHub ↗

Download a file with progress bar

(url, destination)

Source from the content-addressed store, hash-verified

112
113
114def download_file(url, destination):
115 """Download a file with progress bar"""
116 try:
117 response = requests.get(url, stream=True)
118 response.raise_for_status() # Raise an exception for bad status codes
119
120 total_size = int(response.headers.get("content-length", 0))
121
122 with (
123 open(destination, "wb") as f,
124 tqdm(
125 desc=os.path.basename(destination),
126 total=total_size,
127 unit="iB",
128 unit_scale=True,
129 unit_divisor=1024,
130 ) as pbar,
131 ):
132 for data in response.iter_content(chunk_size=1024):
133 size = f.write(data)
134 pbar.update(size)
135 except requests.exceptions.RequestException as e:
136 print(f"Error downloading file: {e}")
137 if os.path.exists(destination):
138 os.remove(destination)
139 raise
140
141
142def prepare_glove_dataset(dataset_dir):

Callers 1

prepare_glove_datasetFunction · 0.70

Calls 2

removeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected