File tree Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Expand file tree Collapse file tree 1 file changed +7
-12
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ def __new__( # type: ignore
80
80
suffix = pathlib .PurePath (filename ).suffix .lower ()
81
81
82
82
if suffix == ".gz" :
83
- suffix , filename = LogReader .unzip (filename )
83
+ suffix , filename = LogReader .decompress (filename )
84
84
85
85
try :
86
86
return typing .cast (
@@ -93,21 +93,16 @@ def __new__( # type: ignore
93
93
) from None
94
94
95
95
@staticmethod
96
- def unzip (zipfile : "can.typechecking.StringPathLike" ):
96
+ def decompress (
97
+ filename : "can.typechecking.StringPathLike" ,
98
+ ) -> typing .Tuple [str , typing .IO [typing .Any ]]:
97
99
"""
98
100
Return the suffix and io object of the decompressed file.
99
101
"""
100
- real_suffix = pathlib .Path (zipfile ).suffixes [- 2 ].lower ()
101
- file = gzip .open (zipfile , "rt" )
102
-
103
- # Re-open in binary mode if file not readable.
104
- try :
105
- file .read ()
106
- file .seek (0 )
107
- except UnicodeDecodeError :
108
- file = gzip .open (zipfile , "rb" )
102
+ real_suffix = pathlib .Path (filename ).suffixes [- 2 ].lower ()
103
+ mode = "rb" if real_suffix == ".blf" else "rt"
109
104
110
- return real_suffix , file
105
+ return real_suffix , gzip . open ( filename , mode )
111
106
112
107
113
108
class MessageSync : # pylint: disable=too-few-public-methods
You can’t perform that action at this time.
0 commit comments