Example #1
0
    def download_blob(self, blob: Blob, destination: FileLike) -> None:
        data = self.client.get_object(blob.container.name, blob.name)

        if isinstance(destination, str):
            with open(destination, "wb") as blob_data:
                for d in data.stream(4096):
                    blob_data.write(d)
        else:
            for d in data.stream(4096):
                destination.write(d)
Example #2
0
    def download_blob(self, blob: Blob, destination: FileLike) -> None:
        try:
            data = self.object_store.download_object(
                obj=blob.name, container=blob.container.name)

            if isinstance(destination, str):
                with open(destination, 'wb') as out:
                    out.write(data)
            else:
                destination.write(data)
        except ResourceNotFound:
            raise NotFoundError(messages.BLOB_NOT_FOUND %
                                (blob.name, blob.container.name))
Example #3
0
    def download_blob(self, blob: Blob, destination: FileLike) -> None:
        blob_path = self._get_file_path(blob)

        if isinstance(destination, str):
            base_name = os.path.basename(destination)
            if not base_name and not os.path.exists(destination):
                raise CloudStorageError("Path %s does not exist." %
                                        destination)

            if not base_name:
                file_path = os.path.join(destination, blob.name)
            else:
                file_path = destination

            shutil.copy(blob_path, file_path)
        else:
            with open(blob_path, "rb") as blob_file:
                for data in read_in_chunks(blob_file):
                    destination.write(data)