Reading from an std::istream
Is it possible to parse CSV from an std::istream?
Yes. You'll have to read the stream into a string like:
std::string s(std::istreambuf_iterator<char>(stream), {});
Then, you can use:
Reader<...> reader;
reader.parse(s);
But std::istreambuf_iterator<char> will read the entire stream before passing it to the reader, this will consume a lot of memory because I'm working on an app that process large CSV files and put them into a database.
I see. So you have an ifstream and would like to parse the file contents. If it is a file, currently csv2 supports memory-mapping it for parsing instead of reading from stream because it is significantly faster to do so. If you're looking to not consume memory, I'd recommend you go down that road anyway. csv2 does not allocate during the file parsing at all. Reading from istream is quite a bit slower - primarily because istream::read copies the block of data being read into the input buffer.
The CSV files resides inside a .zip archive, so I have an std::istream derived class that reads from within the archive. Extracting the archive is not practical because the size would be enormous
I see. Okay I'll add a method that can read from std::istream. Thanks for the explanation.