X Tutup
Skip to content
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
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
X Tutup