public static int ToBase64CharArray (byte[] inArray, int offsetIn, int length,
char[] outArray, int offsetOut, Base64FormattingOptions options)
{
if (inArray == null)
throw new ArgumentNullException ("inArray");
if (outArray == null)
throw new ArgumentNullException ("outArray");
if (offsetIn < 0 || length < 0 || offsetOut < 0)
throw new ArgumentOutOfRangeException ("offsetIn, length, offsetOut < 0");
// avoid integer overflow
if (offsetIn > inArray.Length - length)
throw new ArgumentOutOfRangeException ("offsetIn + length > array.Length");
if (length == 0)
return 0;
// note: normally ToBase64Transform doesn't support multiple block processing
if (options == Base64FormattingOptions.InsertLineBreaks) {
StringBuilder sb = ToBase64StringBuilderWithLine (inArray, offsetIn, length);
sb.CopyTo (0, outArray, offsetOut, sb.Length);
return sb.Length;
} else {
byte[] outArr = ToBase64Transform.InternalTransformFinalBlock (inArray, offsetIn, length);
char[] cOutArr = Encoding.ASCII.GetChars (outArr);
// avoid integer overflow
if (offsetOut > outArray.Length - cOutArr.Length)
throw new ArgumentOutOfRangeException ("offsetOut + cOutArr.Length > outArray.Length");
Array.Copy (cOutArr, 0, outArray, offsetOut, cOutArr.Length);
return cOutArr.Length;
}
}