Structure
MemoryMultipartWriter
A synchronous
MultipartWriter that buffers the output in memory.struct MemoryMultipartWriter<OutboundBody> where OutboundBody : RangeReplaceableCollection, OutboundBody : Sendable, OutboundBody.Element == UInt8
Overview
This writer accumulates all multipart data in an internal buffer, making it suitable for scenarios where you need to generate the complete multipart message before sending. The buffer can be retrieved using getResult() after writing all parts.
var writer = MemoryMultipartWriter<[UInt8]>(boundary: "boundary123")
try await writer.writePart(MultipartPart(
headerFields: [.contentType: "text/plain"],
body: Array("Hello, world!".utf8)
))
try await writer.finish()
let result = writer.getResult()
Topics
Initializers
init(boundary: String)Creates a new buffered multipart writer with the specified boundary.init(boundary: String, buffer: inout OutboundBody)Creates a new buffered multipart writer that writes into an existing buffer.
Instance Properties
let boundary: StringThe boundary separating the parts of the message, without its leading hyphens.
Instance Methods
func finish()Appends the end boundary, terminating the multipart message.func getResult() -> OutboundBodyRetrieves the buffered result and clears the internal buffer.func write(bytes: some Collection<UInt8> & Sendable)Appends the given bytes to the internal buffer.func writePart(MultipartPart<some RangeReplaceableCollection<UInt8> & Sendable>)Appends a complete multipart part: its leading boundary, header fields, and body.
Type Aliases
typealias FailureThisMultipartWriterdoesn’t throw.
Relationships
Conforms To
MultipartWriterSwift.SendableSwift.SendableMetatype