// Linux stand-in for the one call filius-ipad makes into Apple's Compression // framework: COMPRESSION_ZLIB is raw DEFLATE (RFC 1951), decoded here by zlib. import CZlib public struct compression_algorithm: Equatable { let rawValue: Int32 } public let COMPRESSION_ZLIB = compression_algorithm(rawValue: 0x205) public func compression_decode_buffer( _ dst: UnsafeMutablePointer, _ dstSize: Int, _ src: UnsafePointer, _ srcSize: Int, _ scratch: UnsafeMutableRawPointer?, _ algorithm: compression_algorithm ) -> Int { var stream = z_stream() guard inflateInit2_(&stream, -15, ZLIB_VERSION, Int32(MemoryLayout.size)) == Z_OK else { return 0 } defer { inflateEnd(&stream) } stream.next_in = UnsafeMutablePointer(mutating: src) stream.avail_in = uInt(srcSize) stream.next_out = dst stream.avail_out = uInt(dstSize) let status = inflate(&stream, Z_FINISH) guard status == Z_STREAM_END || status == Z_OK || status == Z_BUF_ERROR else { return 0 } return Int(stream.total_out) }