SNRK-67: Add top-level function

This commit is contained in:
Kirill Grachev 2023-04-24 00:36:33 +03:00
parent 88510dbba8
commit 8069ea2f0b

View File

@ -6,6 +6,10 @@ import space.kscience.snark.storage.FileWriter
import java.io.File import java.io.File
import java.nio.file.Path import java.nio.file.Path
public fun localStorage(rootPath: Path): Directory {
return LocalDirectory(rootPath, ".")
}
public class LocalFile(private val path: String) : FileReader, FileWriter { public class LocalFile(private val path: String) : FileReader, FileWriter {
override fun close() {} override fun close() {}
override suspend fun readAll(): ByteArray = File(this.path).readBytes() 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) 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 val current = "$root/$path"
private fun child(child: String): String = "$current/$child" private fun child(child: String): String = "$current/$child"