Is there a way to run .blend file from text format

I was try to figure out how to make a script in blender game to open blender file read the text than start it from the text. with this code.

import bge

path=bge.logic.expandPath("//")

file=open(str(path+"file_to_open.blend"))
data=file.read()
bge.logic.startGame(data)

Sorry if do not get back right away.

Thanks in advance.

Well, you can LibLoad a blend loaded in memory as bytes instead of a file, but to start a the game you need a blend file.
See this answer to see how to LibLoad from bytes in memory, maybe it can help you.

Use bge.logic.LibLoad(path + file_name, Scene, load_scripts=True/False, load_actions=True/False, async=true/False) this is function load stand alone blend file in you working game, you need checking finish load blend file or make delay for ending load, because uploading file and objects this file not use in frame calling function LibLoad()

I tried lib load it won’t work cause it crashes a lot. I want it to open something like a byte array stored in a text file. So it will be half way encoded so others can’t use it.

Sorry i don’t really wont to use libLoad because of the problems it gives me like when i replace currentScene with the loaded scene it just crashes. I would like to find a way with just using startGame() function only with the byte array without having to save the file to disk.

Well, it seems that LibLoad is the only way to achieve what you intend to. But what’s your goal, to obfuscate/protect your source files? If so, maybe there’s already a pre-made solution for your problem (such as BPPlayer or BGArmor)…

BPPlayer and BGArmor look like they will work, I’ll give it a try. Maybe i could use python tempfile module to save temporary files which will make it harder to access or use Enigma virtual box to pack everything into one file.