Skip to content

scan after seek in text files (PR#12640)

1 message · alex at apeironsports.com

#
Full_Name: Dr. Alex Sheppard
Version: 2.7.1
OS: Linux Debian Lenny
Submission from: (NULL) (79.73.224.62)


After scanning from an open (text) connection, then seeking, then scanning
again, the second scan returns incorrect result. It looks like the first byte
scanned was from the pre-seek file position, then it continues to read from the
post-seek file position. 


To reproduce:

#Put 3x3 matrix in a file
#Open file as text
#scan a couple of fields - this looks fine so far
Read 2 items
[1] 1 2

#seek back to start of file
[1] 5

#scan fields again - this doesn't work properly
Read 2 items
[1] 31  2

This happens when either n or nmax arguments are used to control number of
fields read. Problem does not occur when using nlines argument instead. The seek
appears to work ok, as doing readChar(fd,n=1) after the seek operation correctly
returns "1". 
Also, if the file is opened as binary, i.e. fd=file("TEST.txt",open="rb") , all
works fine.