jegesh / python-random-access-file-reader

Low memory usage random access reader for csv and general files
14 stars 6 forks source link

Position / Line Length Calculation #6

Closed erezvas closed 2 years ago

erezvas commented 5 years ago

It seems to me there's an issue with the calculation of position and line length.

In CsvRandomAccessReader._get_line_data, it should be:

lines.append({"position": start_position, "length": current_line + 1}) start_position += current_line + 1 + len(self._endline)

Instead of :

lines.append({"position": start_position, "length": current_line}) start_position += current_line + 1

Otherwise you're not taking into account the end-of-line character, and not counting the character in the start position in the line length calculation.

jegesh commented 5 years ago

Did you encounter problems because of this? (As they say: If it ain't broke, don't fix it)

erezvas commented 5 years ago

Yeap, it caused me problems. and making this change solved the problems for me.

jegesh commented 5 years ago

Were you perchance running your code on a Windows machine (\n\r line endings)?