public static void WriteSqlChars(this Stream stream, SqlChars chars, Encoding encoding) { if (stream == null) { throw new ArgumentNullException("stream"); } if (chars == null) { throw new ArgumentNullException("chars"); } if (encoding == null) { throw new ArgumentNullException("encoding"); } long count = chars.Length; var buffer = new char[Comparable.Min(SqlRuntime.IoBufferSize, count)]; long index = 0L; while (count > 0) { int read = (int)chars.Read(index, buffer, 0, (int)Comparable.Min(buffer.Length, count)); stream.WriteChars(buffer.AsEnumerable(), encoding); index += read; count -= read; } }