title: Extract zlib compressed data from binary file in python
body: <p>My company uses a legacy file format for Electromiography data, which is no longer in production. However, there is some interest in maintaining retro-compatibility, so I am studying the possibility to write a reader for that file format.</p>
  
  <p>By analyzing a very convoluted former source code written in Delphi, the file reader/writer uses ZLIB, and inside a HexEditor it looks like there is a file header in binary ASCII (with fields like "Player", "Analyzer" readily readable), followed by a compressed string containing raw data.</p>
  
  <p>My doubt is: how should I proceed in order to identify:</p>
  
  <ul>
  <li>If it is a compressed stream;</li>
  <li>Where does the compressed stream start and where does it end;</li>
  </ul>
  
  <p>From Wikipedia:</p>
  
  <blockquote>
    <p>zlib compressed data is typically written with a gzip or a zlib
    wrapper. The wrapper encapsulates the raw DEFLATE data by adding a
    header and trailer. This provides stream identification and error
    detection</p>
  </blockquote>
  
  <p>Is this relevant?</p>
  
  <p>I'll be glad to post more information, but I don't know what would be most relevant.</p>
  
  <p>Thanks for any hint.</p>
  
  <p>EDIT: I have the working application, and can use it to record actual data of any time length, getting files even smaller than 1kB if necessary.</p>
  
  <hr>
  
  <p>Some sample files:</p>
  
  <p>A freshly created one, without datastream: <a href="https://dl.dropbox.com/u/4849855/Mio_File/HeltonEmpty.mio" rel="nofollow">https://dl.dropbox.com/u/4849855/Mio_File/HeltonEmpty.mio</a></p>
  
  <p>The same as above after a very short (1 second?) datastream has been saved: <a href="https://dl.dropbox.com/u/4849855/Mio_File/HeltonFilled.mio" rel="nofollow">https://dl.dropbox.com/u/4849855/Mio_File/HeltonFilled.mio</a></p>
  
  <p>A different one, from a patient named "manco" instead of "Helton", with an even shorter stream (ideal for Hex viewing): <a href="https://dl.dropbox.com/u/4849855/Mio_File/manco_short.mio" rel="nofollow">https://dl.dropbox.com/u/4849855/Mio_File/manco_short.mio</a></p>
  
  <p>Instructions: each file should be the file of a patient (a person). Inside these files, one or more exams are saved, each exam consisting of one or more time series. The provided files contain only one exam, with one data series.</p>