Data Compression in Swift 3
<p>I was using LZMA data compression in an extension based on <a href="https://gist.github.com/daltheman/4716ec10d6d0f71aba56" rel="nofollow">NSData+Compression.swift</a> which worked totally fine till iOS 10 and auto-conversion to Swift 3. After auto-conversion the class looks like this:</p>

<pre><code>import Compression

extension Data {
static func compress(_ data: Data) -&gt; Data {

    let sourceBuffer = (data as NSData).bytes.bindMemory(to: UInt8.self, capacity: data.count)
    let sourceBufferSize = data.count

    let destinationBuffer = UnsafeMutablePointer&lt;UInt8&gt;.allocate(capacity: sourceBufferSize)
    let destinationBufferSize = sourceBufferSize

    let status = compression_encode_buffer(destinationBuffer, destinationBufferSize, sourceBuffer, sourceBufferSize, nil, COMPRESSION_LZMA)

    if status == 0 {
        print("Error with status: \(status)")
    }
    print("Original size: \(sourceBufferSize) | Compressed size: \(status)")
    return Data(bytesNoCopy: UnsafeMutablePointer&lt;UInt8&gt;(destinationBuffer), count: status, deallocator: .free)
}
}
</code></pre>

<p>Now the output of the method is always empty with a compressed size of 0. Can you help me finding out whats wrong with this code? </p>