Scoop API

scoop:scoop.http.asyncio:0.1.0

src/multipart/body.scoop

Selected production source · src/multipart/body.scoop

1package scoop.http.asyncio
3import scoop.asyncio.*
4import scoop.platform.memory.NativeByteBuffer
6/**
7 * The current multipart part body, ending at its boundary rather than at transport EOF.
8 */
9public class MultipartBody internal constructor(private val reader: MultipartReader) : AsyncByteSource, AsyncCloseable {
10 internal var complete: Boolean = false
11 internal var closed: Boolean = false
12 internal var data: Array<Byte> = Array<Byte>(0L) { _ -> 0.toByte() }
13 internal var offset: Long = 0L
14 /**
15 * Whether this body or message reached its successful boundary.
16 */
17 public val isComplete: Boolean get() = complete
18 /**
19 * Whether this body or message has been closed.
20 */
21 public val isClosed: Boolean get() = closed || reader.io.isClosed
22 /**
23 * Reads part bytes up to the current boundary and advances the destination buffer.
24 */
25 public override suspend fun readInto(buffer: NativeByteBuffer, count: Long): Long = reader.read(this, buffer, count)
26 /**
27 * Consumes and discards remaining part bytes up to an explicit limit, returning the discarded
28 * count.
29 */
30 public suspend fun discard(maxBytes: Long): Long = reader.discard(this, maxBytes)
31 /**
32 * Closes this body; unfinished-body cleanup follows the multipart reader's abort behavior
33 * rather than an unbounded drain.
34 */
35 public override suspend fun close() { reader.closeBody(this) }
37 internal fun clear() { data = Array<Byte>(0L) { _ -> 0.toByte() }; offset = 0L }