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 AsyncIteratorAn iterator over the sections of a multipart message, with each part’s body collated.
Initializers
init(boundary: String, buffer: BackingSequence)Creates a sequence that parses the multipart message carried bybuffer.
Instance Methods
func makeAsyncIterator() -> MultipartParserAsyncSequence<BackingSequence>.AsyncIteratorCreates an iterator over the sections of the message.
Relationships
Conforms To
_Concurrency.AsyncSequence