<!--
{
  "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/sharedBufferPipe(capacity:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Apple Archive",
      "AppleArchive"
    ],
    "preciseIdentifier" : "s:12AppleArchive0B10ByteStreamC16sharedBufferPipe8capacityAC6output_AC5inputtSgSi_tFZ"
  },
  "title" : "sharedBufferPipe(capacity:)"
}
-->

# sharedBufferPipe(capacity:)

Creates a pair of streams and links them by a shared buffer.

```
static func sharedBufferPipe(capacity: Int) -> (output: ArchiveByteStream, input: ArchiveByteStream)?
```

## Parameters

`capacity`

The size of the internal buffer allocation, in bytes.

## Return Value

A new pair of [`ArchiveByteStream`](/documentation/AppleArchive/ArchiveByteStream) instances on success; `nil` otherwise.

## Discussion

This function creates two [`ArchiveByteStream`](/documentation/AppleArchive/ArchiveByteStream) instances that provide one-way communication between two threads. One thread calls the sequential output stream `output`, and the other thread calls the sequential input stream `input`. The function blocks writing to `output` when the buffer is full, and blocks reading from `input` when the buffer is empty.

If either thread calls [`cancel`](/documentation/AppleArchive/ArchiveHeader/EntryMessageStatus/cancel), the operation aborts both streams, and immediately calls return (without blocking) with an error.

Closing `output`, indicates end-of-file (EOF) and writing additional bytes fails. After the operation reaches EOF and has read all data, the read function on `input` returns `0` to signal EOF.

The operation destroys the underlying buffer after it closes both streams.

---

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)