跳转至

Async utils

labridge.func_modules.paper.download.async_utils

labridge.func_modules.paper.download.async_utils.adownload_file(url, save_path) async

Asynchronously download file.

PARAMETER DESCRIPTION
url

The url of the file.

TYPE: str

save_path

The save path of the file.

TYPE: str

RETURNS DESCRIPTION
save_path

The save path.

TYPE: str

Source code in labridge\func_modules\paper\download\async_utils.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
async def adownload_file(url: str, save_path: str) -> str:
	r"""
	Asynchronously download file.

	Args:
		url (str): The url of the file.
		save_path (str): The save path of the file.

	Returns:
		save_path (str): The save path.
	"""
	async with aiohttp.ClientSession() as session:
		async with session.get(url) as response:
			with open(save_path, 'wb') as f:
				while True:
					chunk = await response.content.read(1024)
					if not chunk:
						break
					f.write(chunk)
	return save_path