Skip to content

Instantly share code, notes, and snippets.

View zaczh's full-sized avatar

jhzhang zaczh

View GitHub Profile
zaczh / gist:d1e37a2ff7f071191f1c30866d5db0f5
Last active December 4, 2016 02:42
NSData lzfse compress & decompress
extension NSData {
func lzfseCompressed() -> NSData {
let sourceBuffer: UnsafePointer<UInt8> = UnsafePointer<UInt8>(self.bytes.assumingMemoryBound(to: UInt8.self))
let sourceBufferSize: Int = self.length
let destinationBuffer: UnsafeMutablePointer<UInt8> = UnsafeMutablePointer<UInt8>.allocate(capacity: sourceBufferSize)
let destinationBufferSize: Int = sourceBufferSize
let status = compression_encode_buffer(destinationBuffer, destinationBufferSize, sourceBuffer, sourceBufferSize, nil, COMPRESSION_LZFSE)