title: How can I unpack multi-part archives (zip/rar) in Python?
body: <p>I have a 2 GB archive (prefer .zip or .rar) file in parts (let's assume 100 parts x 20MB), and I am trying to find a way to unpack it properly. I started with a .zip archive; I had files like test.zip, test.z01, test.z02...test.99, etc. When I merge them in Python like this:</p>
  <pre class="lang-py prettyprint-override"><code>for zipName in zips:
       with open(os.path.join(path_to_zip_file, &quot;test.zip&quot;), &quot;ab&quot;) as f:
           with open(os.path.join(path_to_zip_file, zipName), &quot;rb&quot;) as z:
               f.write(z.read())
  </code></pre>
  <p>and then, after merge, unpack it like thod&quot;</p>
  <pre><code>with zipfile.ZipFile(os.path.join(path_to_zip_file, &quot;test.zip&quot;), &quot;r&quot;) as zipObj:
       zipObj.extractall(path_to_zip_file)
  </code></pre>
  <p>I get errors, likr</p>
  <blockquote>
  <p>test.zip file isn't zip file.</p>
  </blockquote>
  <p>So then I tried with a .rar archive. I tried to unpack just the first file to see if my code would intelligently look for and pick up the remaining archive fragments, but it did not. So again I merged the .rar files (just like in the .zip case), and then tried to unpack it by using <code>patoolib</code>:</p>
  <pre><code>patoolib.extract_archive(&quot;test.rar&quot;, outdir=&quot;path here&quot;)
  </code></pre>
  <p>When I do that, I get errors like:</p>
  <blockquote>
  <p>patoolib.util.PatoolError: could not find an executable program to extract format rar; candidates are (rar,unrar,7z)</p>
  </blockquote>
  <p>After some work I figured out that these merged files are corrupted (I copied it and try to unpack normally on windows using WinRAR, and encountered some problems). So I tried other ways to merge for example using <code>cat</code> <code>cat test.part.* &gt;test.rar</code>, but those don't help.</p>
  <p>How can I merge and then unpack these archive files properly in Python?</p>