title: Attempt to unpickle a compressed pickle file results in OSError: Invalid data stream
body: <p>I have a <code>compressed pickle</code> pickle file. On several attempts, I have tried to unpickle this file with no success. Here is the code to unpickle the compressed pickle file based on the following resources <a href="https://betterprogramming.pub/load-fast-load-big-with-compressed-pickles-5f311584507e" rel="nofollow noreferrer">here</a>, <a href="https://www.datacamp.com/community/tutorials/pickle-python-tutorial#compressing" rel="nofollow noreferrer">here</a> and <a href="https://gist.github.com/cwidmer/7813392" rel="nofollow noreferrer">here</a>.</p>
  <p>First, I try using the <code>pickle</code> module.</p>
  <pre><code>import bz2
  import pickle
  
  data = bz2.BZ2File('test.gzip', 'rb')
  data = pickle.load(data)
  </code></pre>
  <p>Then, I also try with the <code>cPickle</code> module.</p>
  <pre><code>import bz2
  import _pickle as cPickle
  
  data = bz2.BZ2File('test.gzip', 'rb')
  data = cPickle.load(data)
  </code></pre>
  <p>On both attempts, I get an <code>OSError: Invalid data stream</code> on the <code>load()</code> function. Here's a trace.</p>
  <pre>
  Traceback (most recent call last):
    File "", line 1, in 
    File "C:\Users\jane\Anaconda3\envs\py36\lib\bz2.py", line 172, in peek
      return self._buffer.peek(n)
    File "C:\Users\jane\Anaconda3\envs\py36\lib\_compression.py", line 68, in readinto
      data = self.read(len(byte_view))
    File "C:\Users\jane\Anaconda3\envs\py36\lib\_compression.py", line 103, in read
      data = self._decompressor.decompress(rawblock, size)
  OSError: Invalid data stream
  </pre>
  <p>I thought it may have something to do with my Python environment, but I've tested these snippets of code after create Python environments for Python 3.6, 3.7 and 3.8 in Conda. I still get the same error. I also moved into Ubuntu (WSL) and tried it on a Python 3.8 conda environment, and got the same error.</p>
  <p>Any ideas on what's going on?</p>
  <p>I looked at these SO posts <a href="https://stackoverflow.com/questions/55681295/how-to-unpickle-pickle-extension-file">here</a> and <a href="https://stackoverflow.com/questions/48712164/oserror-invalid-data-stream-to-load-bz2-pickle-pbz2-serialized-pd-datafram">here</a>, but the problems and solutions do not really apply.</p>