I'm stuck in place. I am reading a FLV file from a URL. I read this in a Stream and then write this stream to a MemoryStream in a loop. When the code exits the loop, I write the entire MemoryStream to ByteArray and then writing this ByteArray to a local file on my hard drive.
Since this flv is too large, it takes a long time to process in a loop. I'm thinking of reading the original large stream in a MemoryStream in multiple streams. This means splitting a stream into 10 parts and writing these parts to a MemoryStream in multiple streams. How to do it?
I am attaching my piece of code.
WebRequest req = WebRequest.Create(url);
WebResponse response = req.GetResponse();
using (Stream stream = response.GetResponseStream())
{
byte[] buffer = new byte[1024];
int dataLength = (int)response.ContentLength;
using (MemoryStream memStream = new MemoryStream())
{
while (true)
{
int bytesRead = stream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
{
Application.DoEvents();
break;
}
else
{
memStream.Write(buffer, 0, bytesRead);
}
}
byte[] downloadedData = memStream.ToArray();
}
}
Any help is appreciated Thanks