Embed files into binary.

Pie? via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 5 19:22:43 PDT 2016


On Monday, 6 June 2016 at 02:18:48 UTC, docandrew wrote:
> On Monday, 6 June 2016 at 02:05:09 UTC, Pie? wrote:
>> I saw somewhere someone explaining how to embed resources into 
>> a binary using the import keyword.
>>
>> I believe the essentially converted the file into a ubyte or 
>> something and then wrote that out to a temp file and read in 
>> the temp file... this seems a bit of a kludge to me.
>>
>> Is it possible to do the same, but create a sort of "in 
>> memory" file layout?
>>
>> While I can modify my own routines to read the "file" from 
>> memory, I can't do that easily with outside code(I could 
>> modify the binaries).
>>
>> Basically reading a file has to read it to memory, and if the 
>> file data already exists in memory, there is no point to read, 
>> just get it direct.
>>
>> Any thoughts on this?
>>
>> Because D allows such an embedding feature, maybe the file 
>> system should allow working with this concept? That way, it 
>> becomes VERY easy to embed files into the binary and work with 
>> them like they wernt. Also, going between the two different 
>> versions(embedded vs not) could be done with version (Release).
>
> I'm not sure about import, but one option is to put the 
> external files directly in your binary as part of the linker 
> step. Check out:
>
> http://www.linuxjournal.com/content/embedding-file-executable-aka-hello-world-version-5967
>
> On Windows I think there's a way to embed files in .DLLs and 
> then link those into your executable, but I'm ignorant of the 
> steps/tools required.
>
> -Jon

Check out https://p0nce.github.io/d-idioms/ for embedding dll's.

It's much easier than using the link you give.

The problem is the same though, How to use the in memory data 
rather than re-reading it? It's not a problem of embedding but 
that the routines that use the data expect files, not memory 
backed virtual files.



More information about the Digitalmars-d-learn mailing list