Structure
BufferedMultipartWriter
A
MultipartWriter that buffers data up to a specified capacity before forwarding to an underlying writer.struct BufferedMultipartWriter<UnderlyingWriter> where UnderlyingWriter : MultipartWriter
Overview
This writer acts as a buffer between your application and another writer implementation, helping to optimize memory usage and improve performance when dealing with large multipart messages. It accumulates data until a threshold is reached, then forwards the buffered content to the underlying writer and clears its internal buffer.
// Example: Create a buffered writer with 8KB capacity that writes to a socket
var writer = BufferedMultipartWriter(
boundary: "boundary123",
bufferCapacity: 8192,
underlyingWriter: SocketMultipartWriter(socket: mySocket)
)
// Use the writer as normal - buffering happens automatically
try await writer.writePart(myPart)
try await writer.finish()
Topics
Initializers
init(boundary:buffer:bufferCapacity:underlyingWriter:)Creates a new buffered multipart writer with a user-supplied buffer.init(boundary:bufferCapacity:underlyingWriter:)Creates a new buffered multipart writer.
Instance Properties
boundaryThe boundary string used to separate multipart parts.
Instance Methods
finish(writingEndBoundary:)If the buffer has not been emptied by the last write, flushes the final part of the message to the underlying writer.write(bytes:)Writes bytes to the buffer, flushing to the underlying writer if capacity is reached.
Type Aliases
BufferedMultipartWriter.OutboundBodyThe type of the body element that the writer will produce.
Relationships
Conforms To
MultipartWriterSwift.SendableSwift.SendableMetatype