Skip to content

Commit

Permalink
KTOR-7731 Add implementation for the deprecated FileItem.streamProvid…
Browse files Browse the repository at this point in the history
…er (#4469)
  • Loading branch information
e5l authored Nov 11, 2024
1 parent 52e20f6 commit fda56c2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ktor-http/jvm/src/io/ktor/http/content/MultipartJvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

package io.ktor.http.content

import io.ktor.utils.io.jvm.javaio.*
import java.io.*

/**
* Provides file item's content as an [InputStream]
*/
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("This API uses blocking InputStream. Please use provider() directly.")
public val PartData.FileItem.streamProvider: () -> InputStream get() = error(
"streamProvider is deprecated. Use provider() instead"
)
public val PartData.FileItem.streamProvider: () -> InputStream get() = {
provider().toInputStream()
}
25 changes: 25 additions & 0 deletions ktor-http/jvm/test/io/ktor/tests/http/content/MultipartJvmTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package io.ktor.tests.http.content

import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.utils.io.*
import kotlin.test.*

class MultipartJvmTest {

@Suppress("DEPRECATION")
@Test
fun testStreamProvider() {
val fileItem = PartData.FileItem({ ByteReadChannel(ByteArray(4097) { 1 }) }, {}, Headers.Empty)
val stream = fileItem.streamProvider()

val buffer = ByteArray(4097)
val read = stream.read(buffer)
assertEquals(4097, read)
assertEquals(ByteArray(4097) { 1 }.toList(), buffer.toList())
}
}

0 comments on commit fda56c2

Please sign in to comment.