diff --git a/libraries/stdlib/src/kotlin/io/Constants.kt b/libraries/stdlib/src/kotlin/io/Constants.kt index 0f15a2d58b1..812a598f50d 100644 --- a/libraries/stdlib/src/kotlin/io/Constants.kt +++ b/libraries/stdlib/src/kotlin/io/Constants.kt @@ -5,14 +5,13 @@ package kotlin.io /** * Returns the default buffer size when working with buffered streams. */ - -public const val DEFAULT_BUFFER_SIZE: Int = 64 * 1024 +public const val DEFAULT_BUFFER_SIZE: Int = 8 * 1024 /** * Returns the default block size for forEachBlock(). */ -internal const val defaultBlockSize: Int = 4096 +internal const val DEFAULT_BLOCK_SIZE: Int = 4096 /** * Returns the minimum block size for forEachBlock(). */ -internal const val minimumBlockSize: Int = 512 \ No newline at end of file +internal const val MINIMUM_BLOCK_SIZE: Int = 512 \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/io/FileReadWrite.kt b/libraries/stdlib/src/kotlin/io/FileReadWrite.kt index 1efce324d3c..e00acd97a23 100644 --- a/libraries/stdlib/src/kotlin/io/FileReadWrite.kt +++ b/libraries/stdlib/src/kotlin/io/FileReadWrite.kt @@ -102,7 +102,7 @@ public fun File.appendText(text: String, charset: Charset = Charsets.UTF_8): Uni * * @param action function to process file blocks. */ -public fun File.forEachBlock(action: (ByteArray, Int) -> Unit): Unit = forEachBlock(defaultBlockSize, action) +public fun File.forEachBlock(action: (ByteArray, Int) -> Unit): Unit = forEachBlock(DEFAULT_BLOCK_SIZE, action) /** * Reads file by byte blocks and calls [action] for each block read. @@ -114,7 +114,7 @@ public fun File.forEachBlock(action: (ByteArray, Int) -> Unit): Unit = forEachBl * @param blockSize size of a block, replaced by 512 if it's less, 4096 by default. */ public fun File.forEachBlock(blockSize: Int, action: (ByteArray, Int) -> Unit): Unit { - val arr = ByteArray(if (blockSize < minimumBlockSize) minimumBlockSize else blockSize) + val arr = ByteArray(blockSize.coerceAtLeast(MINIMUM_BLOCK_SIZE)) val fis = FileInputStream(this) try {