<!--
{
  "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/withRandomAccessDecompressionStream(readingFrom:allocationLimit:flags:threadCount:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Apple Archive",
      "AppleArchive"
    ],
    "preciseIdentifier" : "s:12AppleArchive0B10ByteStreamC029withRandomAccessDecompressionD011readingFrom15allocationLimit5flags11threadCount_xAC_SiAA0B5FlagsVSixACKXEtKlFZ"
  },
  "title" : "withRandomAccessDecompressionStream(readingFrom:allocationLimit:flags:threadCount:_:)"
}
-->

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

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

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

The result of the closure.

## Discussion

This function opens a stream created by [`randomAccessDecompressionStream(readingFrom:allocationLimit:flags:threadCount:)`](/documentation/AppleArchive/ArchiveByteStream/randomAccessDecompressionStream(readingFrom:allocationLimit:flags:threadCount:)), calls the specified closure, and closes the stream.

---

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)