ToBase64Transform.TransformBlock(Byte[], Int32, Int32, Byte[], Int32) 方法

定义

将输入字节数组的指定区域转换为 Base 64,并将结果复制到输出字节数组的指定区域。

public:
 virtual int TransformBlock(cli::array <System::Byte> ^ inputBuffer, int inputOffset, int inputCount, cli::array <System::Byte> ^ outputBuffer, int outputOffset);
public int TransformBlock (byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset);
abstract member TransformBlock : byte[] * int * int * byte[] * int -> int
override this.TransformBlock : byte[] * int * int * byte[] * int -> int
Public Function TransformBlock (inputBuffer As Byte(), inputOffset As Integer, inputCount As Integer, outputBuffer As Byte(), outputOffset As Integer) As Integer

参数

inputBuffer
Byte[]

要计算为 Base 64 的输入。

inputOffset
Int32

输入字节数组中的偏移量,从该位置开始使用数据。

inputCount
Int32

输入字节数组中用作数据的字节数。

outputBuffer
Byte[]

要向其写入结果的输出。

outputOffset
Int32

输入字节数组中的偏移量,从该位置开始使用数据。

返回

写入的字节数。

实现

例外

已释放当前的 ToBase64Transform 对象。

数据大小无效。

inputBuffer 参数包含无效偏移量长度。

- 或 -

inputCount 参数包含无效值。

inputBuffer 参数为 null

inputBuffer 参数需要非负数。

示例

下面的代码示例演示如何调用 TransformBlock 方法以循环 inputBytes 访问 转换 blockSize。 此代码示例是为 ToBase64Transform 类提供的一个更大示例的一部分。

int inputBlockSize = base64Transform->InputBlockSize;
while ( inputBytes->Length - inputOffset > inputBlockSize )
{
   base64Transform->TransformBlock(
      inputBytes,
      inputOffset,
      inputBytes->Length - inputOffset,
      outputBytes,
      0 );

   inputOffset += base64Transform->InputBlockSize;
   outputFileStream->Write(
      outputBytes,
      0,
      base64Transform->OutputBlockSize );
}
int inputBlockSize = base64Transform.InputBlockSize;

while(inputBytes.Length - inputOffset > inputBlockSize)
{
    base64Transform.TransformBlock(
        inputBytes,
        inputOffset,
        inputBytes.Length - inputOffset,
        outputBytes,
        0);

    inputOffset += base64Transform.InputBlockSize;
    outputFileStream.Write(
        outputBytes, 
        0, 
        base64Transform.OutputBlockSize);
}
Dim inputBlockSize As Integer = base64Transform.InputBlockSize

While (inputBytes.Length - inputOffset > inputBlockSize)
    base64Transform.TransformBlock( _
        inputBytes, _
        inputOffset, _
        inputBytes.Length - inputOffset, _
        outputBytes, _
        0)

    inputOffset += base64Transform.InputBlockSize
    outputFileStream.Write(outputBytes, _
        0, _
        base64Transform.OutputBlockSize)
End While

注解

ToBase64Transform 是一种块算法,用于处理 3 个字节的输入块并创建 4 个字节的输出块。 方法 TransformBlock 将 24 位的输入块转换为 32 位字符数据。 必须保留 3 个字节输入边界到 4 个字节输出边界,才能匹配块转换。

适用于

另请参阅