MultipartReader

class MultipartReader(source: BufferedSource, val boundary: String) : Closeable

This was copied from OkHttp and slightly modified to work in a Multiplatform project.

Original source: https://github.com/square/okhttp/blob/parent-4.9.2/okhttp/src/main/kotlin/okhttp3/MultipartReader.kt

Reads a stream of RFC 2046 multipart body parts. Callers read parts one-at-a-time until nextPart returns null. After calling nextPart any preceding parts should not be read.

Typical use loops over the parts in sequence:

val response: Response = call.execute()
val multipartReader = MultipartReader(response.body!!)

multipartReader.use {
while (true) {
val part = multipartReader.nextPart() ?: break
process(part.headers, part.body)
}
}

Note that nextPart will skip any unprocessed data from the preceding part. If the preceding part is particularly large or if the underlying source is particularly slow, the nextPart call may be slow!

Closing a part does not close this multipart reader; callers must explicitly close this with close.

Constructors

Link copied to clipboard
fun MultipartReader(source: BufferedSource, boundary: String)

Types

Link copied to clipboard
class Part(val headers: List<HttpHeader>, val body: BufferedSource) : Closeable

A single part in a multipart body.

Functions

Link copied to clipboard
open override fun close()
Link copied to clipboard
fun nextPart(): MultipartReader.Part?

Properties

Link copied to clipboard
val boundary: String