Format files

This commit is contained in:
Kirill Grachev 2023-05-06 21:32:17 +03:00
parent 793218b6bc
commit 8225501488
5 changed files with 12 additions and 10 deletions

View File

@ -1,7 +1,7 @@
package space.kscience.snark.storage
import java.nio.file.Path
import kotlin.io.path.*
import kotlin.io.path.Path
public interface Directory : AutoCloseable {
// get file from subtree

View File

@ -3,7 +3,6 @@ package space.kscience.snark.storage.local
import space.kscience.snark.storage.Directory
import space.kscience.snark.storage.FileReader
import space.kscience.snark.storage.FileWriter
import java.lang.Exception
import java.nio.file.Path
import kotlin.io.path.*

View File

@ -5,7 +5,7 @@ import space.kscience.snark.storage.Directory
import space.kscience.snark.storage.FileReader
import space.kscience.snark.storage.FileWriter
import java.nio.file.Path
import kotlin.io.path.*
import kotlin.io.path.div
internal class S3Directory(
private val client: S3Client,

View File

@ -8,11 +8,11 @@ import aws.smithy.kotlin.runtime.content.toByteArray
import space.kscience.snark.storage.FileReader
import space.kscience.snark.storage.FileWriter
import java.nio.file.Path
import kotlin.io.path.*
internal class S3FileReader(private val client: S3Client, private val bucketName: String, private val path: Path) : FileReader {
internal class S3FileReader(private val client: S3Client, private val bucketName: String, private val path: Path) :
FileReader {
override suspend fun readAll(): ByteArray {
val result = client.getObject(GetObjectRequest{
val result = client.getObject(GetObjectRequest {
bucket = bucketName
key = path.toString()
}) {
@ -25,7 +25,8 @@ internal class S3FileReader(private val client: S3Client, private val bucketName
}
}
internal class S3FileWriter(private val client: S3Client, private val bucketName: String, private val path: Path) : FileWriter {
internal class S3FileWriter(private val client: S3Client, private val bucketName: String, private val path: Path) :
FileWriter {
override suspend fun write(bytes: ByteArray) {
client.putObject {
bucket = bucketName

View File

@ -1,12 +1,13 @@
package space.kscience.snark.storage.s3
import aws.sdk.kotlin.services.s3.*
import aws.sdk.kotlin.services.s3.S3Client
import aws.sdk.kotlin.services.s3.createBucket
import aws.sdk.kotlin.services.s3.headBucket
import space.kscience.snark.storage.Directory
import space.kscience.snark.storage.FileReader
import space.kscience.snark.storage.FileWriter
import java.lang.Exception
import java.nio.file.Path
import kotlin.io.path.*
import kotlin.io.path.Path
public fun s3Storage(client: S3Client): Directory =
S3Root(client)
@ -56,6 +57,7 @@ internal class S3Root(private val client: S3Client) : Directory {
throw AccessDeniedException(Path(dirname).toFile(), reason = ex.message)
}
@Deprecated("Not a good idea")
override val path: Path
get() = Path("")