@@ -13,6 +13,7 @@ This Source Code Form is subject to the terms of the
1313using ScriptEngine . Machine . Contexts ;
1414using System ;
1515using System . IO ;
16+ using System . Runtime . Intrinsics . X86 ;
1617using System . Security . Cryptography ;
1718using System . Text ;
1819
@@ -104,6 +105,12 @@ private void AppendStream(Stream stream)
104105
105106 private void AppendStream ( Stream stream , int count )
106107 {
108+ if ( count <= 0 )
109+ {
110+ AppendStream ( stream ) ;
111+ return ;
112+ }
113+
107114 int bufSize = Math . Min ( BUFFER_SIZE , count ) ;
108115 var buffer = new byte [ bufSize ] ;
109116 int toRead = count ;
@@ -119,23 +126,42 @@ private void AppendStream(Stream stream, int count)
119126 }
120127
121128 [ ContextMethod ( "Добавить" , "Append" ) ]
122- public void Append ( BslValue toAdd , int count = 0 )
129+ public void Append ( BslValue toAdd , BslValue count = null )
123130 {
124131 switch ( toAdd )
125132 {
126133 case BslStringValue s :
127134 AppendData ( Encoding . UTF8 . GetBytes ( ( string ) s ) ) ;
128135 break ;
129- case IStreamWrapper wrapper :
130- var stream = wrapper . GetUnderlyingStream ( ) ;
131- if ( count <= 0 )
132- AppendStream ( stream ) ;
133- else
134- AppendStream ( stream , count ) ;
135- break ;
136136 case BinaryDataContext binaryData :
137137 AppendStream ( binaryData . GetStream ( ) ) ;
138138 break ;
139+
140+ case IStreamWrapper wrapper :
141+ var stream = wrapper . GetUnderlyingStream ( ) ;
142+ if ( count == null )
143+ {
144+ AppendStream ( stream ) ;
145+ }
146+ else
147+ {
148+ int cnt ;
149+ try
150+ {
151+ cnt = ( int ) count ;
152+ }
153+ catch
154+ {
155+ if ( count is BslStringValue )
156+ throw RuntimeException . InvalidNthArgumentValue ( 2 ) ;
157+ else
158+ throw RuntimeException . InvalidNthArgumentType ( 2 ) ;
159+ }
160+
161+ AppendStream ( stream , cnt ) ;
162+ }
163+ break ;
164+
139165 default :
140166 throw RuntimeException . InvalidNthArgumentType ( 1 ) ;
141167 }
0 commit comments