Skip to content

Commit 3611019

Browse files
authored
Accept PathLike objects (#15)
1 parent a3f237c commit 3611019

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

xtarfile/xtarfile.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from itertools import chain
2+
from os import PathLike, fspath
23
from tarfile import open as tarfile_open
4+
from typing import Union
35

46
from xtarfile.zstd import ZstandardTarfile
57
from xtarfile.lz4 import Lz4Tarfile
@@ -20,7 +22,8 @@
2022
SUPPORTED_FORMATS = frozenset(chain(_HANDLERS.keys(), _NATIVE_FORMATS))
2123

2224

23-
def get_compression(path: str, mode: str) -> str:
25+
def get_compression(path: Union[str, PathLike], mode: str) -> str:
26+
path = fspath(path)
2427
for delim in (':', '|'):
2528
delim_index = mode.rfind(delim)
2629
if delim_index > -1:
@@ -33,7 +36,7 @@ def get_compression(path: str, mode: str) -> str:
3336
return ''
3437

3538

36-
def xtarfile_open(path: str, mode: str, **kwargs):
39+
def xtarfile_open(path: Union[str, PathLike], mode: str, **kwargs):
3740
compression = get_compression(path, mode)
3841

3942
if not compression or compression in _NATIVE_FORMATS:

0 commit comments

Comments
 (0)