Csvhelper: Keep track of the amount written to, and read from a stream

Created on 1 Jun 2020  路  1Comment  路  Source: JoshClose/CsvHelper

Quite simply, there are times when you are reading and writing large csv files from streams that don't support length or position, and there is a need to know how much has been committed or extracted to, or from the stream.

The particular use case i have is, that i have records streaming to me, and I need to stream them to a csv, that needs to stream them to HttpContent that is essentially a NetworkStream (all without keeping the in memory, or buffering them to file).

There is limit on request size, so i need to progressively serialize the csv content to the NetworkStream and make a new request when a certain threshold is met. Since this data is enumerating progressively, then in-turn writing to a NetworkStream there is no way to know how much data has been sent so that a new requests can be made with the remaining payload.

It would be nice if the Reader and Writer had a simple field that held the actual amount bytes written/read to/from a stream without relying on the base stream length or position, as for some streams this is not available.

There are work arounds to this, however i think it shouldn't be too difficult to hold a byte count in the readers and writers (though i haven't fully got my head around the mechanics of the code, ill have a look tonight)

feature

Most helpful comment

Ahh... false alarm, i found parser.BytePosition

>All comments

Ahh... false alarm, i found parser.BytePosition

Was this page helpful?
0 / 5 - 0 ratings