How to include a data file in a chrome app for a n

2019-05-23 12:03发布

问题:

If I have a chrome packaged app that also includes a PNaCl/NaCl module, is there a way to include in the packaged app some data files, which the NaCl module will then read in?

I don't need to do any file writing, just to include some data files that the native module needs to make use of.

回答1:

The entire contents of your packaged app are available to both JavaScript and NaCl code via http requests.

If you use the nacl_io library then you can also access all the files using standard POSIX file APIs by first mounting the contents of the package somewhere if your virtual filesystem:

e.g:

// Mount the http root at /mnt/package/
mount("/", "/mnt/package/", "httpfs", 0, "");
FILE* f = fopen("/mnt/package/somefile", "r");