Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

binary file to konan.ImmutableBinaryBlob #1819

Closed
msink opened this issue Jul 19, 2018 · 4 comments
Closed

binary file to konan.ImmutableBinaryBlob #1819

msink opened this issue Jul 19, 2018 · 4 comments

Comments

@msink
Copy link
Contributor

msink commented Jul 19, 2018

Currently if I want to embed some binary resource in executable, i need to dump it to something like

val `tetris_all.bmp` = immutableBinaryBlobOf(0x42, 0x4D, 0xF6, .....)

and add to source files.

It works, but IMHO is too complex for this simple task.
Can you please add some command-line and gradle-DSL options to do it directly, without intermediate tetris_all.bmp.kt file?

@joelhandwell
Copy link

joelhandwell commented Aug 5, 2018

Related SO question: https://stackoverflow.com/questions/51697533/how-to-include-text-blob-file-as-resource-to-be-compiled-together-as-executable

@msink so there are no way to do

fun main(arg: Array<String>){
   val text: String = accessResource("hello.txt")
   println(text)
}

for now in Kotlin/Native?

@msink
Copy link
Contributor Author

msink commented Aug 6, 2018

@joelhandwell I do not know, closest is just compile it as String:

val `hello.txt` = """
...textfile...
"""

val text = `hello.txt`

Or as Map:

val __resources = mapOf("hello.txt" to """
...textfile...
""")

val text = __resources["hello.txt"]

@olonho
Copy link
Contributor

olonho commented Aug 6, 2018

Yeah, idea is good, but we not yet sure how it better be done. I see the following options:

  • compiler switch like -binary variable_name,file_path which shall create an top level object
    named variable_name of type BinaryBlob with the content of the provided file
  • Gradle DSL verb, like withBinary {} which produces source code artifact, which could be then linked regularly
  • smth else

@SvyatoslavScherbina
Copy link
Collaborator

According to migrating issue tracking to YouTrack, closing this issue in favour of https://youtrack.jetbrains.com/issue/KT-39194

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants