From 88b3d278803f5211bda8d53c7b85fb2bb0623a2b Mon Sep 17 00:00:00 2001 From: Tony Roberts Date: Mon, 4 Apr 2016 18:50:59 +0100 Subject: [PATCH] Use stream position instead of counting read bytes. FileStream.Read returns (bytes read, buffer), not just bytes read as the buffer is passed by reference. This is a bit unintuative, but checking the position is clear and less error prone. --- demo/wordpad.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/demo/wordpad.py b/demo/wordpad.py index ed76a6ee8..300c4a1dd 100644 --- a/demo/wordpad.py +++ b/demo/wordpad.py @@ -316,11 +316,10 @@ def OpenDocument(self): buff = System.Array.CreateInstance(System.Byte, 1024) data = [] - read = -1 - while (read != 0): + while stream.Position < stream.Length: buff.Initialize() - read = stream.Read(buff, 0, 1024) + stream.Read(buff, 0, 1024) temp = Encoding.ASCII.GetString(buff, 0, 1024) data.append(temp)