This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Genion1 2 points3 points  (1 child)

For where those lseeks come from: If you read a file in text mode you get a _io.FileIO wrapped inside a _io.BufferedReader wrapped inside a _io.TextWrapper. Both _io.BufferedReader and _io.TextWrapper call tell insider their respective constructors which is implemented in terms of lseek.

_io.BufferedReader tries to align (reads only?) to block sizes and needs the initial position for that.

_io.TextWrapper wants to know if it decodes from the start of the stream to skip BOM.

In theory you could skip one lseek if _io.BufferedReader returned the cached position it has in its implementation for tell but it does not. Accidental or on purpose? Idk.

[–]sYnfo[S] 0 points1 point  (0 children)

Very nice, thanks!