---
title: "withCompressionStream(using:writingTo:blockSize:flags:threadCount:_:)"
framework: applearchive
role: symbol
role_heading: Type Method
path: "applearchive/archivebytestream/withcompressionstream(using:writingto:blocksize:flags:threadcount:_:)"
---

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

Calls the given closure with a compression sequential output stream.

## Declaration

```swift
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

Return Value The result of the closure.

## See Also

### Compressing Data

- [compressionStream(using:writingTo:blockSize:flags:threadCount:)](applearchive/archivebytestream/compressionstream(using:writingto:blocksize:flags:threadcount:).md)
- [compressionStream(appendingTo:flags:threadCount:)](applearchive/archivebytestream/compressionstream(appendingto:flags:threadcount:).md)
- [withCompressionStream(appendingTo:flags:threadCount:_:)](applearchive/archivebytestream/withcompressionstream(appendingto:flags:threadcount:_:).md)
