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:)Creates a new buffered multipart writer with the specified boundary.
Instance Properties
boundaryBoundary string used to separate parts in the multipart data.
Instance Methods
finish()Writes the final boundary to the multipart data.getResult()Retrieves the buffered result and clears the internal buffer.write(bytes:)Writes the given bytes to the multipart data.writePart(_:)Writes a complete multipart part including boundary, headers, and body.
Relationships
Conforms To
MultipartWriterSwift.SendableSwift.SendableMetatype