Skip to content

Commit 347c4b4

Browse files
authored
Merge pull request #2564 from effigies/fix/gunzip
FIX/TEST: Gunzip cleanup and test
2 parents fda8fa1 + 6a98617 commit 347c4b4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

nipype/algorithms/misc.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,21 +266,32 @@ class GunzipOutputSpec(TraitedSpec):
266266

267267
class Gunzip(BaseInterface):
268268
"""Gunzip wrapper
269+
270+
>>> from nipype.algorithms.misc import Gunzip
271+
>>> gunzip = Gunzip(in_file='tpms_msk.nii.gz')
272+
>>> res = gunzip.run()
273+
>>> res.outputs.out_file # doctest: +ELLIPSIS
274+
'.../tpms_msk.nii'
275+
276+
.. testcleanup::
277+
278+
>>> os.unlink('tpms_msk.nii')
269279
"""
270280
input_spec = GunzipInputSpec
271281
output_spec = GunzipOutputSpec
272282

273283
def _gen_output_file_name(self):
274284
_, base, ext = split_filename(self.inputs.in_file)
275-
if ext[-2:].lower() == ".gz":
285+
if ext[-3:].lower() == ".gz":
276286
ext = ext[:-3]
277-
return os.path.abspath(base + ext[:-3])
287+
return os.path.abspath(base + ext)
278288

279289
def _run_interface(self, runtime):
280290
import gzip
291+
import shutil
281292
with gzip.open(self.inputs.in_file, 'rb') as in_file:
282293
with open(self._gen_output_file_name(), 'wb') as out_file:
283-
out_file.write(in_file.read())
294+
shutil.copyfileobj(in_file, out_file)
284295
return runtime
285296

286297
def _list_outputs(self):

0 commit comments

Comments
 (0)