Convert Arduino fs:File* into c++ std::File* - c++

it seemed too easy. I stored an xml file on a sdcard connected to my esp32.
I use the SD.open() function to access the files stored on the sdcard. For parsing the xml file I downloaded the tinyxml2 library and tried to use the xmlDocument.LoadFile() function.
The problem is that the xmlDocument.LoadFile function is using a std::File pointer. The SD.open() function return an fs::File pointer.
The resulting error message in my ArduinoIDE is:
No matching function for call to tinyxml2::XMLDocument::LoadFile(fs::File*).
Does anybody has an idea how to convert the fs::File* into std::File*?
Thank you very much!
tinyxml2 lib:tinyxml2 lib

Thank you so much.
as #Galik mentioned, his hint was the key for me. But in the long run #Juraj suggestion to use json the better way.

Related

How to open a gzip file using fopen (or a function with the same return value as fopen) in C++?

I currently have some code reading files which are not compressed, it uses the following approach to read a file in C++
FILE* id = fopen("myfile.dat", "r");
after obtaining id, different parts of the code access the file using fread, fseek, etc.
I would like to adapt my code so as to open a gzip version of the file, e.g. "myfile.dat.gz" without needing to change too much.
Ideally I would implement a wrapper to fopen, call it fopen2, which can read both myfile.dat and myfile.dat.gz, i.e. it should return a pointer to a FILE object, so that the remaining of the code does not need to be changed.
Any suggestions?
Thank you.
PS: it would be fine to decompress the whole file in memory, if this approach provides a solution
zlib provides analogs of fopen(), fread(), etc. called gzopen(), gzread(), etc. for reading and writing gzip files. If the file is not gzip-compressed, it will be read just as the f functions would. So you would only need to change the function names and link in zlib.

Converting FILE * to CMemFile (or retrieving void* from FILE *)

I'm currently working with a function call that uses FILE *, but I need to get data from the FILE * into a buffer without letting the data touch the HDD. My first idea was to convert FILE * to a CMemFile, but I cannot find a way to do this. Any ideas?
Using MFC...
This question comes up from using the JPEG library by IJG whose homepage can be found here: http://www.ijg.org/
You can use setvbuf to make a FILE pointer use a predefined (and filled) buffer.

How to get file type on linux?

I need to get file type without using file extensions on linux. There is "file" utility, which can do this. How can I do the same using C/C++? Not 'system(const char *)', of course... Thanks)
AFAIK file is implemented over libmagic. For more reference see:
file sources
and maybe this link: http://linux.die.net/man/3/libmagic.
Either call file as a child process or emulate what it does. There are no other options if you want to intelligently examine a file's content to guess what it contains.

How to use openssl to base 64 decode?

I am developing in C++ using Boost.Asio. I want to be able to base64 decode data and since Boost.Asio links to openssl I want to use it's functions to do so and not add an extra dependency(eg crypto++). I have found this code here that shows how to do it. (change int finalLen = BIO_read(bmem, (void*)pOut, outLen); to inLen )
I don't know if it works. I just pass to it some test data that I verify with an online decoder found here(2) (select decode safely as text and count the symbols). The test string I use is this one: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" (without the ""). Both the online decoder and a quick crypto++ implementation return 23 chars. But the code I mentioned above using openssl returns 0. Am I doing something wrong? Is openssl suitable for base64 decoding?
Please provide me a solution (if one exists). Thanks for you time.
pff sorry my mistake. I forgot to allocate memory for pOut. The code seems to work now.

TinyXML: how to parse a file pointer

I'm trying to connect the output of popen, a file pointer, to the input of TinyXML.
According to the main page, the best way to do it is using the parse method:
C style input:
* based on FILE*
* the Parse() and LoadFile() methods
I believe I need to use the TIXML_USE_STL to get to this. How do I go about finding examples and import it?
A reply since deleted pointed me in the right direction on the docs
http://www.grinninglizard.com/tinyxmldocs/index.html
Thanks.
Now, i just need to figure out how to link and import it.
I'm not hugely familiar with TinyXML, but does LoadFile() not work in its overloaded version which takes a FILE *?
http://www.grinninglizard.com/tinyxmldocs/classTiXmlDocument.html#a12
EDIT: Ah, the problem is that TinyXML doesn't support reading from a stream (see the link above). Your only choice then is to read the stream manually into a buffer and pass it to TinyXML's Parse().
You can read the file data into some buffer (say SomeCharBuffer), append null terminator to it and do
TiXmlDocument doc;
doc.Parse(SomeCharBuffer);