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

定义

将输入字节数组的指定区域转换为 Base 64,并将结果复制到输出字节数组的指定区域。Converts the specified region of the input byte array to base 64 and copies the result to the specified region of the output byte array.

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 的输入。The input to compute to base 64.

inputOffset
Int32

输入字节数组中的偏移量,从该位置开始使用数据。The offset into the input byte array from which to begin using data.

inputCount
Int32

输入字节数组中用作数据的字节数。The number of bytes in the input byte array to use as data.

outputBuffer
Byte[]

要向其写入结果的输出。The output to which to write the result.

outputOffset
Int32

输出字节数组中的偏移量,从该位置开始写入数据。The offset into the output byte array from which to begin writing data.

返回

写入的字节数The number of bytes written.

实现

异常

已释放当前的 ToBase64Transform 对象。The current ToBase64Transform object has already been disposed.

数据大小无效。The data size is not valid.

inputBuffer 参数包含无效偏移量长度。The inputBuffer parameter contains an invalid offset length.

-or- inputCount 参数包含无效值。The inputCount parameter contains an invalid value.

inputBuffer 参数为 nullThe inputBuffer parameter is null.

inputBuffer 参数需要非负数。The inputBuffer parameter requires a non-negative number.

示例

下面的代码示例演示如何调用TransformBlock方法来inputBytes循环访问转换blockSizeThe following code example demonstrates how to call the TransformBlock method to iterate through inputBytes transforming by blockSize. 此代码示例是为ToBase64Transform类提供的更大示例的一部分。This code example is part of a larger example provided for the ToBase64Transform class.

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个字节的输出块。The ToBase64Transform class is a block algorithm that processes input blocks of 3 bytes and creates output blocks of 4 bytes. 方法TransformBlock将24位的输入块转换为32位的字符数据。The TransformBlock method transforms an input block of 24 bits into 32 bits of character data. 必须将3个字节的输入边界保留到4个字节的输出边界, 才能匹配块转换。You must maintain 3 byte input boundaries to 4 byte output boundaries in order to match the block transform.

适用于

另请参阅