Skip to content

Commit

Permalink
Multiplatform file reading
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonMeep committed Sep 9, 2022
1 parent f961402 commit a9c771b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/commonMain/kotlin/com/libermall/tnt/Utility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ fun ContentData.flatten(): ByteArray = when (this) {
is ContentData.Snake -> this.data.flatten()
is ContentData.Chunks -> TODO("chunky content data")
}

expect fun readFileAsString(file: String): String
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ import com.libermall.tnt.model.CollectionModel
import com.libermall.tnt.model.MintableModel
import com.libermall.tnt.model.SpecModel
import com.libermall.tnt.model.StandaloneItemModel
import com.libermall.tnt.readFileAsString
import com.libermall.tnt.toSafeBounceable
import com.libermall.tnt.toSafeUnbounceable
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import mu.KLogging
import org.koin.core.component.KoinComponent
import org.koin.core.component.inject
Expand All @@ -47,7 +48,6 @@ import org.ton.cell.Cell
import org.ton.cell.CellBuilder
import org.ton.lite.client.LiteClient
import org.ton.tlb.storeTlb
import java.io.File

class MintCommand : CliktCommand(
name = "mint",
Expand All @@ -62,7 +62,7 @@ class MintCommand : CliktCommand(
@OptIn(ExperimentalSerializationApi::class)
val spec by argument().convert {
try {
Json.decodeFromStream<SpecModel>(File(it).inputStream())
Json.decodeFromString<SpecModel>(readFileAsString(it))
} catch (e: Exception) {
logger.warn(e, {})
throw e
Expand Down
24 changes: 24 additions & 0 deletions src/jvmMain/kotlin/com/libermall/tnt/readFileAsString.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* (T)ON (N)FT (T)ool - all-in-one utility to work with NFTs on The Open Network
* Copyright (c) 2022
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.libermall.tnt

import java.io.File

actual fun readFileAsString(file: String): String =
File(file).readText()

0 comments on commit a9c771b

Please sign in to comment.