title: File viewer with sliding buffer
body: <p>I'd like to make a simple text file viewer and I'd like it to be able to handle large files (possibly larger than the computer's memory).</p>
  
  <p>I know that I need to implement something like a sliding buffer, that will contain the currently visible portion of the file. The main problem is to determine the relation between lines and file offsets. If I just needed to be able to navigate by lines, I'd just need an <em>linked list of lines</em> and on line up/line down just read new line from the file. But what should I do when I also want to go to, say 50% of the file? I need to show the lines starting from the half of the file, so if the file is 10000 bytes long, I'd seek to byte 5000, look for a line break and display stuff from there. The problem is, that I don't know what line I'm at when seeking like this. </p>
  
  <p>So what I would like to know is what would be a suitable data structure for keeping these few lines in memory (the ones that will be painted on the screen).</p>
  
  <p>Keep in mind that I don't need to edit the files, just view them, so I don't need to care about efficiency of the chosen approach for editing.</p>