Skip to content

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

Instance Properties

  • boundary
    The 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

Relationships

Conforms To