On Monday, 16 October 2017 at 05:34:13 UTC, Ky-Anh Huynh wrote:
Hello,
I want to use some static contents in my program, e.g, a CSS
file, a long listing. To help deployment process I'd like to
have them embedded in the final binary file.
Is there any convenient way to support this? Maybe I need a
tool/library to load file contents and generate D-code at
run-time ?
Thanks for your reading.
import can do this, basically it gives you an array that you can
cast to ubyte[] for binary too, be careful with enums though,
because enum arrays will allocate every time you access it
string data = import("strings.txt");
more
https://dlang.org/spec/expression.html#import_expressions
However for security reasons it only looks in folders which you
pass with -J flag
or with dub using "stringImportPaths"
http://code.dlang.org/package-format?lang=json