<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Compression",
  "identifier" : "/documentation/Compression/compression_stream",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Compression"
    ],
    "preciseIdentifier" : "c:@SA@compression_stream"
  },
  "title" : "compression_stream"
}
-->

# compression_stream

A structure representing a compression stream.

```
struct compression_stream
```

## Overview

The basic workflow for using the stream interface is as follows:

1. Initialize the state of your [`compression_stream`](/documentation/Compression/compression_stream) structure by calling [`compression_stream_init(_:_:_:)`](/documentation/Compression/compression_stream_init(_:_:_:)) with the `operation` parameter set to specify whether you are encoding or decoding, and the chosen algorithm specified by the `algorithm` parameter.  This allocates storage for the state that allows you to resume encoding or decoding across calls.
2. Set the `dst_buffer`, `dst_size`, `src_buffer`, and `src_size` fields of the [`compression_stream`](/documentation/Compression/compression_stream) object to point to the next blocks that your code processes.
3. Call [`compression_stream_process(_:_:)`](/documentation/Compression/compression_stream_process(_:_:)).  If no further input will be added to the stream via subsequent calls, `flags` should be [`COMPRESSION_STREAM_FINALIZE`](/documentation/Compression/COMPRESSION_STREAM_FINALIZE) (otherwise 0). If [`compression_stream_process(_:_:)`](/documentation/Compression/compression_stream_process(_:_:)) returns [`COMPRESSION_STATUS_END`](/documentation/Compression/COMPRESSION_STATUS_END), there is no further output from the stream.
4. Repeat steps 2 and 3 as necessary to process the entire stream.
5. Call [`compression_stream_destroy(_:)`](/documentation/Compression/compression_stream_destroy(_:)) to free the state object in the stream structure.

## Topics

### Initializers

[`init(dst_ptr:dst_size:src_ptr:src_size:state:)`](/documentation/Compression/compression_stream/init(dst_ptr:dst_size:src_ptr:src_size:state:))

Returns a new compression stream structure.

### Compression Stream Properties

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

A pointer to the first byte of the destination buffer.

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

The size, in bytes, of the destination buffer.

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

A pointer to the first byte of the source buffer.

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

The size, in bytes, of the source buffer.

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

The stream state object of the compression stream.

## Relationships

### Conforms To

[`BitwiseCopyable`](/documentation/Swift/BitwiseCopyable)

---

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)