static int ChunkLength(object chunk)
{
AssertChunkObject(chunk);
if (chunk.GetType() == typeof(string)) return ((string)chunk).Length;
if (chunk.GetType() == typeof(byte[])) return ((byte[])chunk).Length;
if (chunk.GetType() == typeof(PhpString)) return ((PhpString)chunk).Length;
if (chunk.GetType() == typeof(char[])) return ((char[])chunk).Length;
throw new ArgumentException();
}