ProgressStream
Stream wrapper that reports progress during read or write operations.
Herda de: Stream
Construtores
public ProgressStream(Stream inner, long totalBytes, Action<int> progress, bool trackReads, bool trackWrites, bool leaveOpen)
progressStream = ProgressStream(inner, totalBytes, progress, trackReads, trackWrites, leaveOpen)
Initializes a new instance of ProgressStream.
- inner
- The underlying stream to wrap.
- totalBytes
- Total bytes expected (for percentage calculation).
- progress
- Callback invoked with progress percentage (0-100).
- trackReads
- Track progress on read operations.
- trackWrites
- Track progress on write operations.
- leaveOpen
- Whether to leave the inner stream open when disposed.
Propriedades
public override bool CanRead { get; }
value = progressStream.CanRead
Gets a value indicating whether the current stream supports reading.
public override bool CanSeek { get; }
value = progressStream.CanSeek
Gets a value indicating whether the current stream supports seeking.
public override bool CanWrite { get; }
value = progressStream.CanWrite
Gets a value indicating whether the current stream supports writing.
public int LastReportedPercent { get; }
value = progressStream.LastReportedPercent
Gets the last reported progress percentage.
public override long Length { get; }
value = progressStream.Length
Gets the difference between the maximum and minimum values of the range.
public override long Position { get; set; }
value = progressStream.Position
progressStream.Position = value
Current position value.
public long ProcessedBytes { get; }
value = progressStream.ProcessedBytes
Gets the total bytes processed so far.
Métodos
public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken)
result = progressStream.CopyToAsync(destination, bufferSize, cancellationToken)
protected override void Dispose(bool disposing)
progressStream.Dispose(disposing)
Disposes the command resources.
- disposing
- True if disposing managed resources.
public override void Flush()
progressStream.Flush()
Flushes the current byte to the underlying stream and resets the buffer.
public override Task FlushAsync(CancellationToken cancellationToken)
result = progressStream.FlushAsync(cancellationToken)
Flushes the stream asynchronously.
- cancellationToken
- CancellationToken
Retorna: Task
public override int Read(byte[] buffer, int offset, int count)
result = progressStream.Read(buffer, offset, count)
Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
- buffer
- An array of bytes. When this method returns, the buffer contains the specified byte array with the values between and ( + - 1) replaced by the bytes read from the current source.
- offset
- The zero-based byte offset in at which to begin storing the data read from the current stream.
- count
- The maximum number of bytes to be read from the current stream.
Retorna: The total number of bytes read into the buffer.
public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken)
result = progressStream.ReadAsync(buffer, cancellationToken)
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
result = progressStream.ReadAsync(buffer, offset, count, cancellationToken)
public override int ReadByte()
result = progressStream.ReadByte()
Reads a byte from the current position and advances the position by 1 byte.
Retorna: The byte at the current position.
public override long Seek(long offset, SeekOrigin origin)
result = progressStream.Seek(offset, origin)
When overridden in a derived class, sets the position within the current stream.
- offset
- A byte offset relative to the parameter.
- origin
- A value of type SeekOrigin indicating the reference point used to obtain the new position.
Retorna: The new position within the current stream.
public override void SetLength(long value)
progressStream.SetLength(value)
When overridden in a derived class, sets the length of the current stream.
- value
- The desired length of the current stream in bytes.
public override void Write(byte[] buffer, int offset, int count)
progressStream.Write(buffer, offset, count)
Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
- buffer
- An array of bytes. This method copies bytes from to the current stream.
- offset
- The zero-based byte offset in at which to begin copying bytes to the current stream.
- count
- The number of bytes to be written to the current stream.
public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken)
result = progressStream.WriteAsync(buffer, cancellationToken)
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
result = progressStream.WriteAsync(buffer, offset, count, cancellationToken)
public override void WriteByte(byte value)
progressStream.WriteByte(value)
Writes a byte value to the span at the current position and advances the position.
- value
- The byte value to write.