Skip to content

You're viewing documentation for a pre-release version. View the latest stable version

Structure

MultipartParserAsyncSequence

A sequence that parses a stream of multipart data into parts asynchronously.
struct MultipartParserAsyncSequence<BackingSequence> where BackingSequence : AsyncSequence, BackingSequence.Element : RangeReplaceableCollection, BackingSequence.Element : Sendable, BackingSequence.Element.Element == UInt8

Overview

This sequence is designed to be used with AsyncStream to parse a stream of data asynchronously. Different to the StreamingMultipartParserAsyncSequence, this sequence will collate the body chunks into one section rather than yielding them individually.

Each part’s body therefore arrives as a single .bodyChunk section, which is convenient when parts are small enough to hold in memory. For large parts, such as file uploads, prefer StreamingMultipartParserAsyncSequence, which never holds a whole body at once.

let sequence = MultipartParserAsyncSequence(boundary: "boundary123", buffer: stream)

for try await section in sequence {
    switch section {
    case .headerFields(let fields): print(fields)
    case .bodyChunk(let body): print(String(decoding: body, as: UTF8.self))
    case .boundary: break
    }
}

Topics

Structures

  • struct AsyncIterator
    An iterator over the sections of a multipart message, with each part’s body collated.

Initializers

Instance Methods

Relationships

Conforms To

  • _Concurrency.AsyncSequence