diff --git a/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/FileJs.kt b/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/FileJs.kt index b6fb890..e8ba9a6 100644 --- a/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/FileJs.kt +++ b/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/FileJs.kt @@ -18,28 +18,28 @@ package io.matthewnelson.kmp.file import io.matthewnelson.kmp.file.internal.* import io.matthewnelson.kmp.file.internal.errorCode -@DelicateFileApi +// @Throws(IOException::class) public fun File.lstat(): Stats = try { Stats(fs_lstatSync(path)) } catch (t: Throwable) { throw t.toIOException() } -@DelicateFileApi +// @Throws(IOException::class) public fun File.stat(): Stats = try { Stats(fs_statSync(path)) } catch (t: Throwable) { throw t.toIOException() } -@DelicateFileApi +// @Throws(IOException::class) public fun File.read(): Buffer = try { Buffer(fs_readFileSync(path)) } catch (t: Throwable) { throw t.toIOException() } -@DelicateFileApi +// @Throws(IOException::class) public fun File.write(data: Buffer) { try { fs_writeFileSync(path, data.value) @@ -48,7 +48,6 @@ public fun File.write(data: Buffer) { } } -@DelicateFileApi public fun Throwable.toIOException(): IOException { if (this is IOException) return this diff --git a/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/Wrappers.kt b/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/Wrappers.kt index 145fd31..57ce706 100644 --- a/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/Wrappers.kt +++ b/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/Wrappers.kt @@ -27,7 +27,6 @@ import io.matthewnelson.kmp.file.internal.fs_Stats * println(buffer.unwrap()) * * */ -@DelicateFileApi public value class Buffer internal constructor( internal val value: buffer_Buffer ) { @@ -69,7 +68,6 @@ public value class Buffer internal constructor( } } -@DelicateFileApi public value class Stats internal constructor( private val value: fs_Stats ) { diff --git a/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/internal/JsPlatform.kt b/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/internal/JsPlatform.kt index 1937fe8..5ab1e40 100644 --- a/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/internal/JsPlatform.kt +++ b/library/file/src/jsMain/kotlin/io/matthewnelson/kmp/file/internal/JsPlatform.kt @@ -43,7 +43,6 @@ internal actual val IsWindows: Boolean by lazy { } } -@OptIn(DelicateFileApi::class) @Suppress("NOTHING_TO_INLINE") internal actual inline fun File.platformReadBytes(): ByteArray = try { val buffer = read() @@ -61,7 +60,6 @@ internal actual inline fun File.platformReadBytes(): ByteArray = try { throw t.toIOException() } -@OptIn(DelicateFileApi::class) @Suppress("NOTHING_TO_INLINE") internal actual inline fun File.platformReadUtf8(): String = try { val buffer = read() @@ -79,7 +77,6 @@ internal actual inline fun File.platformReadUtf8(): String = try { throw t.toIOException() } -@OptIn(DelicateFileApi::class) @Suppress("NOTHING_TO_INLINE") internal actual inline fun File.platformWriteBytes(array: ByteArray) { try { @@ -89,7 +86,6 @@ internal actual inline fun File.platformWriteBytes(array: ByteArray) { } } -@OptIn(DelicateFileApi::class) @Suppress("NOTHING_TO_INLINE") internal actual inline fun File.platformWriteUtf8(text: String) { try { @@ -125,7 +121,6 @@ internal actual fun fs_chmod(path: String, mode: String) { try { fs_chmodSync(path, mode) } catch (t: Throwable) { - @OptIn(DelicateFileApi::class) throw t.toIOException() } } @@ -146,7 +141,6 @@ internal actual fun fs_remove(path: String): Boolean { fs_rmdirSync(path, Options.Remove(force = true, recursive = false)) true } catch (t: Throwable) { - @OptIn(DelicateFileApi::class) throw t.toIOException() } } @@ -165,7 +159,6 @@ internal actual fun fs_realpath(path: String): String { return try { fs_realpathSync(path) } catch (t: Throwable) { - @OptIn(DelicateFileApi::class) throw t.toIOException() } } diff --git a/library/file/src/jsTest/kotlin/io/matthewnelson/kmp/file/WrapperUnitTest.kt b/library/file/src/jsTest/kotlin/io/matthewnelson/kmp/file/WrapperUnitTest.kt index e29ea6a..f46d1ff 100644 --- a/library/file/src/jsTest/kotlin/io/matthewnelson/kmp/file/WrapperUnitTest.kt +++ b/library/file/src/jsTest/kotlin/io/matthewnelson/kmp/file/WrapperUnitTest.kt @@ -17,7 +17,6 @@ package io.matthewnelson.kmp.file import kotlin.test.* -@OptIn(DelicateFileApi::class) class WrapperUnitTest { @Test diff --git a/library/file/src/mingwMain/kotlin/io/matthewnelson/kmp/file/internal/MingwFs.kt b/library/file/src/mingwMain/kotlin/io/matthewnelson/kmp/file/internal/MingwFs.kt index bb70139..4432ae4 100644 --- a/library/file/src/mingwMain/kotlin/io/matthewnelson/kmp/file/internal/MingwFs.kt +++ b/library/file/src/mingwMain/kotlin/io/matthewnelson/kmp/file/internal/MingwFs.kt @@ -19,7 +19,6 @@ package io.matthewnelson.kmp.file.internal import io.matthewnelson.kmp.file.FileNotFoundException import io.matthewnelson.kmp.file.IOException -import io.matthewnelson.kmp.file.DelicateFileApi import io.matthewnelson.kmp.file.errnoToIOException import kotlinx.cinterop.ByteVar import kotlinx.cinterop.CPointer @@ -43,7 +42,7 @@ import platform.posix.rmdir internal actual fun fs_chmod(path: String, mode: String) { /* no-op */ } @Throws(IOException::class) -@OptIn(DelicateFileApi::class, ExperimentalForeignApi::class) +@OptIn(ExperimentalForeignApi::class) internal actual fun fs_remove(path: String): Boolean { if (remove(path) == 0) return true @@ -60,7 +59,7 @@ internal actual fun fs_platform_mkdir( ): Int = mkdir(path) @Throws(IOException::class) -@OptIn(DelicateFileApi::class, ExperimentalForeignApi::class) +@OptIn(ExperimentalForeignApi::class) internal actual fun fs_realpath( path: String, ): String { diff --git a/library/file/src/nativeMain/kotlin/io/matthewnelson/kmp/file/FileNative.kt b/library/file/src/nativeMain/kotlin/io/matthewnelson/kmp/file/FileNative.kt index 032383e..2e7bebe 100644 --- a/library/file/src/nativeMain/kotlin/io/matthewnelson/kmp/file/FileNative.kt +++ b/library/file/src/nativeMain/kotlin/io/matthewnelson/kmp/file/FileNative.kt @@ -65,6 +65,14 @@ public inline fun File.fOpen( return result } +/** + * Reads the contents of [FILE] into provided ByteArray. + * + * When return value is: + * - Negative: error, check [errno] + * - 0: no more data to read (break) + * - Positive: [buf] was filled with that much data starting from 0 + * */ @DelicateFileApi @ExperimentalForeignApi public fun CPointer.fRead( @@ -73,6 +81,14 @@ public fun CPointer.fRead( fs_platform_fread(this, pinned.addressOf(0), buf.size) } +/** + * Writes [buf] to [FILE] + * + * When return value is: + * - Negative: error, check [errno] + * - 0: wrote no data (break) + * - Positive: Amount of data from [buf] written. + * */ @DelicateFileApi @ExperimentalForeignApi public fun CPointer.fWrite( @@ -83,7 +99,6 @@ public fun CPointer.fWrite( fs_platform_fwrite(this, pinned.addressOf(offset), len) } -@DelicateFileApi @ExperimentalForeignApi public fun errnoToIOException(errno: Int): IOException { val message = strerror(errno)?.toKString() ?: "errno: $errno" diff --git a/library/file/src/nativeTest/kotlin/io/matthewnelson/kmp/file/ChmodNativeUnitTest.kt b/library/file/src/nativeTest/kotlin/io/matthewnelson/kmp/file/ChmodNativeUnitTest.kt index 895ede4..413752a 100644 --- a/library/file/src/nativeTest/kotlin/io/matthewnelson/kmp/file/ChmodNativeUnitTest.kt +++ b/library/file/src/nativeTest/kotlin/io/matthewnelson/kmp/file/ChmodNativeUnitTest.kt @@ -21,7 +21,6 @@ import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue -@OptIn(DelicateFileApi::class) class ChmodNativeUnitTest: ChmodBaseTest() { @Test diff --git a/library/file/src/nativeTest/kotlin/io/matthewnelson/kmp/file/NativeTestPlatform.kt b/library/file/src/nativeTest/kotlin/io/matthewnelson/kmp/file/NativeTestPlatform.kt index 7635554..0991a34 100644 --- a/library/file/src/nativeTest/kotlin/io/matthewnelson/kmp/file/NativeTestPlatform.kt +++ b/library/file/src/nativeTest/kotlin/io/matthewnelson/kmp/file/NativeTestPlatform.kt @@ -15,11 +15,7 @@ **/ package io.matthewnelson.kmp.file -import kotlinx.cinterop.ExperimentalForeignApi -import platform.posix.F_OK -import platform.posix.X_OK import platform.posix.access -import platform.posix.errno import kotlin.experimental.ExperimentalNativeApi actual val isJvm: Boolean = false @@ -36,7 +32,6 @@ actual val isSimulator: Boolean by lazy { } @Throws(IOException::class, IndexOutOfBoundsException::class) -@OptIn(DelicateFileApi::class, ExperimentalForeignApi::class) fun File.checkAccess(vararg access: Int): Boolean { if (!exists()) throw FileNotFoundException() diff --git a/library/file/src/nonJvmMain/kotlin/io/matthewnelson/kmp/file/File.kt b/library/file/src/nonJvmMain/kotlin/io/matthewnelson/kmp/file/File.kt index 83888cb..fbcafa2 100644 --- a/library/file/src/nonJvmMain/kotlin/io/matthewnelson/kmp/file/File.kt +++ b/library/file/src/nonJvmMain/kotlin/io/matthewnelson/kmp/file/File.kt @@ -47,7 +47,6 @@ public actual class File: Comparable { * @throws [IOException] if [mode] is inappropriate * @throws [FileNotFoundException] if the file does not exist * */ - @DelicateFileApi @Throws(IOException::class) public fun chmod(mode: String) { fs_chmod(realPath, mode) } diff --git a/library/file/src/unixMain/kotlin/io/matthewnelson/kmp/file/internal/UnixFs.kt b/library/file/src/unixMain/kotlin/io/matthewnelson/kmp/file/internal/UnixFs.kt index b2d66c8..6858d18 100644 --- a/library/file/src/unixMain/kotlin/io/matthewnelson/kmp/file/internal/UnixFs.kt +++ b/library/file/src/unixMain/kotlin/io/matthewnelson/kmp/file/internal/UnixFs.kt @@ -24,7 +24,7 @@ import kotlinx.cinterop.* import platform.posix.* @Throws(IOException::class) -@OptIn(DelicateFileApi::class, ExperimentalForeignApi::class) +@OptIn(ExperimentalForeignApi::class) internal actual fun fs_chmod(path: String, mode: String) { val modeT = try { Mode(value = mode).toModeT() @@ -39,7 +39,7 @@ internal actual fun fs_chmod(path: String, mode: String) { } @Throws(IOException::class) -@OptIn(DelicateFileApi::class, ExperimentalForeignApi::class) +@OptIn(ExperimentalForeignApi::class) internal actual fun fs_remove(path: String): Boolean { val result = remove(path) if (result != 0) { @@ -50,7 +50,7 @@ internal actual fun fs_remove(path: String): Boolean { } @Throws(IOException::class) -@OptIn(DelicateFileApi::class, ExperimentalForeignApi::class) +@OptIn(ExperimentalForeignApi::class) internal actual fun fs_realpath(path: String): String { val real = realpath(path, null) ?: throw errnoToIOException(errno)