Contents

decompressed(using:)

Returns a new data object by decompressing data object’s bytes.

Declaration

func decompressed(using algorithm: NSData.CompressionAlgorithm) throws -> Self

Parameters

  • algorithm:

    An algorithm used to decompress the data. For a list of available algorithms, see Compressionalgorithm.

Return Value

An NSData instance that contains the decompressed buffer data.

Discussion

Use this method to inflate in-memory data when you need uncompressed bytes. Specify the same algorithm used to compress the data to successfully decompress it.

The following example shows how to create a new NSData instance from data compressed with the NSData.CompressionAlgorithm.zlib algorithm:

do {
    let uncompressedData = try compressedData.decompressed(using: .zlib)
} catch {
    print ("Decompression error: \(error)")
}

See Also

Compressing and Decompressing Data