Skip to content

Commit cc18642

Browse files
committed
Add gzip check to compress method
Addresses @zariiii9003 from #1385 (comment)
1 parent 5f485db commit cc18642

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

can/io/logger.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class Logger(MessageWriter): # pylint: disable=abstract-method
6161
".txt": Printer,
6262
}
6363

64+
incompatible_gzip = [".blf", ".db"]
65+
6466
@staticmethod
6567
def __new__( # type: ignore
6668
cls: Any, filename: Optional[StringPathLike], *args: Any, **kwargs: Any
@@ -105,6 +107,10 @@ def compress(
105107
File will automatically recompress upon close.
106108
"""
107109
real_suffix = pathlib.Path(filename).suffixes[-2].lower()
110+
if real_suffix in Logger.incompatible_gzip:
111+
raise ValueError(
112+
f"The file type {real_suffix} is currently incompatible with gzip."
113+
)
108114
if kwargs.get("append", False):
109115
mode = "ab" if real_suffix == ".blf" else "at"
110116
else:

0 commit comments

Comments
 (0)