title: Compress and decompress zlib (RFC 1950) using DEFLATE (RFC 1951) functions
body: <p>On iOS 13 and macOS 10.15 Apple ships some nice functions to compress and decompress in one line of code.</p>
  
  <p>However they only support DEFLATE (RFC 1951) and I have data compressed with ZLIB (RFC 1950).</p>
  
  <p>I have experimentally found that if I remove the first 2 bytes then decompress works:</p>
  
  <pre class="lang-swift prettyprint-override"><code>let output = try NSData(data: input[2...]).decompressed(using: .zlib)
  </code></pre>
  
  <p>Is this a reliable method?</p>
  
  <p>For compression I've tried adding a 2 byte header:</p>
  
  <pre class="lang-swift prettyprint-override"><code>let output = try Data([0x78, 0x9c]) + input.compressed(using: .zlib)
  </code></pre>
  
  <p>This works in a few simple cases but definitely fails in others. Is there any way to make this work?</p>