internal static byte[] GetBuffer(this MemoryStream memStream) { ArraySegment<byte> buffer; if (!memStream.TryGetBuffer(out buffer)) return memStream.ToArray(); return buffer.Array; } }