22// Created by basicx-StrgV //
33// https://github.com/basicx-StrgV/ //
44//--------------------------------------------------//
5- using System ;
6- using System . IO ;
5+ using System . Diagnostics ;
76using System . Text ;
87using System . Threading ;
9- using System . Diagnostics ;
108using System . Threading . Tasks ;
11- using WGetNET . Models ;
129using WGetNET . Extensions ;
10+ using WGetNET . Models ;
1311
1412namespace WGetNET . Components . Internal
1513{
@@ -114,7 +112,7 @@ private ProcessResult RunProcess(ProcessStartInfo processStartInfo)
114112 {
115113 proc . Start ( ) ;
116114
117- result . Output = ReadSreamOutput ( proc . StandardOutput ) ;
115+ result . Output = proc . StandardOutput . ReadSreamOutputByLine ( ) ;
118116
119117 //Wait till end and get exit code
120118 proc . WaitForExit ( ) ;
@@ -153,7 +151,7 @@ private async Task<ProcessResult> RunProcessAsync(ProcessStartInfo processStartI
153151 {
154152 proc . Start ( ) ;
155153
156- result . Output = await ReadSreamOutputAsync ( proc . StandardOutput , cancellationToken ) ;
154+ result . Output = await proc . StandardOutput . ReadSreamOutputByLineAsync ( cancellationToken ) ;
157155
158156 // Kill the process and return, if the task is canceled
159157 if ( cancellationToken . IsCancellationRequested && ! proc . HasExited )
@@ -179,71 +177,5 @@ private async Task<ProcessResult> RunProcessAsync(ProcessStartInfo processStartI
179177
180178 return result ;
181179 }
182-
183- /// <summary>
184- /// Reads the data from the process output to a string array.
185- /// </summary>
186- /// <param name="output">
187- /// The <see cref="StreamReader"/> with the process output.
188- /// </param>
189- /// <returns>
190- /// A <see cref="string"/> array
191- /// containing the process output stream content by lines.
192- /// </returns>
193- private string [ ] ReadSreamOutput ( StreamReader output )
194- {
195- string [ ] outputArray = Array . Empty < string > ( ) ;
196-
197- //Read output to list
198- while ( ! output . EndOfStream )
199- {
200- string ? outputLine = output . ReadLine ( ) ;
201- if ( outputLine is null )
202- {
203- continue ;
204- }
205-
206- outputArray = outputArray . Add ( outputLine ) ;
207- }
208-
209- return outputArray ;
210- }
211-
212- /// <summary>
213- /// Asynchronous reads the data from the process output to a string array.
214- /// </summary>
215- /// <param name="output">
216- /// The <see cref="System.IO.StreamReader"/> with the process output.
217- /// </param>
218- /// <param name="cancellationToken">
219- /// The <see cref="System.Threading.CancellationToken"/> for the <see cref="System.Threading.Tasks.Task"/>.
220- /// </param>
221- /// <returns>
222- /// A <see cref="string"/> array
223- /// containing the process output stream content by lines.
224- /// </returns>
225- private async Task < string [ ] > ReadSreamOutputAsync ( StreamReader output , CancellationToken cancellationToken = default )
226- {
227- string [ ] outputArray = Array . Empty < string > ( ) ;
228-
229- //Read output to list
230- while ( ! output . EndOfStream )
231- {
232- if ( cancellationToken . IsCancellationRequested )
233- {
234- break ;
235- }
236-
237- string ? outputLine = await output . ReadLineAsync ( ) ;
238- if ( outputLine is null )
239- {
240- continue ;
241- }
242-
243- outputArray = outputArray . Add ( outputLine ) ;
244- }
245-
246- return outputArray ;
247- }
248180 }
249181}
0 commit comments