Skip to content

Instantly share code, notes, and snippets.

@rfdickerson
Created April 12, 2016 00:09
Show Gist options
  • Select an option

  • Save rfdickerson/a59ff08e80e48ba6bcd4049bbd0fc04f to your computer and use it in GitHub Desktop.

Select an option

Save rfdickerson/a59ff08e80e48ba6bcd4049bbd0fc04f to your computer and use it in GitHub Desktop.
zLib Compression
typealias Byte = UInt8
let size: Int = 100000
var simpleData = [Byte](repeating: 3, count: size)
var dataCompressed = [Byte](repeating: 6, count: size)
simpleData[3] = 2
simpleData[4] = 1
var sizeDataCompressed: uLongf = 0
let result = compress2( &dataCompressed, &sizeDataCompressed,
&simpleData, uLong(size), Z_BEST_SPEED )
switch result {
case Z_OK:
print("Everything's OK")
case Z_BUF_ERROR:
print("Buffer error")
default:
print("Some other error")
}
print("Size after compression is: \(sizeDataCompressed)")
@rfdickerson

Copy link
Copy Markdown
Author

It builds and runs, but result is always -5 which means the destination buffer is not large enough to store the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment