<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Compression",
  "identifier" : "/documentation/Compression",
  "metadataVersion" : "0.1.0",
  "role" : "Framework",
  "symbol" : {
    "kind" : "Framework",
    "modules" : [
      "Compression"
    ],
    "preciseIdentifier" : "Compression"
  },
  "title" : "Compression"
}
-->

# Compression

Leverage compression algorithms for lossless data compression.

## Overview

The Compression framework enables your app to provide lossless compression when saving or sharing files and data. Compression is a process in which you compress (encode) and decompress (decode) data. For example, a text editor may save its files in a compressed format, and automatically decompress the saved file when the user opens it.

![A flow diagram that illustrates the compression and decompression process. The encoder compresses the original data into the encoded (compressed) data. The decoder decompresses the encoded data into the decompressed data.](images/com.apple.compression/media-4311255@2x.png)

The framework offers two methods of compression:

- *Buffer compression* uses a single-step method for compressing files, making it perfect for use with uncompressed files under 8 MB, or compressed files under 1 MB.
- *Stream compression* uses multiple steps for compressing files, making it ideal for compressing larger files or streamed data, such as an incoming audio signal or downloading files.

To use buffer compression, you compress or decompress the input data with one call to the corresponding function. To learn more about buffer compression, including a walk-through of the code used to encode and decode a string, see <doc://com.apple.documentation/documentation/Accelerate/compressing-and-decompressing-data-with-buffer-compression>.

To use stream compression, you call the compression or decompression function repeatedly to compress or decompress data from a source buffer to a destination buffer. Between calls, the compressor or decompressor moves processed data out of the source buffer and loads new data into the destination buffer. To learn more about stream compression, see the sample code project <doc://com.apple.documentation/documentation/Accelerate/compressing-and-decompressing-files-with-stream-compression>.

## Topics

### Objects that simplify multiple-step compression

Simplify encoding and decoding streams of data using Compression classes for Swift.

  <doc://com.apple.documentation/documentation/Accelerate/compressing-and-decompressing-data-with-input-and-output-filters>

  <doc://com.apple.documentation/documentation/Accelerate/compressing-and-decompressing-files-with-stream-compression>

[`InputFilter`](/documentation/Compression/InputFilter)

An encoder-decoder that reads input data from a stream.

[`OutputFilter`](/documentation/Compression/OutputFilter)

An encoder-decoder that writes output data to a stream.

[`Algorithm`](/documentation/Compression/Algorithm)

Algorithms used for compression or decompression.

[`FilterError`](/documentation/Compression/FilterError)

Errors that occur during compression.

[`FilterOperation`](/documentation/Compression/FilterOperation)

Operations that define whether input and output filters compress or decompress data.

### Multiple-step compression

Stream compression functions compress or decompress sequential blocks of data.

[`compression_stream`](/documentation/Compression/compression_stream)

A structure representing a compression stream.

[`compression_stream_init`](/documentation/Compression/compression_stream_init(_:_:_:))

Initializes a compression stream for either compression or decompression.

[`compression_stream_process`](/documentation/Compression/compression_stream_process(_:_:))

Performs compression or decompression using an initialized compression stream structure.

[`compression_stream_destroy`](/documentation/Compression/compression_stream_destroy(_:))

Frees any memory allocated by stream initialization function.

[`compression_status`](/documentation/Compression/compression_status)

A set of values used to represent the status of stream compression.

[`compression_stream_flags`](/documentation/Compression/compression_stream_flags)

A set of values used to represent stream compression flags.

[`compression_stream_operation`](/documentation/Compression/compression_stream_operation)

A set of values used to represent a stream compression operation.

[`compression_algorithm`](/documentation/Compression/compression_algorithm)

A structure for values that represent compression algorithms.

### Single-step compression

Buffer compression functions compress or decompress a block of data stored contiguously in memory.

  <doc://com.apple.documentation/documentation/Accelerate/compressing-and-decompressing-data-with-buffer-compression>

[`compression_encode_scratch_buffer_size`](/documentation/Compression/compression_encode_scratch_buffer_size(_:))

Returns the required compression scratch buffer size for the selected algorithm.

[`compression_encode_buffer`](/documentation/Compression/compression_encode_buffer(_:_:_:_:_:_:))

Compresses the contents of a source buffer into a destination buffer.

[`compression_decode_scratch_buffer_size`](/documentation/Compression/compression_decode_scratch_buffer_size(_:))

Returns the required decompression scratch buffer size for the selected algorithm.

[`compression_decode_buffer`](/documentation/Compression/compression_decode_buffer(_:_:_:_:_:_:))

Decompresses the contents of a source buffer into a destination buffer.

[`compression_algorithm`](/documentation/Compression/compression_algorithm)

A structure for values that represent compression algorithms.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)