How to embed data within an executable?

Gary Willoughby dev at nomad.so
Sun Feb 2 09:45:36 PST 2014


On Sunday, 2 February 2014 at 17:17:14 UTC, bearophile wrote:
> Gary Willoughby:
>
>> How do you access that at runtime?
>
> In the usual ways. A hex string is just a different kind of 
> literal for a string (so if you need hex data you need to cast 
> it, unfortunately). The mixin(import("...")) can import 
> anything, including your base64 data, that you can convert at 
> compile-time or run-time in what you need.
>
> Bye,
> bearophile

Ah right i see what you mean. Something like this:

template embed(string file)
{
	private string getData()
	{
		return Base64.encode(cast(ubyte[])import(file));
	}

	enum embed = getData();
}


More information about the Digitalmars-d-learn mailing list