import tempfile


def wrap_binhex(func):
    """
    Convert a function
        f(in_filename, out_filename)
    to
        out_bytes = f(in_bytes)
    """

    def new_func(in_bytes):
        in_file = tempfile.NamedTemporaryFile()
        in_file.write(in_bytes)
        in_file.seek(0)
        out_file = tempfile.NamedTemporaryFile()
        func(in_file.name, out_file.name)
        out_file.seek(0)
        out_bytes = out_file.read()
        return out_bytes

    return new_func