import io


def make_buffer(cls=io.BytesIO, initial_value=None, name=None, noclose=False):
    """
    Construct a new in-memory file object aka "buf".

    :param cls: Class of the file object. Meaningful values are BytesIO and StringIO.
    :param initial_value: Passed directly to the constructor, this is the content of the returned buffer.
    :param name: Associated file path. Not assigned if is None (default).
    :param noclose: If True, disables the .close function.
    :return: Instance of `cls`.
    """
    buf = cls(initial_value) if initial_value else cls()
    if name is not None:
        buf.name = name
    if noclose:
        buf.close = lambda: None
    return buf