File tree 2 files changed +27
-4
lines changed
2 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -293,12 +293,13 @@ def OpenDocument(self):
293
293
stream = File .OpenRead (filename )
294
294
295
295
buff = System .Array .CreateInstance (System .Byte , 1024 )
296
+ buff .Initialize ()
296
297
data = []
298
+ read = 1
297
299
298
- while stream .Position < stream .Length :
299
- buff .Initialize ()
300
- stream .Read (buff , 0 , 1024 )
301
- temp = Encoding .ASCII .GetString (buff , 0 , 1024 )
300
+ while read > 0 :
301
+ read , _ = stream .Read (buff , 0 , 1024 )
302
+ temp = Encoding .ASCII .GetString (buff , 0 , read )
302
303
data .append (temp )
303
304
304
305
data = '' .join (data )
Original file line number Diff line number Diff line change @@ -759,6 +759,28 @@ def test():
759
759
760
760
self .assertRaises (TypeError , test )
761
761
762
+ def testWeCanBindToEncodingGetString (self ):
763
+ """Check that we can bind to the Encoding.GetString method with variables."""
764
+
765
+ from System .Text import Encoding
766
+ from System .IO import MemoryStream
767
+ myBytes = Encoding .UTF8 .GetBytes ('Some testing string' )
768
+ stream = MemoryStream ()
769
+ stream .Write (myBytes , 0 , myBytes .Length )
770
+ stream .Position = 0
771
+
772
+ buff = System .Array .CreateInstance (System .Byte , 3 )
773
+ buff .Initialize ()
774
+ data = []
775
+ read = 1
776
+
777
+ while read > 0 :
778
+ read , _ = stream .Read (buff , 0 , buff .Length )
779
+ temp = Encoding .UTF8 .GetString (buff , 0 , read )
780
+ data .append (temp )
781
+
782
+ data = '' .join (data )
783
+ self .assertEqual (data , 'Some testing string' )
762
784
763
785
def test_suite ():
764
786
return unittest .makeSuite (MethodTests )
You can’t perform that action at this time.
0 commit comments