Skip to content

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.

let boundary = "boundary123"
var message = ArraySlice(...)
let stream = AsyncStream { continuation in
var offset = message.startIndex
    while offset < message.endIndex {
        let endIndex = min(message.endIndex, message.index(offset, offsetBy: 16))
        continuation.yield(message[offset..<endIndex])
        offset = endIndex
    }
    continuation.finish()
}
let sequence = MultipartParserAsyncSequence(boundary: boundary, buffer: stream)
for try await part in sequence {
    switch part {
    case .bodyChunk(let chunk): ...
    case .headerFields(let field): ...
    case .boundary: break
}

Topics

Structures

Initializers

Instance Methods

  • makeAsyncIterator()
    Creates the asynchronous iterator that produces elements of this asynchronous sequence.

Relationships

Conforms To

  • _Concurrency.AsyncSequence