---
title: "withCompressionStream(appendingTo:flags:threadCount:_:)"
framework: applearchive
role: symbol
role_heading: Type Method
path: "applearchive/archivebytestream/withcompressionstream(appendingto:flags:threadcount:_:)"
---

# withCompressionStream(appendingTo:flags:threadCount:_:)

Reopens a compression sequential output stream and calls the given closure.

## Declaration

```swift
static func withCompressionStream<E>(appendingTo compressedStream: ArchiveByteStream, flags: ArchiveFlags = [], threadCount: Int = 0, _ body: (ArchiveByteStream) throws -> E) throws -> E
```

## Parameters

- `compressedStream`: The output stream that the function reopens and receives the compressed data.
- `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.

## Discussion

Discussion This function opens a stream created by compressionStream(appendingTo:flags:threadCount:), calls the specified closure, and closes the stream.

## See Also

### Compressing Data

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