Show / Hide Table of Contents

Class StreamSegment

Represents read-only view over the portion of underlying stream.

Inheritance
object
MarshalByRefObject
Stream
StreamSegment
Implements
IDisposable
IAsyncDisposable
IFlushable
Inherited Members
Stream.Null
Stream.CopyTo(Stream)
Stream.CopyTo(Stream, int)
Stream.CopyToAsync(Stream)
Stream.CopyToAsync(Stream, int)
Stream.CopyToAsync(Stream, CancellationToken)
Stream.CopyToAsync(Stream, int, CancellationToken)
Stream.Dispose()
Stream.Close()
Stream.FlushAsync()
Stream.ReadAsync(byte[], int, int)
Stream.ReadExactlyAsync(Memory<byte>, CancellationToken)
Stream.ReadExactlyAsync(byte[], int, int, CancellationToken)
Stream.ReadAtLeastAsync(Memory<byte>, int, bool, CancellationToken)
Stream.WriteAsync(byte[], int, int)
Stream.ReadExactly(Span<byte>)
Stream.ReadExactly(byte[], int, int)
Stream.ReadAtLeast(Span<byte>, int, bool)
Stream.Synchronized(Stream)
MarshalByRefObject.GetLifetimeService()
MarshalByRefObject.InitializeLifetimeService()
object.GetType()
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
Namespace: DotNext.IO
Assembly: DotNext.IO.dll
Syntax
public sealed class StreamSegment : Stream, IDisposable, IAsyncDisposable, IFlushable
Remarks

The segmentation is supported only for seekable streams.

Constructors

View Source

StreamSegment(Stream, bool)

Represents read-only view over the portion of underlying stream.

Declaration
public StreamSegment(Stream stream, bool leaveOpen = true)
Parameters
Type Name Description
Stream stream

The underlying stream represented by the segment.

bool leaveOpen

true to leave stream open after the object is disposed; otherwise, false.

Remarks

The segmentation is supported only for seekable streams.

Properties

View Source

BaseStream

Gets underlying stream.

Declaration
public Stream BaseStream { get; }
Property Value
Type Description
Stream
View Source

CanRead

Gets a value indicating whether the current stream supports reading.

Declaration
public override bool CanRead { get; }
Property Value
Type Description
bool

true if the stream supports reading; otherwise, false.

Overrides
Stream.CanRead
View Source

CanSeek

Gets a value indicating whether the current stream supports seeking.

Declaration
public override bool CanSeek { get; }
Property Value
Type Description
bool

true if the stream supports seeking; otherwise, false.

Overrides
Stream.CanSeek
View Source

CanTimeout

Declaration
public override bool CanTimeout { get; }
Property Value
Type Description
bool
Overrides
Stream.CanTimeout
View Source

CanWrite

Gets a value indicating whether the current stream supports writing.

Declaration
public override bool CanWrite { get; }
Property Value
Type Description
bool

Always false.

Overrides
Stream.CanWrite
View Source

Length

Declaration
public override long Length { get; }
Property Value
Type Description
long
Overrides
Stream.Length
View Source

Position

Declaration
public override long Position { get; set; }
Property Value
Type Description
long
Overrides
Stream.Position
View Source

Range

Gets or sets the segment range.

Declaration
public (long Offset, long Length) Range { get; set; }
Property Value
Type Description
(long Offset, long Length)
Exceptions
Type Condition
ArgumentOutOfRangeException

The length is larger than the remaining length of the underlying stream; or the offset is greater than the length of the underlying stream.

View Source

ReadTimeout

Declaration
public override int ReadTimeout { get; set; }
Property Value
Type Description
int
Overrides
Stream.ReadTimeout
View Source

WriteTimeout

Declaration
public override int WriteTimeout { get; set; }
Property Value
Type Description
int
Overrides
Stream.WriteTimeout

Methods

View Source

BeginRead(byte[], int, int, AsyncCallback?, object?)

Declaration
public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
Parameters
Type Name Description
byte[] buffer
int offset
int count
AsyncCallback callback
object state
Returns
Type Description
IAsyncResult
Overrides
Stream.BeginRead(byte[], int, int, AsyncCallback, object)
View Source

BeginWrite(byte[], int, int, AsyncCallback?, object?)

