CsvHelper icon indicating copy to clipboard operation
CsvHelper copied to clipboard

Allow WriteRecord(s) without Header

Open jrowe88 opened this issue 2 years ago • 1 comments

As a developer, I would like to be able to use CsvHelper to export some very large tables. Currently, I will run into out-of-memory errors in the CsvWriter using either WriteRecords() or looping with WriteRecord.

I can avoid an out-of-memory error by batching smaller sets of records. However, it currently seems impossible to have CsvHelper not also write a Header Record with each batch. Internally, it looks like the CsvWriter keeps track of the header being record being written, and if it hasn't been written will automatically write it.

A few things that I thought of were: a) expose the "hasHeaderBeenWritten" variable through a Public property that can be set; b) add a config option; c) make "hasHeaderBeenWritten" a protected variable instead of Private, so I could derive my CustomCsvWriter() relatively easily and set this property.

Or, of course, if I'm missing something, please advise!

jrowe88 avatar Oct 07 '22 16:10 jrowe88

As a developer

Do you write a lot of agile stories? lol

You shouldn't be getting out of memory issues. There is something wrong there. There is an internal buffer that holds at most row size * 2. Do you have rows that are insanely large?

If you're writing to a MemoryStream you definitely could run out, but that's not CsvHelpers issue. If this is the case, you'll need to write to a file first.

JoshClose avatar Oct 07 '22 16:10 JoshClose