<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppleArchive",
  "identifier" : "/documentation/AppleArchive/ArchiveByteStream/withCompressionStream(using:writingTo:blockSize:flags:threadCount:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Apple Archive",
      "AppleArchive"
    ],
    "preciseIdentifier" : "s:12AppleArchive0B10ByteStreamC015withCompressionD05using9writingTo9blockSize5flags11threadCount_xAA0bF0V_ACSiAA0B5FlagsVSixACKXEtKlFZ"
  },
  "title" : "withCompressionStream(using:writingTo:blockSize:flags:threadCount:_:)"
}
-->

# withCompressionStream(using:writingTo:blockSize:flags:threadCount:_:)

Calls the given closure with a compression sequential output stream.

```
static func withCompressionStream<E>(using compressionAlgorithm: ArchiveCompression, writingTo compressedStream: ArchiveByteStream, blockSize: Int = (1<<20), flags: ArchiveFlags = [], threadCount: Int = 0, _ body: (ArchiveByteStream) throws -> E) throws -> E
```

## Parameters

`compressionAlgorithm`

The compression algorithm.

`compressedStream`

An output stream that receives compressed data, the operation only calls write methods.

`blockSize`

The compression block size, in bytes.

`flags`

Flags that control the behavior of the operation.

`threadCount`

The number of worker threads that the operation uses, set to `0` for default.

`body`

A closure with the archive byte stream passed as a parameter.

## Return Value

The result of the closure.

---

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)