Skip to content

PeekableStream Class ​

Definition ​

A read-only Stream wrapper that supports peeking at the next byte without consuming it.

c#
public sealed class PeekableStream : Stream, IDisposable, IAsyncDisposable

View source

Constructors ​

NameDescription
PeekableStream(Stream, Boolean)Initializes a new instance of the PeekableStream class.

Properties ​

NameDescription
CanReadWhen overridden in a derived class, gets a value indicating whether the current stream supports reading.
CanSeekWhen overridden in a derived class, gets a value indicating whether the current stream supports seeking.
CanWriteWhen overridden in a derived class, gets a value indicating whether the current stream supports writing.
EndOfStreamGets a value indicating whether the end of the stream has been reached.
LengthWhen overridden in a derived class, gets the length in bytes of the stream.
PositionWhen overridden in a derived class, gets or sets the position within the current stream.

Methods ​

NameDescription
Dispose(Boolean)Releases the unmanaged resources used by the Stream and optionally releases the managed resources.
EndOfStreamAsync(CancellationToken)Asynchronously determines whether the end of the stream has been reached.
Flush()When overridden in a derived class, clears all buffers for this stream and causes any buffered data to be written to the underlying device.
Peek()Reads the next byte from the stream without consuming it. Subsequent calls to Peek() will return the same value until the byte is consumed by a read operation, or the position is changed.
PeekAsync(CancellationToken)Asynchronously reads the next byte from the stream without consuming it. Subsequent calls to PeekAsync(CancellationToken) will return the same value until the byte is consumed by a read operation, or the position is changed.
Read(Byte[], Int32, Int32)When overridden in a derived class, reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
ReadAsync(Byte[], Int32, Int32, CancellationToken)Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.
ReadAsync(Memory<Byte>, CancellationToken)Asynchronously reads a sequence of bytes from the current stream, advances the position within the stream by the number of bytes read, and monitors cancellation requests.
Seek(Int64, SeekOrigin)When overridden in a derived class, sets the position within the current stream.
SetLength(Int64)When overridden in a derived class, sets the length of the current stream.
Write(Byte[], Int32, Int32)When overridden in a derived class, writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.