Declaration
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state)
Parameters
Type Name Description
byte[] buffer
int offset
int count
AsyncCallback callback
object state
Returns
Type Description
IAsyncResult
Overrides
Stream.BeginWrite(byte[], int, int, AsyncCallback, object)
View Source

Dispose(bool)

Declaration
protected override void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing
Overrides
Stream.Dispose(bool)
View Source

DisposeAsync()

Declaration
public override ValueTask DisposeAsync()
Returns
Type Description
ValueTask
Overrides
Stream.DisposeAsync()
View Source

EndRead(IAsyncResult)

Declaration
public override int EndRead(IAsyncResult asyncResult)
Parameters
Type Name Description
IAsyncResult asyncResult
Returns
Type Description
int
Overrides
Stream.EndRead(IAsyncResult)
View Source

EndWrite(IAsyncResult)

Declaration
public override void EndWrite(IAsyncResult asyncResult)
Parameters
Type Name Description
IAsyncResult asyncResult
Overrides
Stream.EndWrite(IAsyncResult)
View Source

Flush()

Declaration
public override void Flush()
Overrides
Stream.Flush()
View Source

FlushAsync(CancellationToken)

Declaration
public override Task FlushAsync(CancellationToken token)
Parameters
Type Name Description
CancellationToken token
Returns
Type Description
Task
Overrides
Stream.FlushAsync(CancellationToken)
View Source

Read(byte[], int, int)

Declaration
public override int Read(byte[] buffer, int offset, int count)
Parameters
Type Name Description
byte[] buffer
int offset
int count
Returns
Type Description
int
Overrides
Stream.Read(byte[], int, int)
View Source

Read(Span<byte>)

Declaration
public override int Read(Span<byte> buffer)
Parameters
Type Name Description
Span<byte> buffer
Returns
Type Description
int
Overrides
Stream.Read(Span<byte>)
View Source

ReadAsync(byte[], int, int, CancellationToken)

Declaration
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken token)
Parameters
Type Name Description
byte[] buffer
int offset
int count
CancellationToken token
Returns
Type Description
Task<int>
Overrides
Stream.ReadAsync(byte[], int, int, CancellationToken)
View Source

ReadAsync(Memory<byte>, CancellationToken)

Declaration
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken token = default)
Parameters
Type Name Description
Memory<byte> buffer
CancellationToken token
Returns
Type Description
ValueTask<int>
Overrides
Stream.ReadAsync(Memory<byte>, CancellationToken)
View Source

ReadByte()

Declaration
public override int ReadByte()
Returns
Type Description
int
Overrides
Stream.ReadByte()
View Source

Seek(long, SeekOrigin)

Declaration
public override long Seek(long offset, SeekOrigin origin)
Parameters
Type Name Description
long offset
SeekOrigin origin
Returns
Type Description
long
Overrides
Stream.Seek(long, SeekOrigin)
View Source

SetLength(long)

Declaration
public override void SetLength(long value)
Parameters
Type Name Description
long value
Overrides
Stream.SetLength(long)
View Source

Write(byte[], int, int)

Declaration
public override void Write(byte[] buffer, int offset, int count)
Parameters
Type Name Description
byte[] buffer
int offset
int count
Overrides
Stream.Write(byte[], int, int)
View Source

Write(ReadOnlySpan<byte>)

Declaration
public override void Write(ReadOnlySpan<byte> buffer)
Parameters
Type Name Description
ReadOnlySpan<byte> buffer
Overrides
Stream.Write(ReadOnlySpan<byte>)
View Source

WriteAsync(byte[], int, int, CancellationToken)

Declaration
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken token)
Parameters
Type Name Description
byte[] buffer
int offset
int count
CancellationToken token
Returns
Type Description
Task
Overrides
Stream.WriteAsync(byte[], int, int, CancellationToken)
View Source

WriteAsync(ReadOnlyMemory<byte>, CancellationToken)

Declaration
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default)
Parameters
Type Name Description
ReadOnlyMemory<byte> buffer
CancellationToken cancellationToken
Returns
Type Description
ValueTask
Overrides
Stream.WriteAsync(ReadOnlyMemory<byte>, CancellationToken)
View Source

WriteByte(byte)

