Loading extra files in TorchScript from libTorch C++

Hi, I would like to know how to load a file included in traced .pt model that was added as an extra file in C++. In this case I save the model with PyTorch and try to load it with C++.
This could be an example (from documentation):

class MyModule(torch.nn.Module):
    def forward(self, x):
        return x + 10

m = torch.jit.script(MyModule())
# Save with extra files
extra_files = torch._C.ExtraFilesMap()
extra_files['module.meta'] = 'metadata'
torch.jit.save(m, 'scriptmodule.pt', _extra_files=extra_files)

module.meta could be a text file and I would like to read its content when loading model in C++ like this:

#include <torch/torch.h>
#include <torch/script.h>

int main()
{
	torch::jit::script::Module module;
	try
	{
		std::string modulePath = "scriptmodule.pt";
		torch::jit::ExtraFilesMap extraFilesMap_;
		std::pair<std::string, std::string> moduleMeta("module.meta", "");
		extraFilesMap_.insert(moduleMeta);
		module = torch::jit::load(modelPath, torch::kCPU, extraFilesMap_);
		module.eval();
        for (auto const& fileMap : extraFilesMap_)
		{
			std::cout << fileMap.first << std::endl;
			std::cout << fileMap.second << std::endl;
		}
        //How could open and read the content of the file "module.meta"
	}
	catch (const std::exception& e)
	{
		const std::string errorMsg = e.what();
		std::cerr << " Error: " << errorMsg << std::endl;
	}
    return 0;
 }

From here, extraFilesMap_ when doing iteration will print fileMap.first = module.meta and fileMap.second = metadata

How could I read that extra file content?

Thanks in advance

Please take a look at this
β€˜https://github.com/pytorch/pytorch/blob/22401b850b2010119d3f674f495b7c2b2dfb710b/test/cpp/jit/test_save_load.cpp#L16’

It seems to me that the extra_files can store string only.
If you want more info, please change the category to β€˜jit’, jit people can provide more info.

Thanks for your response @glaringlee I have seen that the test is only for retrieving the std::pair<std::string, std::string> from extraFilesMap. I will change the category for trying to find more help for this.

Check my answer here at stackoverflow. I wrote a code that works for me loading 2 double variables on c++ that were saved with extra_files on python with PyTorch.

Thanks for your reply!, It gives me an example of how to use it