@@ -273,6 +273,7 @@ def _list_outputs(self):
273273
274274class GunzipInputSpec (BaseInterfaceInputSpec ):
275275 in_file = File (exists = True , mandatory = True )
276+ compress = traits .Bool (default_value = False )
276277
277278
278279class GunzipOutputSpec (TraitedSpec ):
@@ -298,17 +299,28 @@ class Gunzip(BaseInterface):
298299
299300 def _gen_output_file_name (self ):
300301 _ , base , ext = split_filename (self .inputs .in_file )
301- if ext [- 3 :].lower () == ".gz" :
302- ext = ext [:- 3 ]
302+
303+ if self .inputs .compress :
304+ ext += ".gz"
305+ else :
306+ if ext [- 3 :].lower () == ".gz" :
307+ ext = ext [:- 3 ]
308+
303309 return os .path .abspath (base + ext )
304310
305311 def _run_interface (self , runtime ):
306312 import gzip
307313 import shutil
308314
309- with gzip .open (self .inputs .in_file , "rb" ) as in_file :
310- with open (self ._gen_output_file_name (), "wb" ) as out_file :
311- shutil .copyfileobj (in_file , out_file )
315+ if self .inputs .compress :
316+ with open (self .inputs .in_file , "rb" ) as in_file :
317+ with gzip .open (self ._gen_output_file_name (), "wb" ) as out_file :
318+ shutil .copyfileobj (in_file , out_file )
319+ else :
320+ with gzip .open (self .inputs .in_file , "rb" ) as in_file :
321+ with open (self ._gen_output_file_name (), "wb" ) as out_file :
322+ shutil .copyfileobj (in_file , out_file )
323+
312324 return runtime
313325
314326 def _list_outputs (self ):
0 commit comments