blob: 002f22c7a485f0e0ef5ee7596b67a2239a042302 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
 | "Common file utilities"
from typing import Union
from pathlib import Path
from zipfile import ZipFile, is_zipfile
def open_file(filepath: Union[str, Path]):
    "Transparently open both TSV and ZIP files"
    if not is_zipfile(filepath):
        return open(filepath, encoding="utf-8")
    with ZipFile(filepath, "r") as zfile:
        return zfile.open(zfile.infolist()[0], "r")
 |