Fix sync callback progress not working properly for downloads
- Reduce duplicated code - Fixes #484
This commit is contained in:
parent
58667d2ae8
commit
ae88c851bb
@ -949,7 +949,8 @@ class Client(Methods, Scaffold):
|
||||
offset += limit
|
||||
|
||||
if progress:
|
||||
await progress(
|
||||
func = functools.partial(
|
||||
progress,
|
||||
min(offset, file_size)
|
||||
if file_size != 0
|
||||
else offset,
|
||||
@ -957,6 +958,11 @@ class Client(Methods, Scaffold):
|
||||
*progress_args
|
||||
)
|
||||
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await func()
|
||||
else:
|
||||
await self.loop.run_in_executor(self.executor, func)
|
||||
|
||||
r = await session.send(
|
||||
raw.functions.upload.GetFile(
|
||||
location=location,
|
||||
@ -1035,13 +1041,6 @@ class Client(Methods, Scaffold):
|
||||
offset += limit
|
||||
|
||||
if progress:
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await progress(
|
||||
min(offset, file_size) if file_size != 0 else offset,
|
||||
file_size,
|
||||
*progress_args
|
||||
)
|
||||
else:
|
||||
func = functools.partial(
|
||||
progress,
|
||||
min(offset, file_size) if file_size != 0 else offset,
|
||||
@ -1049,6 +1048,9 @@ class Client(Methods, Scaffold):
|
||||
*progress_args
|
||||
)
|
||||
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await func()
|
||||
else:
|
||||
await self.loop.run_in_executor(self.executor, func)
|
||||
|
||||
if len(chunk) < limit:
|
||||
|
@ -183,9 +183,6 @@ class SaveFile(Scaffold):
|
||||
file_part += 1
|
||||
|
||||
if progress:
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await progress(min(file_part * part_size, file_size), file_size, *progress_args)
|
||||
else:
|
||||
func = functools.partial(
|
||||
progress,
|
||||
min(file_part * part_size, file_size),
|
||||
@ -193,6 +190,9 @@ class SaveFile(Scaffold):
|
||||
*progress_args
|
||||
)
|
||||
|
||||
if inspect.iscoroutinefunction(progress):
|
||||
await func()
|
||||
else:
|
||||
await self.loop.run_in_executor(self.executor, func)
|
||||
except StopTransmission:
|
||||
raise
|
||||
|
Loading…
Reference in New Issue
Block a user