Search code examples
c++embedded-resource

Accessing embedded resource as "a file"


I'm trying to glue together two libraries where lib1 is providing scripts to lib2. The libraries are used in c++11 code I'm writing. I can't modify those libs.

Scripts in lib1 are embedded into the shared object with https://github.com/vector-of-bool/cmrc.

The content of each script can be accessed with an iterator, like so

cmrc::embedded_filesystem fs=cmrc::hpo::get_filesystem()
auto script1 = fs.open("script1")
# use iterator for script1...

However, lib2 function requires 'physical' file: void file(const char *);

I know I can dump content from lib1 iterator to a temp file, read it with lib2 and then remove the file. This solution sounds rather sub optimal and I'm looking for a better way.


Solution

  • While named pipes are usually used for inter-process communication, they also work intra-process. And on many Operating Systems, including Windows, they have a name that's part of the file system namespace. Hence you can usually pass a pipe name to libraries which expect file names.