Declaration
public override void WriteByte(byte value)
Parameters
Type Name Description
byte value
Overrides
Stream.WriteByte(byte)

Implements

IDisposable
IAsyncDisposable
IFlushable

Extension Methods

BasicExtensions.As<T>(T)
BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, params ReadOnlySpan<T>)
StreamExtensions.CopyToAsync(Stream, IBufferWriter<byte>, int, CancellationToken)
StreamExtensions.CopyToAsync(Stream, IBufferWriter<byte>, long, int, CancellationToken)
StreamExtensions.CopyToAsync(Stream, Stream, long, Memory<byte>, CancellationToken)
StreamExtensions.CopyToAsync(Stream, Stream, Memory<byte>, CancellationToken)
StreamExtensions.CopyToAsync<TConsumer>(Stream, TConsumer, long, Memory<byte>, CancellationToken)
StreamExtensions.CopyToAsync<TConsumer>(Stream, TConsumer, Memory<byte>, CancellationToken)
StreamExtensions.DecodeAsync(Stream, DecodingContext, LengthFormat, Memory<byte>, MemoryAllocator<char>?, CancellationToken)
StreamExtensions.DecodeAsync(Stream, DecodingContext, LengthFormat, Memory<char>, Memory<byte>, CancellationToken)
StreamExtensions.EncodeAsync(Stream, ReadOnlyMemory<char>, EncodingContext, LengthFormat?, Memory<byte>, CancellationToken)
StreamExtensions.FormatAsync<T>(Stream, T, EncodingContext, LengthFormat?, Memory<byte>, string?, IFormatProvider?, MemoryAllocator<char>?, CancellationToken)
StreamExtensions.FormatAsync<T>(Stream, T, LengthFormat?, Memory<byte>, string?, IFormatProvider?, CancellationToken)
StreamExtensions.ParseAsync<T>(Stream, LengthFormat, Memory<byte>, NumberStyles, IFormatProvider?, CancellationToken)
StreamExtensions.ParseAsync<T>(Stream, LengthFormat, Memory<byte>, IFormatProvider?, CancellationToken)
StreamExtensions.ParseAsync<TArg, TResult>(Stream, TArg, Func<ReadOnlySpan<char>, TArg, TResult>, DecodingContext, LengthFormat, Memory<byte>, MemoryAllocator<char>?, CancellationToken)
StreamExtensions.ReadAllAsync(Stream, int, MemoryAllocator<byte>?, CancellationToken)
StreamExtensions.ReadAsync<T>(Stream, Memory<byte>, CancellationToken)
StreamExtensions.ReadBigEndianAsync<T>(Stream, Memory<byte>, CancellationToken)
StreamExtensions.ReadBlockAsync(Stream, LengthFormat, MemoryAllocator<byte>?, CancellationToken)
StreamExtensions.ReadExactlyAsync(Stream, long, int, MemoryAllocator<byte>?, CancellationToken)
StreamExtensions.ReadLittleEndianAsync<T>(Stream, Memory<byte>, CancellationToken)
StreamExtensions.ReadUtf8(Stream, Span<byte>, IBufferWriter<char>)
StreamExtensions.ReadUtf8Async(Stream, Memory<byte>, IBufferWriter<char>, CancellationToken)
StreamExtensions.ReadUtf8Async<TArg>(Stream, Memory<byte>, Memory<char>, Func<ReadOnlyMemory<char>, TArg, CancellationToken, ValueTask>, TArg, CancellationToken)
StreamExtensions.ReadUtf8<TArg>(Stream, Span<byte>, Span<char>, ReadOnlySpanAction<char, TArg>, TArg)
StreamExtensions.Slice(Stream, long, long)
StreamExtensions.WriteAsync(Stream, ReadOnlySequence<byte>, CancellationToken)
StreamExtensions.WriteAsync(Stream, ReadOnlyMemory<byte>, LengthFormat, Memory<byte>, CancellationToken)
StreamExtensions.WriteAsync<T>(Stream, T, Memory<byte>, CancellationToken)
StreamExtensions.WriteBigEndianAsync<T>(Stream, T, Memory<byte>, CancellationToken)
StreamExtensions.WriteLittleEndianAsync<T>(Stream, T, Memory<byte>, CancellationToken)
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