-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support more generic stream input #162
Comments
Sorry for taking so long to respond, but this is a great suggestion. I essentially had to rewrite it so it could support processing parsing data from This was accomplished by creating the If you want to play around, you can see if |
Hi Vincent, I would like to echo Matt and thank you for your excellent library. I was curious about how you were able to read from a gzipped file? Unfortunately, using an istream in the constructor of the CSVReader does not work since the move constructor is protected for istreams. Any help would be greatly appreciated |
Hi Vincent, I have played around, trying to adapt the StreamParser to work with std::istream. The move part is easy: initialize a member reference rather than moving the stream. And works when the actual stream is file. But I'm afraid to face a more fundamental problem now. A generic stream input should also support pipes, such that you can consume CVS data from a decompression filter or similar source. But in case of pipes std::istream::tellg will not report anything useful other than pos_type(-1), and StreamParser::next will not be able to determine base class IBasicCSVParser::source_size upfront, but result in zero. It immediately "declares" EOF and terminates, even without catching the error of tellg. Is the logic of IBasicCSVParser intended to work with implementations, where data would need to be processed before knowing the final source size? |
First, thanks for an excellent library. It seems to be the best in class.
CSVReader
has a templated stream constructor where the template parameter can be derived from astd::istream
. As the documentation suggests, this works well withstd::stringstream
andstd::ifstream
. However, it can't be used withstd::istream
itself, or certain other derived streams. I think this is because it tries to move the stream into theStreamParser
, so the code doesn't compile if the stream doesn't support this.It would be incredibly useful to be able to use the parser with more generic streams, giving users the ability to read from compressed files. For example, this might be via the
gzip_decompressor
or thebzip2_decompressor
inboost::iostreams
. Reading from a gzip compressed CSV file is trivial in languages like Python. It's also a common requirement given how inefficient it can be to store a lot of data in a CSV file.It seems as though the parser can almost support this already, so it probably doesn't need significant changes.
The text was updated successfully, but these errors were encountered: