def format_bucket_prefix(base_prefix: str, dirname: str) -> str:
    """Format an S3 bucket key prefix by joining a base prefix with a directory
    name.
    """
    base_prefix = base_prefix.rstrip("/").lstrip("/")
    dirname = dirname.lstrip("/")
    prefix = "/".join((base_prefix, dirname))
    if not prefix.endswith("/"):
        prefix = prefix + "/"
    return prefix