iseki
10/13/2025, 2:18 PMbyteCount large than Int.MAX_VALUE ? The code from Kotlinx.io
The second important, how to do zero-copy? Of course I can't access the internal data structure of the Buffer.
override fun write(
source: Buffer,
byteCount: Long
) {
require(byteCount >= 0L) { "byteCount: $byteCount" }
require(source.size >= byteCount) { "source.size=${source.size} < byteCount=$byteCount" }
check(!closed) { "closed" }
val allContent = source.readByteArray(byteCount.toInt())
// Copy bytes from that segment into the file.
val bytesWritten = allContent.usePinned { pinned ->
variantFwrite(pinned.addressOf(0), byteCount.toUInt(), file).toLong()
}
if (bytesWritten < byteCount) {
throwIOExceptionForErrno("file write")
}
}jw
10/13/2025, 2:23 PMUnsafeBufferOperations. There hasn't really been focus on improving the file API since then.