import zlib


def gzdecode(encoded_data):
    """Decode gzip encoded string
    :type encoded_data: str
    :rtype: str
    """
    # automatically accepts either the zlib or gzip format
    b = 40
    return zlib.decompress(encoded_data, b)


def gzencode(data):
    """Encode with gzip format
    :type data: str
    :rtype: str
    """
    # gzip format
    b = 25
    compressor = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, b)
    return compressor.compress(data) + compressor.flush()
