📦 Krate-KMP

Enterprise-grade File System Library for Kotlin Multiplatform
A unified, type-safe file system API that works seamlessly across Android, iOS, Desktop, and Web.
✨ Features
📋 Platform Support
📦 Installation
Add the dependency to your build.gradle.kts:
implementation("in.sitharaj.krate:krate:1.0.0")
implementation("in.sitharaj.krate:krate-android:1.0.0")
implementation("in.sitharaj.krate:krate-iosarm64:1.0.0")
implementation("in.sitharaj.krate:krate-desktop:1.0.0")
implementation("in.sitharaj.krate:krate-js:1.0.0")
🚀 Quick Start
Basic Usage
Type-Safe Paths
val path = KrateLocation.documents / "projects" / "myapp" / "config.json"
path.name
path.extension
path.parent
val backup = path.sibling("config.backup.json")
Platform Locations
KrateLocation.appData
KrateLocation.cache
KrateLocation.documents
KrateLocation.temp
📖 API Reference
Read Operations
val bytes: ByteArray = krate.read(path)
val text: String = krate.readText(path)
val bytesOrNull: ByteArray? = krate.readOrNull(path)
Write Operations
krate.write(path, byteArray)
krate.writeText(path, "Hello, World!")
krate.writeText(path, "\nNew line", append = true)
File Operations
val exists: Boolean = krate.exists(path)
val deleted: Boolean = krate.delete(path)
krate.copy(source, destination, overwrite = true)
krate.move(source, destination, overwrite = true)
val metadata: FileMetadata = krate.metadata(path)
Directory Operations
krate.createDirectory(path)
val entries: List<KrateEntry> = krate.list(path)
krate.deleteDirectory(path, recursive = true)
🏗️ Architecture
┌─────────────────────────────────────────────────────────────┐
│ Krate API (Common) │
│ ┌──────────┐ ┌──────────┐ ┌───────────┐ ┌───────────────┐ │
│ │ read() │ │ write() │ │ copy() │ │ list() │ │
│ └──────────┘ └──────────┘ └───────────┘ └───────────────┘ │
├─────────────────────────────────────────────────────────────┤
│ Android │ iOS │ Desktop │ Browser │
│ ────────── │ ──────────── │ ───────── │ ──────── │
│ java.nio.file │ FileManager │ java.nio │ OPFS │
│ SAF support │ Foundation │ Files API │ Modern API │
└─────────────────────────────────────────────────────────────┘
🔧 Advanced Usage
Error Handling
try {
val content = krate.read(path)
} catch (e: KrateException) {
when (e.error) {
KrateError.FILE_NOT_FOUND -> println("File doesn't exist")
KrateError.PERMISSION_DENIED -> println("No permission")
KrateError.IO_ERROR -> println("I/O error occurred")
else -> println("Error: ${e.error}")
}
}
Result-Based API (Coming Soon)
when (val result = krate.readResult(path)) {
is KrateResult.Success -> process(result.value)
is KrateResult.Failure -> handleError(result.error)
}
📄 License
Copyright 2024 Sitharaj Seenivasan
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance the License.
You may obtain a copy of the License at
http:
Unless applicable law agreed to writing, software
distributed under the License distributed an BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express implied.
See the License the specific language governing permissions
limitations under the License.
🔗 Links