Skip to content

Instantly share code, notes, and snippets.

@Azerothian
Created June 22, 2011 01:59
Show Gist options
  • Save Azerothian/1039372 to your computer and use it in GitHub Desktop.
Save Azerothian/1039372 to your computer and use it in GitHub Desktop.
public override int Read(byte[] buffer, int offset, int count)
{
lock (_incomingLock)
{
_incomingMemoryStream.Position = 0;
var cnt = _incomingMemoryStream.Read(buffer, offset, count);
int amountleft = (int)(_incomingMemoryStream.Length - _incomingMemoryStream.Position);
var newMs = new MemoryStream();
if (amountleft > 0)
{
byte[] data = new byte[amountleft];
_incomingMemoryStream.Read(data, 0, amountleft);
newMs.Write(data, 0, data.Length);
}
_incomingMemoryStream.Close();
_incomingMemoryStream = newMs;
return cnt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment