Closed rgarrison12345 closed 1 year ago
I don't plan on supporting this. The main issue is that it means reading ahead. For some inputs, you are reading forward-only, like a Stream
, where you can't "go back" and re-read the record again. I'd essentially need to store the line in memory and check if it's set each time a record was read. That's not a huge overhead, but it's just more state to keep track of. In many cases, it's faster to open the file once, try to read one record, then reopen and reread it from the beginning, if that's option. You can also implement sticking the first record somewhere and setting/clearing it yourself.
There's also a ton of code in this project for reacting to parsing/conversion errors, skipping rows, etc. It'd be hard to write a HasRecords
boolean that accounted for all those usages. Many production files contain a lot of extra header information and "commented out" lines. In a worst case scenario, such a method could read and skip every record in the file... I don't think anyone would want or anticipate that.
It would be nice to see on the FixedLengthReader and DelimitedReader a boolean property called HasRows similar to DbDataReader to know if the underlying file has any rows before having to call Read/ReadAsync