title: Why does recompressing a file using gzip produces a different output?
body: <p>I need to decompress, edit, and then recompress a Minecraft .dat file. However after recompression the file changes significantly (without any editing on my side) which makes it unreadable for the game.</p>
  <p>Here's the snippet of code I use to decompress,</p>
  <pre><code>import gzip
  import shutil
  with gzip.open('file_1.dat', 'rb') as f_in:
      with open('file_1.txt', 'wb') as f_out:
          shutil.copyfileobj(f_in, f_out)
  </code></pre>
  <p>and here's the code I use to compress the file:</p>
  <pre><code>with open('file_1.txt', 'rb') as f_in2:
      with gzip.open('file_1_recmp.dat', 'wb') as f_out2:
          shutil.copyfileobj(f_in2, f_out2)
  </code></pre>
  <p>Here are the <a href="https://filebin.net/ppgfoqh8iw7r3ld6" rel="nofollow noreferrer">before and after files</a>.</p>
  <p>So, what am I doing wrong?</p>