I am currently trying to stream content out to the web after a trans-coding process. This usually works fine by writing binary out to my web stream, but some browsers (speci
Just as a follow up to BalusC's excellent post, here is the code I am using in C#. I am chunking data manually directly to an HTTP output stream, after receiving data from the STDOUT on a process.
int buffSize = 16384;
byte[] buffer = new byte[buffSize];
byte[] hexBuff;
byte[] CRLF = Encoding.UTF8.GetBytes("\r\n");
br = new BinaryReader(transcoder.StandardOutput.BaseStream);
//Begin chunking...
int ret = 0;
while (!transcoder.HasExited && (ret = br.Read(buffer, 0, buffSize)) > 0)
{
//Write hex length...
hexBuff = Encoding.UTF8.GetBytes(ret.ToString("X"));
e.Context.Stream.Write(hexBuff, 0, hexBuff.Length);
//Write CRLF...
e.Context.Stream.Write(CRLF, 0, CRLF.Length);
//Write byte content...
e.Context.Stream.Write(buffer, 0, ret);
//Write CRLF...
e.Context.Stream.Write(CRLF, 0, CRLF.Length);
}
//End chunking...
//Write hex length...
hexBuff = Encoding.UTF8.GetBytes(0.ToString("X"));
e.Context.Stream.Write(hexBuff, 0, hexBuff.Length);