import json
import codecs


def encode_blob(data):
    """ Encode a dictionary to a base64-encoded compressed binary blob.

    :param data:    data to encode into a blob
    :type data:     dict
    :returns:       The data as a compressed base64-encoded binary blob
    """
    blob_data = json.dumps(data).encode('utf8')
    for codec in ('zlib', 'base64'):
        blob_data = codecs.encode(blob_data, codec)
    return blob_data.replace(b'\n', b'')