I have the same issue when I'm working with downloaded HTTP data. Long lines of text are hard to break up using a while loop, especially if you're analyzing the file for html tags b/c if you break them up at the wrong point some tags may be still left in there.

P.S: If you think that's hard, try working with POSTdata files - in order to tell where each file in that list started I actually had to have it read a set amount, then read that minus 25 in position, then minus 50, then minus 75 before going on to read the next section of data lol. Now that was some crazy stuff! (Analyzing lengths of binary for certain values is not quite easy)