scoop:scoop.http.asyncio:0.1.0
src/multipart/body.scoop
Selected production source · src/multipart/body.scoop
1
package scoop.http.asyncio3
import scoop.asyncio.*4
import scoop.platform.memory.NativeByteBuffer6
/**7
* The current multipart part body, ending at its boundary rather than at transport EOF.8
*/9
public class MultipartBody internal constructor(private val reader: MultipartReader) : AsyncByteSource, AsyncCloseable {10
internal var complete: Boolean = false11
internal var closed: Boolean = false12
internal var data: Array<Byte> = Array<Byte>(0L) { _ -> 0.toByte() }13
internal var offset: Long = 0L14
/**15
* Whether this body or message reached its successful boundary.16
*/17
public val isComplete: Boolean get() = complete18
/**19
* Whether this body or message has been closed.20
*/21
public val isClosed: Boolean get() = closed || reader.io.isClosed22
/**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 discarded28
* 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 behavior33
* 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 }38
}