<!--
{
  "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",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Apple Archive"
    ],
    "preciseIdentifier" : "s:12AppleArchive0B10ByteStreamC"
  },
  "title" : "ArchiveByteStream"
}
-->

# ArchiveByteStream

An archive stream that reads from and writes to buffers.

```
class ArchiveByteStream
```

## Topics

### Creating an Archive Byte Stream

[`init(object: _AAOptionalObjectWrapper<_AAByteStreamTraits>.AAType?, owned: Bool)`](/documentation/AppleArchive/ArchiveByteStream/init(object:owned:))

Returns a new archive byte stream from the specified traits and entry message processing callback.

### Reading and Writing Data

### Using Archive Byte Streams

[`func close(updatingContext: ArchiveEncryptionContext) throws`](/documentation/AppleArchive/ArchiveByteStream/close(updatingContext:))

Closes the stream, releases associated resources, and writes the sealed container attributes to the specified encryption context.

### Compressing Data

[`static func compressionStream(using: ArchiveCompression, writingTo: ArchiveByteStream, blockSize: Int, flags: ArchiveFlags, threadCount: Int) -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/compressionStream(using:writingTo:blockSize:flags:threadCount:))

Creates a compression sequential output stream.

[`static func withCompressionStream<E>(using: ArchiveCompression, writingTo: ArchiveByteStream, blockSize: Int, flags: ArchiveFlags, threadCount: Int, (ArchiveByteStream) throws -> E) throws -> E`](/documentation/AppleArchive/ArchiveByteStream/withCompressionStream(using:writingTo:blockSize:flags:threadCount:_:))

Calls the given closure with a compression sequential output stream.

[`static func compressionStream(appendingTo: ArchiveByteStream, flags: ArchiveFlags, threadCount: Int) -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/compressionStream(appendingTo:flags:threadCount:))

Reopens a compression sequential output stream.

[`static func withCompressionStream<E>(appendingTo: ArchiveByteStream, flags: ArchiveFlags, threadCount: Int, (ArchiveByteStream) throws -> E) throws -> E`](/documentation/AppleArchive/ArchiveByteStream/withCompressionStream(appendingTo:flags:threadCount:_:))

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

### Decompressing Data

[`static func decompressionStream(readingFrom: ArchiveByteStream, flags: ArchiveFlags, threadCount: Int) -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/decompressionStream(readingFrom:flags:threadCount:))

Creates a decompression sequential input stream.

[`static func withDecompressionStream<E>(readingFrom: ArchiveByteStream, flags: ArchiveFlags, threadCount: Int, (ArchiveByteStream) throws -> E) throws -> E`](/documentation/AppleArchive/ArchiveByteStream/withDecompressionStream(readingFrom:flags:threadCount:_:))

Calls the given closure with a decompression sequential input stream.

[`static func randomAccessDecompressionStream(readingFrom: ArchiveByteStream, allocationLimit: Int, flags: ArchiveFlags, threadCount: Int) -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/randomAccessDecompressionStream(readingFrom:allocationLimit:flags:threadCount:))

Creates a decompression random-access input stream.

[`static func withRandomAccessDecompressionStream<E>(readingFrom: ArchiveByteStream, allocationLimit: Int, flags: ArchiveFlags, threadCount: Int, (ArchiveByteStream) throws -> E) throws -> E`](/documentation/AppleArchive/ArchiveByteStream/withRandomAccessDecompressionStream(readingFrom:allocationLimit:flags:threadCount:_:))

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

### Encrypting Data

[`static func encryptionStream(appendingTo: ArchiveByteStream, encryptionContext: ArchiveEncryptionContext, flags: ArchiveFlags, threadCount: Int) -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/encryptionStream(appendingTo:encryptionContext:flags:threadCount:))

Reopens an existing encryption sequential output stream.

[`static func encryptionStream(writingTo: ArchiveByteStream, encryptionContext: ArchiveEncryptionContext, flags: ArchiveFlags, threadCount: Int) -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/encryptionStream(writingTo:encryptionContext:flags:threadCount:))

Creates a encryption sequential input stream.

### Decrypting Data

[`static func decryptionStream(readingFrom: ArchiveByteStream, encryptionContext: ArchiveEncryptionContext, flags: ArchiveFlags, threadCount: Int) -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/decryptionStream(readingFrom:encryptionContext:flags:threadCount:))

Creates a decryption sequential input stream.

[`static func randomAccessDecryptionStream(readingFrom: ArchiveByteStream, encryptionContext: ArchiveEncryptionContext, allocationLimit: Int, flags: ArchiveFlags, threadCount: Int) -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/randomAccessDecryptionStream(readingFrom:encryptionContext:allocationLimit:flags:threadCount:))

Creates a decryption random access input stream.

### Processing Data

[`static func process(readingFrom: ArchiveByteStream, writingTo: ArchiveByteStream) throws -> Int64`](/documentation/AppleArchive/ArchiveByteStream/process(readingFrom:writingTo:))

Processes data between two byte streams.

### File Streaming

[`static func fileStream(fd: FileDescriptor, automaticClose: Bool) -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/fileStream(fd:automaticClose:))

Creates a stream from an open file descriptor.

[`static func withFileStream<E>(fd: FileDescriptor, automaticClose: Bool, (ArchiveByteStream) throws -> E) throws -> E`](/documentation/AppleArchive/ArchiveByteStream/withFileStream(fd:automaticClose:_:))

Calls the given closure with a file stream created from the specified file descriptor.

[`static func fileStream(path: FilePath, mode: FileDescriptor.AccessMode, options: FileDescriptor.OpenOptions, permissions: FilePermissions) -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/fileStream(path:mode:options:permissions:))

Opens a new file descriptor using the given path and parameters, and creates a stream from the file descriptor.

[`static func withFileStream<E>(path: FilePath, mode: FileDescriptor.AccessMode, options: FileDescriptor.OpenOptions, permissions: FilePermissions, (ArchiveByteStream) throws -> E) throws -> E`](/documentation/AppleArchive/ArchiveByteStream/withFileStream(path:mode:options:permissions:_:))

Calls the given closure with a file stream.

[`static func temporaryFileStream() -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/temporaryFileStream())

Creates a new temporary file stream.

[`static func withTemporaryFileStream<E>((ArchiveByteStream) throws -> E) throws -> E`](/documentation/AppleArchive/ArchiveByteStream/withTemporaryFileStream(_:))

Calls the given closure with a temporary file stream.

### Streaming with Custom Streams

[`static func customStream<C>(instance: C) -> ArchiveByteStream?`](/documentation/AppleArchive/ArchiveByteStream/customStream(instance:))

Returns a new archive byte stream instance mapped to an object that conforms to the archive byte stream protocol.

[`static func withStream<C, E>(wrapping: C, (ArchiveByteStream) throws -> E) throws -> E`](/documentation/AppleArchive/ArchiveByteStream/withStream(wrapping:_:))

Calls the given closure with an archive byte stream instance mapped to an object that conforms to the archive byte stream protocol.

[`static func sharedBufferPipe(capacity: Int) -> (output: ArchiveByteStream, input: ArchiveByteStream)?`](/documentation/AppleArchive/ArchiveByteStream/sharedBufferPipe(capacity:))

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

## Relationships

### Conforms To

[`ArchiveByteStreamProtocol`](/documentation/AppleArchive/ArchiveByteStreamProtocol)

---

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)