title: Accessing files inside a .zip archive without extracting them
body: <p>I am attempting to read a NIFTI file inside a .zip without having to extract the directory to the root directory. More specifically, I am working with the ADNI database and the files are stored by subjectID in individual .zip files. Inside the .zip file there is all the data pertaining to that subject, I would like to extract the NIFTI file (.nii.gz) from within the .zip without extracting the files. </p>
  
  <p>Currently I have the following code snippet</p>
  
  <pre><code>def openNIFTI(filename):
     return nib.load(filename).get_data()
  
  zip_filename = filepath + str(subject_id) + '_3T_Structural_unproc.zip'
  filename = str(subject_id) + '/unprocessed/3T/T1w_MPR1/' + str(subject_id) + '_3T_T1w_MPR1.nii.gz'
  
  file = zf.extract(filename)
  data = openNIFTI(file)
  </code></pre>
  
  <p>The <em>filepath</em> is the path to the collection of .zip files. <em>filename</em> is the path inside the .zip file to the NIFTI file I want to extract.</p>
  
  <hr>
  
  <p>(Edit)</p>
  
  <p>It seem the error is coming from the nibabel load function. Then function checks</p>
  
  <pre><code>if not op.exists(filename):
  </code></pre>
  
  <p>Upon testing the os.path.exists(filename) function independently I found that.</p>
  
  <pre><code>os.path.exists(r'C:/Users/eee/workspace_python/Image Reconstruction/data/ADNI/MRI data/100206_3T_Structural_unproc.zip/100206/unprocessed/3T/T1w_MPR1/100206_3T_T1w_MPR1.nii.gz')
  </code></pre>
  
  <blockquote>
    <p>False</p>
  </blockquote>
  
  <p>However, this path is copy/pasted from the file I am attempting to open. It seems to me the error appears due to the .zip in the file path because</p>
  
  <pre><code>os.path.exists(r'C:/Users/eee/workspace_python/Image Reconstruction/data/ADNI/MRI data/100206_3T_Structural_unproc.zip')
  </code></pre>
  
  <blockquote>
    <p>True</p>
  </blockquote>
  
  <p>Is there another way of doing this?</p>