-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KotlinX IO support & better Ktor support (#31)
- Loading branch information
1 parent
bc8474a
commit 2c2c417
Showing
50 changed files
with
817 additions
and
505 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/commonMain/kotlin/com/ashampoo/kim/common/KotlinIoExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2023 Ashampoo GmbH & Co. KG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.ashampoo.kim.common | ||
|
||
import kotlinx.io.buffered | ||
import kotlinx.io.files.Path | ||
import kotlinx.io.files.SystemFileSystem | ||
import kotlinx.io.readByteArray | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
fun Path.copyTo(destination: Path) { | ||
|
||
require(exists()) { "$this does not exist." } | ||
|
||
val metadata = SystemFileSystem.metadataOrNull(this) | ||
|
||
requireNotNull(metadata) { "Failed to read metadata of $this" } | ||
require(metadata.isRegularFile) { "Source $this must be a regular file." } | ||
|
||
SystemFileSystem.source(this).buffered().use { rawSource -> | ||
SystemFileSystem.sink(destination).buffered().use { sink -> | ||
sink.write(rawSource, metadata.size) | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
fun Path.writeBytes(byteArray: ByteArray) = | ||
SystemFileSystem | ||
.sink(this) | ||
.buffered() | ||
.use { it.write(byteArray) } | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
fun Path.readBytes(): ByteArray = | ||
SystemFileSystem | ||
.source(this) | ||
.buffered() | ||
.use { it.readByteArray() } | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
fun Path.exists(): Boolean = | ||
SystemFileSystem.exists(this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.