How to use the azure-storage-file.azure.storage.file._download_chunking._FileChunkDownloader function in azure-storage-file

To help you get started, we’ve selected a few azure-storage-file examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-storage-python / azure-storage-file / azure / storage / file / _download_chunking.py View on Github external
def _download_chunk(self, chunk_start, chunk_end):
        return self.file_service._get_file(
            self.share_name,
            self.directory_name,
            self.file_name,
            start_range=chunk_start,
            end_range=chunk_end - 1,
            validate_content=self.validate_content,
            timeout=self.timeout,
            _context=self.operation_context,
            snapshot=self.snapshot
        )


class _ParallelFileChunkDownloader(_FileChunkDownloader):
    def __init__(self, file_service, share_name, directory_name, file_name,
                 download_size, chunk_size, progress, start_range, end_range,
                 stream, progress_callback, validate_content, timeout, operation_context, snapshot):
        super(_ParallelFileChunkDownloader, self).__init__(file_service, share_name, directory_name, file_name,
                                                           download_size, chunk_size, progress, start_range, end_range,
                                                           stream, progress_callback, validate_content, timeout,
                                                           operation_context, snapshot)

        # for a parallel download, the stream is always seekable, so we note down the current position
        # in order to seek to the right place when out-of-order chunks come in
        self.stream_start = stream.tell()

        # since parallel operations are going on
        # it is essential to protect the writing and progress reporting operations
        self.stream_lock = threading.Lock()
        self.progress_lock = threading.Lock()
github Azure / azure-storage-python / azure-storage-file / azure / storage / file / _download_chunking.py View on Github external
self.progress_lock = threading.Lock()

    def _update_progress(self, length):
        if self.progress_callback is not None:
            with self.progress_lock:
                self.progress_total += length
                total_so_far = self.progress_total
            self.progress_callback(total_so_far, self.download_size)

    def _write_to_stream(self, chunk_data, chunk_start):
        with self.stream_lock:
            self.stream.seek(self.stream_start + (chunk_start - self.start_index))
            self.stream.write(chunk_data)


class _SequentialFileChunkDownloader(_FileChunkDownloader):
    def __init__(self, file_service, share_name, directory_name, file_name, download_size, chunk_size, progress,
                 start_range, end_range, stream, progress_callback, validate_content, timeout, operation_context,
                 snapshot):
        super(_SequentialFileChunkDownloader, self).__init__(file_service, share_name, directory_name, file_name,
                                                             download_size, chunk_size, progress, start_range,
                                                             end_range, stream, progress_callback, validate_content,
                                                             timeout, operation_context, snapshot)

    def _update_progress(self, length):
        if self.progress_callback is not None:
            self.progress_total += length
            self.progress_callback(self.progress_total, self.download_size)

    def _write_to_stream(self, chunk_data, chunk_start):
        # chunk_start is ignored in the case of sequential download since we cannot seek the destination stream
        self.stream.write(chunk_data)

azure-storage-file

Microsoft Azure Storage File Client Library for Python

MIT
Latest version published 5 years ago

Package Health Score

70 / 100
Full package analysis