def _process_part()

in alibabacloud_oss_v2/downloader.py [0:0]


    def _process_part(self, start:int):
        # When an error occurs, ignore other download requests
        if len(self._download_errors) > 0:
            return None

        size = self._calc_part_size(start)
        request = copy.copy(self._reqeust)

        got = 0
        error: Exception = None

        chash: Crc64 = None
        if self._calc_crc:
            chash = Crc64(0)

        while True:
            request.range_header = f'bytes={start + got}-{start + size - 1}'
            request.range_behavior = 'standard'

            try:
                result = self._client.get_object(request)
            except Exception as err:
                error = err
                break

            kwargs = {}
            if self._options.block_size:
                kwargs['block_size'] = self._options.block_size

            try:
                gotlen = 0
                for d in result.body.iter_bytes(**kwargs):
                    l = len(d)
                    if l > 0:
                        self._write_to_stream(d, start + got)
                        self._update_progress(l)
                        got += l
                        gotlen += l
                        if chash:
                            chash.update(d)

                if result.content_length is not None and gotlen < result.content_length:
                    if not result.body.is_closed:
                        result.body.close()
                    continue
                break
            except Exception:
                pass

        return start, got, error, (chash.sum64() if chash else 0)