# Buggy code
def storage_blob_download_batch(
    client,
    source,
    destination,
    source_container_name,
    pattern=None,
    dryrun=False,
    progress_callback=None,
):
    def _download_blob(blob_service, container, destination_folder, blob_name):
        import os

        # TODO: try catch IO exception
        destination_path = os.path.join(destination_folder, blob_name)
        destination_folder = os.path.dirname(destination_path)
        if not os.path.exists(destination_folder):
            mkdir_p(destination_folder)

        blob = blob_service.get_blob_to_path(
            container, blob_name, destination_path, progress_callback=progress_callback
        )
        return blob.name

    source_blobs = list(collect_blobs(client, source_container_name, pattern))

    if dryrun:
        logger = get_logger(__name__)
        logger.warning("download action: from %s to %s", source, destination)
        logger.warning("    pattern %s", pattern)
        logger.warning("  container %s", source_container_name)
        logger.warning("      total %d", len(source_blobs))
        logger.warning(" operations")
        for b in source_blobs:
            logger.warning("  - %s", b)
        return []

    return list(
        _download_blob(client, source_container_name, destination, blob)
        for blob in source_blobs
    )


# Traceback (TypeError)
az --verbose storage blob download --name test.csv --file a --start-range 0 --end-range 10 --container-name *** --connection-string 'DefaultEndpointsProtocol=https;EndpointSuffix=core.windows.net;AccountName=***;AccountKey=***'

unsupported operand type(s) for -: 'str' and 'str'
Traceback (most recent call last):
File "az_virtenv/lib/python3.4/site-packages/knack/cli.py", line 193, in invoke
cmd_result = self.invocation.execute(args)
File "az_virtenv/lib/python3.4/site-packages/azure/cli/core/commands/__init__.py", line 319, in execute
six.reraise(*sys.exc_info())
File "az_virtenv/lib/python3.4/site-packages/six.py", line 693, in reraise
raise value
File "az_virtenv/lib/python3.4/site-packages/azure/cli/core/commands/__init__.py", line 292, in execute
result = cmd(params)
File "az_virtenv/lib/python3.4/site-packages/azure/cli/core/commands/__init__.py", line 169, in __call__
return super(AzCliCommand, self).__call__(*args, **kwargs)
File "az_virtenv/lib/python3.4/site-packages/knack/commands.py", line 109, in __call__
return self.handler(*args, **kwargs)
File "az_virtenv/lib/python3.4/site-packages/azure/cli/core/__init__.py", line 328, in default_command_handler
result = op(**command_args)
File "az_virtenv/lib/python3.4/site-packages/azure/multiapi/storage/v2017_04_17/blob/baseblobservice.py", line 1784, in get_blob_to_path
timeout)
File "az_virtenv/lib/python3.4/site-packages/azure/multiapi/storage/v2017_04_17/blob/baseblobservice.py", line 1915, in get_blob_to_stream
if end_range and end_range - start_range < first_get_size:
TypeError: unsupported operand type(s) for -: 'str' and 'str'

# Fixed code
def storage_blob_download_batch(
    client,
    source,
    destination,
    source_container_name,
    pattern=None,
    dryrun=False,
    progress_callback=None,
    max_connections=2,
):
    def _download_blob(blob_service, container, destination_folder, blob_name):
        import os

        # TODO: try catch IO exception
        destination_path = os.path.join(destination_folder, blob_name)
        destination_folder = os.path.dirname(destination_path)
        if not os.path.exists(destination_folder):
            mkdir_p(destination_folder)

        blob = blob_service.get_blob_to_path(
            container,
            blob_name,
            destination_path,
            max_connections=max_connections,
            progress_callback=progress_callback,
        )
        return blob.name

    source_blobs = list(collect_blobs(client, source_container_name, pattern))

    if dryrun:
        logger = get_logger(__name__)
        logger.warning("download action: from %s to %s", source, destination)
        logger.warning("    pattern %s", pattern)
        logger.warning("  container %s", source_container_name)
        logger.warning("      total %d", len(source_blobs))
        logger.warning(" operations")
        for b in source_blobs:
            logger.warning("  - %s", b)
        return []

    return list(
        _download_blob(client, source_container_name, destination, blob)
        for blob in source_blobs
    )