title: Remove null bytes from the beginning of a stream
body: <p>I have a class in a dll which parses a file and returns a Stream which represents an FAT image (or any <strong>other</strong>)</p>
  
  <p>My problem is when there is any <strong>other</strong> image the class creates about 3702 (on average) null bytes at the beginning of the stream.</p>
  
  <p>So I have to edit the stream first and then save it to a file.</p>
  
  <p>I have a code already but it works slow.</p>
  
  <p>[Note : <em>fts</em> is the returned FileStream.]</p>
  
  <pre><code>BufferedStream bfs = new BufferedStream(fts);
  BinaryReader bbr = new BinaryReader(bfs);
  byte[] all_bytes = bbr.ReadBytes((int)fts.Length);
  
  List&lt;byte&gt; nls = new List&lt;byte&gt;();
  int index = 0;
  
  foreach (byte bbrs in all_bytes)
  {
      if (bbrs == 0x00)
      {
          index++;
          nls.Add(bbrs);
      }
      else
      {
          break;
      }
  }
  
  byte[] nulls = new byte[nls.Count];
  nulls = nls.ToArray();
  
  //File.WriteAllBytes(outputDir + "Nulls.bin", nulls);
  long siz = fts.Length - index;
  byte[] file = new byte[siz];
  
  bbr.BaseStream.Position = index;
  file = bbr.ReadBytes((int)siz);
  
  bbr.Close();
  bfs.Close();
  fts.Close();
  
  bfs = null;
  fts = null;
  
  fts = new FileStream(outputDir + "Image.bin", FileMode.Create, FileAccess.Write);
  bfs = new BufferedStream(fts);
  
  bfs.Write(file, 0, (int)siz);
  
  bfs.Close();
  fts.Close();
  </code></pre>
  
  <p>Now, my question is :</p>
  
  <p>How can I remove the nulls more efficiently and faster than the above code?</p>