title: Split up a memorystream into bytarray
body: <p>Im trying to split up a memorystream into chunks by reading parts into a byte array but i think i have got something fundamentally wrong. I can read the first chunk but when i try to read rest of memorystream i get index out of bound even if there are more bytes to read. It seems that the issue is the size of the receving byte buffer that need to be as large as the memorystrem. I need to convert it into chunks as the code is in a webservice.</p>
  
  <p>Anyone knows whats wrong with this code</p>
  
  <p>fb.buffer is MemoryStream</p>
  
  <pre><code>  long bytesLeft = fb.Buffer.Length;
                  fb.Buffer.Position = 0;
                  int offset =0;
                  int BUFF_SIZE = 8196;
  
  
                  while (bytesLeft &gt; 0)
                  {
                      byte[] fs = new byte[BUFF_SIZE];
  
                      fb.Buffer.Read(fs, offset, BUFF_SIZE);
                      offset += BUFF_SIZE;
                      bytesLeft -= BUFF_SIZE;
                  }
  </code></pre>