title: Why is the amount of bytes read different in each case?
body: <p>Snippet is trying to count the number of bytes read in the following <code>sample.txt</code></p>
  
  <p><strong>sample.txt</strong></p>
  
  <pre><code>one two three four five six
  seven eight nine ten eleven twelve
  thirteen fourteen fifteen sixteen
  %
  </code></pre>
  
  <p><strong>case 1:</strong></p>
  
  <pre class="lang-rust prettyprint-override"><code>let file = File::open(fname)?;
  let mut reader = BufReader::new(&amp;file);
  let mut buffer: Vec&lt;u8&gt; = vec![];
  let num_bytes = reader.read_until(b'%', &amp;mut buffer);
  //println!("{}", String::from_utf8(buffer).unwrap());
  println!("read_bytes: {}", num_bytes.unwrap());
  </code></pre>
  
  <blockquote>
    <p><code>read_bytes: 101</code></p>
  </blockquote>
  
  <p><strong>case 2:</strong></p>
  
  <pre class="lang-rust prettyprint-override"><code>let file = File::open(fname)?;
  let mut reader = BufReader::new(&amp;file);
  let mut num_bytes: u32 = 0;
  for readline in reader.lines() {
      if let Ok(line) = readline {
          //println!("{}", line);
          let bytes = line.as_bytes();
          num_bytes += bytes.len() as u32;
          if bytes == b"%" {
              break;
          }
      }
  }
  println!("read_bytes: {}", num_bytes)
  </code></pre>
  
  <blockquote>
    <p><code>read_bytes: 98</code></p>
  </blockquote>
  
  <p>I can't seem to figure out why the two cases are outputting different results. Any help with appreciated thanks</p>