def read(self, callback: Callable[[bytearray], Any]):
try:
for downloader in self._downloaders:
# Wait until downloader is not in a downloaded/cancelled state.
async with self._state_condition:
while downloader.state not in (DOWNLOADED, CANCELLED):
await self._state_condition.wait()
if downloader.state != DOWNLOADED:
self._debug('Downloader not in `DOWNLOADED` state, but in `{!s}`.'.format(downloader.state))
raise CancelledError()
# Open file and send all its bytes it to back.
await read_from_file_by_chunks(downloader.buffer_file_path, callback, self._chunk_size,
lambda: self._state != CANCELLED, loop=self._loop)
except Exception as exc:
raise ReadError(exc)
评论列表
文章目录