BrotliStream.Read 方法

定义

重载

Read(Span<Byte>)

将当前 Brotli 流中的一个字节序列读取到字节范围,并按读取的字节数向前移动 Brotli 流中的位置。Reads a sequence of bytes from the current Brotli stream to a byte span and advances the position within the Brotli stream by the number of bytes read.

Read(Byte[], Int32, Int32)

将若干解压缩的字节读入指定的字节数组。Reads a number of decompressed bytes into the specified byte array.

Read(Span<Byte>)

将当前 Brotli 流中的一个字节序列读取到字节范围,并按读取的字节数向前移动 Brotli 流中的位置。Reads a sequence of bytes from the current Brotli stream to a byte span and advances the position within the Brotli stream by the number of bytes read.

public:
 override int Read(Span<System::Byte> buffer);
public override int Read (Span<byte> buffer);
override this.Read : Span<byte> -> int
Public Overrides Function Read (buffer As Span(Of Byte)) As Integer

参数

buffer
Span<Byte>

内存的区域。A region of memory. 当此方法返回时,此区域的内容将替换为从当前源读取的字节。When this method returns, the contents of this region are replaced by the bytes read from the current source.

返回

Int32

读入缓冲区中的总字节数。The total number of bytes read into the buffer. 如果很多字节当前不可用,则这可小于在缓冲区中分配的字节数;如果已到达流结尾,则为零 (0)。This can be less than the number of bytes allocated in the buffer if that many bytes are not currently available, or zero (0) if the end of the stream has been reached.

注解

使用 CanRead 属性可确定当前实例是否支持读取。Use the CanRead property to determine whether the current instance supports reading. 使用 ReadAsync 方法从当前流中异步读取。Use the ReadAsync method to read asynchronously from the current stream.

此方法从当前流中读取最多 buffer.Length 字节,并将它们存储在中 bufferThis method read a maximum of buffer.Length bytes from the current stream and store them in buffer. Brotli 流中的当前位置由读取的字节数提前,但是,如果发生异常,则 Brotli 流中的当前位置将保持不变。The current position within the Brotli stream is advanced by the number of bytes read; however, if an exception occurs, the current position within the Brotli stream remains unchanged. 如果没有数据可用,则此方法将被阻止,直到至少有一个字节的数据可供读取。This method will block until at least one byte of data can be read, in the event that no data is available. Read 仅当流中没有更多的数据,但不需要更多的数据时,才会返回0, (例如关闭的套接字或文件末尾) 。Read returns 0 only when there is no more data in the stream and no more is expected (such as a closed socket or end of file). 即使尚未到达流的末尾,方法也可以随意返回比所请求的字节更少的字节。The method is free to return fewer bytes than requested even if the end of the stream has not been reached.

用于 BinaryReader 读取基元数据类型。Use BinaryReader for reading primitive data types.

适用于

Read(Byte[], Int32, Int32)

将若干解压缩的字节读入指定的字节数组。Reads a number of decompressed bytes into the specified byte array.

public:
 override int Read(cli::array <System::Byte> ^ buffer, int offset, int count);
public override int Read (byte[] buffer, int offset, int count);
override this.Read : byte[] * int * int -> int
Public Overrides Function Read (buffer As Byte(), offset As Integer, count As Integer) As Integer

参数

buffer
Byte[]

用于存储解压缩字节的数组。The array used to store decompressed bytes.

offset
Int32

buffer 中的字节偏移量,将在此处放置读取的字节。The byte offset in buffer at which the read bytes will be placed.

count
Int32

最多要读取的解压缩字节数。The maximum number of decompressed bytes to read.

返回

Int32

解压缩到字节数组中的字节数。The number of bytes that were decompressed into the byte array. 如果已到达流的末尾,则返回 0 或已读取的字节数。If the end of the stream has been reached, zero or the number of bytes read is returned.

例外

buffernullbuffer is null.

创建对象时,CompressionMode 值为 Compress,或者此流上已存在活动的异步操作。The CompressionMode value was Compress when the object was created, or there is already an active asynchronous operation on this stream.

offsetcount 小于零。offset or count is less than zero.

buffer 长度减去索引起始点小于 countThe buffer length minus the index starting point is less than count.

数据的格式无效。The data is in an invalid format.

基础流为 NULL 或已关闭。The underlying stream is null or closed.

适用于