Skip to content

Fix demo stream reading #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix demo stream reading
  • Loading branch information
matthid committed Jun 4, 2016
commit bdced63928bf1ffe9bf151dfef79d873ae4c5b18
9 changes: 5 additions & 4 deletions demo/wordpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,13 @@ def OpenDocument(self):
stream = File.OpenRead(filename)

buff = System.Array.CreateInstance(System.Byte, 1024)
buff.Initialize()
data = []
read = 1

while stream.Position < stream.Length:
buff.Initialize()
stream.Read(buff, 0, 1024)
temp = Encoding.ASCII.GetString(buff, 0, 1024)
while read > 0:
read, _ = stream.Read(buff, 0, 1024)
temp = Encoding.ASCII.GetString(buff, 0, read)
data.append(temp)

data = ''.join(data)
Expand Down
22 changes: 22 additions & 0 deletions src/tests/test_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,28 @@ def test():

self.assertRaises(TypeError, test)

def testWeCanBindToEncodingGetString(self):
"""Check that we can bind to the Encoding.GetString method with variables."""

from System.Text import Encoding
from System.IO import MemoryStream
myBytes = Encoding.UTF8.GetBytes('Some testing string')
stream = MemoryStream()
stream.Write(myBytes, 0, myBytes.Length)
stream.Position = 0

buff = System.Array.CreateInstance(System.Byte, 3)
buff.Initialize()
data = []
read = 1

while read > 0:
read, _ = stream.Read(buff, 0, buff.Length)
temp = Encoding.UTF8.GetString(buff, 0, read)
data.append(temp)

data = ''.join(data)
self.assertEqual(data, 'Some testing string')

def test_suite():
return unittest.makeSuite(MethodTests)
Expand Down