@@ -165,7 +165,7 @@ class _PipedCompressionProgram(io.IOBase):
165
165
Read and write compressed files by running an external process and piping into it.
166
166
"""
167
167
168
- def __init__ ( # noqa: C901
168
+ def __init__ (
169
169
self ,
170
170
filename : FileOrPath ,
171
171
mode = "rb" ,
@@ -199,9 +199,10 @@ def __init__( # noqa: C901
199
199
raise ValueError (
200
200
f"compresslevel must be in { program_settings .acceptable_compression_levels } ."
201
201
)
202
+ self ._compresslevel = compresslevel
202
203
self .fileobj , self .closefd = _file_or_path_to_binary_stream (filename , mode )
203
- filepath = _filepath_from_path_or_filelike (filename )
204
- self .name : str = str (filepath )
204
+ self . _path = _filepath_from_path_or_filelike (filename )
205
+ self .name : str = str (self . _path )
205
206
self ._mode : str = mode
206
207
self ._stderr = tempfile .TemporaryFile ("w+b" )
207
208
self ._threads_flag : Optional [str ] = program_settings .threads_flag
@@ -215,7 +216,10 @@ def __init__( # noqa: C901
215
216
threads = min (_available_cpu_count (), 4 )
216
217
self ._threads = threads
217
218
218
- if threads != 0 and self ._threads_flag is not None :
219
+ self ._open_process ()
220
+
221
+ def _open_process (self ):
222
+ if self ._threads != 0 and self ._threads_flag is not None :
219
223
self ._program_args += [f"{ self ._threads_flag } { self ._threads } " ]
220
224
221
225
# Setting close_fds to True in the Popen arguments is necessary due to
@@ -229,12 +233,12 @@ def __init__( # noqa: C901
229
233
self .in_pipe = None
230
234
self .in_thread = None
231
235
self ._feeding = True
232
- if "r" in mode :
236
+ if "r" in self . _mode :
233
237
self ._program_args += ["-c" , "-d" ] # type: ignore
234
238
stdout = subprocess .PIPE
235
239
else :
236
- if compresslevel is not None :
237
- self ._program_args += ["-" + str (compresslevel )]
240
+ if self . _compresslevel is not None :
241
+ self ._program_args += ["-" + str (self . _compresslevel )]
238
242
stdout = self .fileobj # type: ignore
239
243
try :
240
244
self .process = subprocess .Popen (
@@ -249,7 +253,7 @@ def __init__( # noqa: C901
249
253
self .fileobj .close ()
250
254
raise
251
255
assert self .process .stdin is not None
252
- if "r" in mode :
256
+ if "r" in self . _mode :
253
257
self .in_pipe = self .process .stdin
254
258
# A python subprocess can read and write from pipes, but not from
255
259
# Python in-memory objects. In order for a program to read from an
0 commit comments