<!--
{
  "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/compression_stream_init(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Compression"
    ],
    "preciseIdentifier" : "c:@F@compression_stream_init"
  },
  "title" : "compression_stream_init(_:_:_:)"
}
-->

# compression_stream_init(_:_:_:)

Initializes a compression stream for either compression or decompression.

```
func compression_stream_init(_ stream: UnsafeMutablePointer<compression_stream>, _ operation: compression_stream_operation, _ algorithm: compression_algorithm) -> compression_status
```

## Parameters

`stream`

Pointer to an allocated [`compression_stream`](/documentation/Compression/compression_stream) structure.

`operation`

A constant of type [`compression_stream_operation`](/documentation/Compression/compression_stream_operation) used to indicate the stream operation.

`algorithm`

A constant of type [`compression_algorithm`](/documentation/Compression/compression_algorithm) that specifies the compression algorithm.

## Discussion

### Return Value

A value of type [`compression_status`](/documentation/Compression/compression_status), interpreted as follows:

- [`COMPRESSION_STATUS_OK`](/documentation/Compression/COMPRESSION_STATUS_OK) means the stream object was successfully initialized.
- [`COMPRESSION_STATUS_ERROR`](/documentation/Compression/COMPRESSION_STATUS_ERROR) means an error occurred.

## Discussion

After success of this function, set the `dst_ptr`, `dst_size`, `src_ptr`, and `src_size` fields of the stream structure to their respective values. You can then pass stream structure to the [`compression_stream_process(_:_:)`](/documentation/Compression/compression_stream_process(_:_:)) function.

---

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)