from typing import Union
from pathlib import Path
import gzip


def _get_writer(path: Union[str, Path]):
    """Get the file opener."""
    if isinstance(path, str):
        path = Path(path)
    if path.suffix == ".gz":
        return gzip.open, dict(mode="wt")
    return open, {"mode": "w"}