schovi / baked_file_system

Virtual File System for Crystal language. Embedding your assets into final binary.
MIT License
177 stars 18 forks source link

calling Process.run on embedded assets #33

Closed harbirg closed 5 years ago

harbirg commented 5 years ago

I'm trying to run an executable that will be embedded into my crystal application. I'm unable to run the following code ->

class FileStorage extend BakedFileSystem bake_folder "../include/" end file = FileStorage.get("path/to/executable") Process.run(file.path)

How do I go about accomplishing this. No issues in reading contents of embedded text files using .gets_to_end

straight-shoota commented 5 years ago

The baked file system is not available to the operating system, so it can't run a baked-in executable. You'll need to copy the file to a file system that's accessible to the OS and then you can execute it.

harbirg commented 5 years ago

Thanks and it makes sense. Would you happen to know methods available to copy contents of a file in the baked file system to disk? I will close this issue out soon after.

straight-shoota commented 5 years ago
File.open(path, "w") do |file|
  IO.copy(baked_file, file)
end
harbirg commented 5 years ago

Thanks. Closing this out.