Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import io.ktor.http.contentType
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.readUTF8Line
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.serialization.json.Json
import me.devnatan.dockerkt.io.requestCatching
import me.devnatan.dockerkt.models.image.Image
Expand All @@ -36,15 +36,15 @@ public class ImageResource internal constructor(
public suspend fun list(): List<ImageSummary> = httpClient.get("$BasePath/json").body()

public fun pull(image: String): Flow<ImagePull> =
flow {
channelFlow {
httpClient
.preparePost("$BasePath/create") {
parameter("fromImage", image)
}.execute { response ->
val channel = response.body<ByteReadChannel>()
while (true) {
val line = channel.readUTF8Line() ?: break
emit(json.decodeFromString(line))
send(json.decodeFromString(line))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.ktor.client.request.prepareGet
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.readUTF8Line
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.serialization.json.Json
import me.devnatan.dockerkt.io.requestCatching
import me.devnatan.dockerkt.models.system.Event
Expand Down Expand Up @@ -83,7 +83,7 @@ public class SystemResource internal constructor(
* @param options Options to filter the received events.
*/
public fun events(options: MonitorEventsOptions = MonitorEventsOptions()): Flow<Event> =
flow {
channelFlow {
requestCatching {
httpClient
.prepareGet("/events") {
Expand All @@ -95,7 +95,7 @@ public class SystemResource internal constructor(
while (true) {
val raw = channel.readUTF8Line() ?: break
val decoded = json.decodeFromString<Event>(raw)
emit(decoded)
send(decoded)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public actual class ContainerResource(

@JvmSynthetic
public actual fun attach(container: String): Flow<Frame> =
flow {
channelFlow {
httpClient
.preparePost("$BasePath/$container/attach") {
parameter("stream", "true")
Expand All @@ -504,7 +504,7 @@ public actual class ContainerResource(
val line = channel.readUTF8Line() ?: break

// TODO handle stream type
emit(Frame(line, line.length, Stream.StdOut))
send(Frame(line, line.length, Stream.StdOut))
}
}
}
Expand Down
Loading