All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.ktor.client.statement.Readers.kt Maven / Gradle / Ivy

Go to download

Ktor is a framework for quickly creating web applications in Kotlin with minimal effort.

There is a newer version: 2.2.4
Show newest version
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.client.statement

import io.ktor.util.*
import io.ktor.utils.io.*
import io.ktor.utils.io.core.*

/**
 * Reads exactly [count] bytes of the [HttpResponse.content].
 */
@OptIn(InternalAPI::class)
public suspend fun HttpResponse.readBytes(count: Int): ByteArray = ByteArray(count).also {
    content.readFully(it)
}

/**
 * Reads the whole [HttpResponse.content] if `Content-Length` is specified.
 * Otherwise, it just reads one byte.
 */
@OptIn(InternalAPI::class)
public suspend fun HttpResponse.readBytes(): ByteArray = content.readRemaining().readBytes()

/**
 * Efficiently discards the remaining bytes of [HttpResponse.content].
 */
@OptIn(InternalAPI::class)
public suspend fun HttpResponse.discardRemaining() {
    content.discard()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy