title: Powershell - Is there a benefit to using the Peek method over Readline (while not null)?
body: <p>I've been working on a PowerShell script using Streamreader (and StreamWriter) to parse a large file into smaller reports. While doing some searching around on the best way to put this thing together, I've found there are two methods largely used to read content to the end of the file.</p>
  
  <p>1 - <code>while ($reader.Peek() -ge 0) { $line = $reader.Readline() ... }</code></p>
  
  <p>2 - <code>while (($line = $read.ReadLine()) -ne $null) { do stuff ... }</code></p>
  
  <p>From the documentation, it looks like <a href="https://docs.microsoft.com/en-us/dotnet/api/system.io.streamreader.peek?view=netframework-4.8#System_IO_StreamReader_Peek" rel="nofollow noreferrer">Peek</a> will read the next value, but not change the position of the reader. It looks like <a href="https://docs.microsoft.com/en-us/dotnet/api/system.io.streamreader.readline?view=netframework-4.8#System_IO_StreamReader_ReadLine" rel="nofollow noreferrer">ReadLine</a> will essentially do the same, but read a whole string/line. I feel like this is a "no-duh" question - is it really more efficient to actually peek at a value before reading the line, or is it just an extra step before assigning the reader to a variable?</p>
  
  <p>Thank you in advance!</p>