Embed files into binary.

Pie? via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 5 20:11:32 PDT 2016


On Monday, 6 June 2016 at 02:34:07 UTC, Adam D. Ruppe wrote:
> On Monday, 6 June 2016 at 02:05:09 UTC, Pie? wrote:
>> 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.
>
> They might do that for certain special cases, but 
> import("file.whatever") just drops the file content in memory 
> and you can then access it as an array.
>
>> Because D allows such an embedding feature, maybe the file 
>> system should allow working with this concept?
>
> Why do you need it through the file system? If you're writing 
> the code, just use the array in memory. If it is external, see 
> if the library offers something like that.
>
> DLL and exe are a special case, most things don't need to be 
> physical files.

Because, as I said, if I'm working with pre-exiting modules that 
work with file, I have to provide a file or modify the source.

e.g., how could I do this easily with your read in your png 
module? It takes a file..

/// Easily reads a png file into a MemoryImage
MemoryImage readPng(string filename) {
	import std.file;
	return imageFromPng(readPng(cast(ubyte[]) read(filename)));

recognize the code?

Of course, like I said, it can be modified in this case, but that 
means nothing in general.



More information about the Digitalmars-d-learn mailing list