Change default buffer size to be 8K (same default as in java BufferedReader).
Rename internal constants.
This commit is contained in:
@@ -5,14 +5,13 @@ package kotlin.io
|
|||||||
/**
|
/**
|
||||||
* Returns the default buffer size when working with buffered streams.
|
* Returns the default buffer size when working with buffered streams.
|
||||||
*/
|
*/
|
||||||
|
public const val DEFAULT_BUFFER_SIZE: Int = 8 * 1024
|
||||||
public const val DEFAULT_BUFFER_SIZE: Int = 64 * 1024
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the default block size for forEachBlock().
|
* 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().
|
* Returns the minimum block size for forEachBlock().
|
||||||
*/
|
*/
|
||||||
internal const val minimumBlockSize: Int = 512
|
internal const val MINIMUM_BLOCK_SIZE: Int = 512
|
||||||
@@ -102,7 +102,7 @@ public fun File.appendText(text: String, charset: Charset = Charsets.UTF_8): Uni
|
|||||||
*
|
*
|
||||||
* @param action function to process file blocks.
|
* @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.
|
* 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.
|
* @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 {
|
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)
|
val fis = FileInputStream(this)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user