MCPcopy Create free account
hub / github.com/dolthub/doltgresql / readLine

Method readLine

core/dataloader/csvreader.go:156–188  ·  view source on GitHub ↗

readLine reads the next line (with the trailing endline). If EOF is hit without a trailing endline, it will be omitted. If some bytes were read, then the error is never io.EOF. The result is only valid until the next call to readLine.

()

Source from the content-addressed store, hash-verified

154// If some bytes were read, then the error is never io.EOF.
155// The result is only valid until the next call to readLine.
156func (csvr *csvReader) readLine() ([]byte, error) {
157 var rawBuffer []byte
158
159 line, err := csvr.bRd.ReadSlice('\n')
160 if err == bufio.ErrBufferFull {
161 rawBuffer = append(rawBuffer[:0], line...)
162 for err == bufio.ErrBufferFull {
163 line, err = csvr.bRd.ReadSlice('\n')
164 rawBuffer = append(rawBuffer, line...)
165 }
166 line = rawBuffer
167 }
168 if len(line) > 0 && err == io.EOF {
169 err = nil
170 // For backwards compatibility, drop trailing \r before EOF.
171 if line[len(line)-1] == '\r' {
172 line = line[:len(line)-1]
173 }
174 }
175 csvr.numLine++
176 // Normalize \r\n to \n on all input lines.
177 if n := len(line); n >= 2 && line[n-2] == '\r' && line[n-1] == '\n' {
178 line[n-2] = '\n'
179 line = line[:n-1]
180 }
181
182 // If the line does NOT end with a newline, then we must have read a partial record
183 if len(line) > 0 && lengthNL(line) == 0 {
184 return nil, &partialLineError{string(line)}
185 }
186
187 return line, err
188}
189
190type recordState struct {
191 line []byte

Callers 3

csvReadRecordsMethod · 0.95
parseQuotedFieldMethod · 0.95
nextRowMethod · 0.80

Calls 1

lengthNLFunction · 0.85

Tested by

no test coverage detected