tried this but it seems to be wrong: ``` val f...
# kotlin-native
s
tried this but it seems to be wrong:
Copy code
val file = fopen("../data/maps/nexus_prod.wmap", "r")
    file?.let {
        println("INFO: File found ")
        
        fseek(it, 0, SEEK_END)
        val size = ftell(it)
        rewind(it)
        
        val buffer = it.readBytes(size.toInt())

        val reader = Reader(buffer)
        val version = reader.readByte()

        println("Version: $version")
    }
    fclose(file)
m
Copy code
val file = fopen(fileName, "r")
    if (file == null) 
        throw Error("Cannot read file '$fileName'")
    fseek(file, 0, SEEK_END)
    val size = ftell(file)
    rewind(file)
    memScoped {
        val buffer = allocArray<ByteVar>(size)
        fread(buffer, 1, size, file)
        fclose(file)
        return ByteArray(size) { buffer[it] }
    }
❤️ 1
s
works fine, thanks a lot!