Give csv.NewReader your own *bufio.Reader. Regarding (https://pkg.go.dev/pkg/bufio/#NewReaderSize) if the underlying io.Reader is already a *bufio.Reader with a big enough size (and csv.NewReader uses the default 4k), then the underlying reader is used, no new wrapping is introduced.
This way if you use cr := countingReader{Reader:r} br := bufio.NewReader(cr) csvR := csv.NewReader(br) then cr.N - br.Buffered() is the number of bytes read by csv.Reader, the end of the last line read. Hope this helps. Severyn Lisovsky a következőt írta (2020. október 31., szombat, 3:17:26 UTC+1): > Hi, > > I have difficulty counting bytes that were processed by csv.Reader because > it reads from internally created bufio.Reader. If I pass some counting > reader to csv.NewReader it will show not the actual number bytes > "processed" by csv.Reader to receive the output I get calling > csv.Reader.Read method, but the number of bytes copied to bufio.Reader's > buffer internally (some bytes may be read during next csv.Reader.Read call > from the buffer). > > Is there a way I can deal with this issue by not forking encoding/csv > package? > > To give you more high-level picture - I want to split remote csv file to > chunks. Each chunk should be standalone csv file - starting from actual > beginning of the line, ending with newline byte. So I'm trying to do the > following - split file size by the number of chunks, and for each chunk - > skip first bytes up to newline symbol and read to offset+chunkSize+[number > of bytes to the next newline symbol] > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c03c741f-a572-45bf-a503-76ecb61b71d1n%40googlegroups.com.