From 8069ea2f0b441351f761b283a8dc7bc9fd734f61 Mon Sep 17 00:00:00 2001 From: Kirill Grachev Date: Mon, 24 Apr 2023 00:36:33 +0300 Subject: [PATCH] SNRK-67: Add top-level function --- .../space/kscience/snark/storage/local/LocalDriver.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/local/LocalDriver.kt b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/local/LocalDriver.kt index bb76118..d75db16 100644 --- a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/local/LocalDriver.kt +++ b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/local/LocalDriver.kt @@ -6,6 +6,10 @@ import space.kscience.snark.storage.FileWriter import java.io.File import java.nio.file.Path +public fun localStorage(rootPath: Path): Directory { + return LocalDirectory(rootPath, ".") +} + public class LocalFile(private val path: String) : FileReader, FileWriter { override fun close() {} override suspend fun readAll(): ByteArray = File(this.path).readBytes() @@ -13,7 +17,7 @@ public class LocalFile(private val path: String) : FileReader, FileWriter { override suspend fun write(bytes: ByteArray) = File(this.path).writeBytes(bytes) } -public class LocalDirectory(private val root: String, private val path: String) : Directory { +public class LocalDirectory(private val root: Path, path: String) : Directory { private val current = "$root/$path" private fun child(child: String): String = "$current/$child"