---
title: "withRandomAccessDecompressionStream(readingFrom:allocationLimit:flags:threadCount:_:)"
framework: applearchive
role: symbol
role_heading: Type Method
path: "applearchive/archivebytestream/withrandomaccessdecompressionstream(readingfrom:allocationlimit:flags:threadcount:_:)"
---

# withRandomAccessDecompressionStream(readingFrom:allocationLimit:flags:threadCount:_:)

Calls the given closure with a decompression random access input stream.

## Declaration

```swift
static func withRandomAccessDecompressionStream<E>(readingFrom compressedStream: ArchiveByteStream, allocationLimit: Int = Int.max, flags: ArchiveFlags = [], threadCount: Int = 0, _ body: (ArchiveByteStream) throws -> E) throws -> E
```

## Parameters

- `compressedStream`: An input stream that provides compressed data.
- `allocationLimit`: The requested memory allocation size, in bytes. Set to 0 for lowest memory footprint or doc://com.apple.documentation/documentation/Swift/Int/max for best performance.
- `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 randomAccessDecompressionStream(readingFrom:allocationLimit:flags:threadCount:), calls the specified closure, and closes the stream.

## See Also

### Decompressing Data

- [decompressionStream(readingFrom:flags:threadCount:)](applearchive/archivebytestream/decompressionstream(readingfrom:flags:threadcount:).md)
- [withDecompressionStream(readingFrom:flags:threadCount:_:)](applearchive/archivebytestream/withdecompressionstream(readingfrom:flags:threadcount:_:).md)
- [randomAccessDecompressionStream(readingFrom:allocationLimit:flags:threadCount:)](applearchive/archivebytestream/randomaccessdecompressionstream(readingfrom:allocationlimit:flags:threadcount:).md)
