Skip to content

Commit 9019e02

Browse files
committed
ENH: Enable compression with Gunzip interface
1 parent b410d08 commit 9019e02

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

nipype/algorithms/misc.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def _list_outputs(self):
273273

274274
class GunzipInputSpec(BaseInterfaceInputSpec):
275275
in_file = File(exists=True, mandatory=True)
276+
compress = traits.Bool(default_value=False)
276277

277278

278279
class 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

Comments
 (0)