I'm trying to read a UTF8 encoded file (.torrent). In the file there is a 'pieces' section. Directly following that is the length of the text that contains a sequence of SHA1 hashes. The file reports a length (say 130100) to read, but when reading I end up going passed EOF.
I'm not sure why this is happening. The files are good (I've tested them with existing torrent clients and I've tried a number of them with consistent results) and I'm reading them with this:
string contents = string.Empty;
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)
{
using (StreamReader reader = new StreamReader(fs, Encoding.UTF8))
{
contents = reader.ReadToEnd();
}
}
parse(contents);
However, this obviously isn't working. Am I reading the file wrong, or am I storing it in a string incorrectly before trying to parse it? It seems to only fault when it reads characters outside of the normal range of readable strings.