Structure
StreamingMultipartParserAsyncSequence
A sequence that parses a stream of multipart data into sections asynchronously.
struct StreamingMultipartParserAsyncSequence<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. The sequence will yield MultipartSection values as they are parsed from the stream.
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 = StreamingMultipartParserAsyncSequence(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
StreamingMultipartParserAsyncSequence.AsyncIteratorThe type of asynchronous iterator that produces elements of this asynchronous sequence.
Initializers
Instance Methods
makeAsyncIterator()Creates the asynchronous iterator that produces elements of this asynchronous sequence.
Relationships
Conforms To
_Concurrency.AsyncSequence