- Platform: SDK 1.11.1 on Linux/Windows10
(not tested on device, because I haven't it yet)
Strange inconsistent behavior
When a file is 16 MB or larger, seek() does not seem to move the file pointer to the correct location.
The location specified by seek() does not match the result of tell().
This problem occurs only when the location specified by seek() is an odd number of bytes.
Reproduction Ex
- testfile.txt (newline: LF)
[LF] (firstline is newline only:1byte)
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
.
.
.
Over16MB
- testfile.txt structure
0
[LF]
1 54
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ[LF]
55 108
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ[LF]
109 162
abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ[LF]
.
.
.
- code(pseudo code)
file = playdate.file.open(testfile.txt, playdate.file.kFileRead)
LOOP begin
linenum = linenum+1
offset = [give position of "a" at eachline:0, 1, 55, 109, 163, 217, 271...]
file:seek(offset)
print("seek".."["..linenum.."]:"..offset)
location = file:tell()
print("tell:"..location)
[file:readline() & drawText()]
LOOP end
- console output
seek[1]:0
tell:0
seek[2]:1
tell:1
seek[3]:55
tell:55
seek[4]:109
tell:109
seek[5]:163
tell:163
seek[6]:217
tell:217
seek[7]:271
tell:271
.
.
.
seek[310687]:16776991
tell:16776991
seek[310688]:16777045
tell:16777045
seek[310689]:16777099
tell:16777099
seek[310690]:16777153
tell:16777153
seek[310691]:16777207
tell:16777207
seek[310692]:16777261 <--Over16MB(16777216) & odd byte
tell:16777260 <- * doesn't match to seek() value (-1)
seek[310693]:16777315
tell:16777316 <- * doesn't match to seek() value (+1)
seek[310694]:16777369
tell:16777368 <- * doesn't match to seek() value (-1)
seek[310695]:16777423
tell:16777424 <- * doesn't match to seek() value (+1)
.
.
.
-
top of file
-
location around 16MB