SizeTrackingStream
Stream wrapper that tracks write operations against a file system size limit. Checks limits during Write (fail-fast), not during Dispose.
Hereda de: Stream
Constructores
public SizeTrackingStream(Stream inner, Func<long, long, bool> checkAndReserve, Action<long, long> commitSize, FileSystemOverflowBehavior behavior, long oldFileSize)
sizeTrackingStream = SizeTrackingStream(inner, checkAndReserve, commitSize, behavior, oldFileSize)
Creates a new size tracking stream wrapper.
- inner
- The underlying stream to wrap.
- checkAndReserve
- Callback to check if write is allowed. Takes (bytesToWrite, oldFileSize), returns true if allowed. For EvictOldest, this callback should attempt eviction before returning false.
- commitSize
- Callback to commit the final size change. Takes (newSize, oldSize). Called on dispose to update TotalSize.
- behavior
- Overflow behavior when limit is exceeded.
- oldFileSize
- Previous file size (credited for overwrites).
Propiedades
public override bool CanRead { get; }
value = sizeTrackingStream.CanRead
Gets a value indicating whether the current stream supports reading.
public override bool CanSeek { get; }
value = sizeTrackingStream.CanSeek
Gets a value indicating whether the current stream supports seeking.
public override bool CanWrite { get; }
value = sizeTrackingStream.CanWrite
Gets a value indicating whether the current stream supports writing.
public override long Length { get; }
value = sizeTrackingStream.Length
Gets the difference between the maximum and minimum values of the range.
public override long Position { get; set; }
value = sizeTrackingStream.Position
sizeTrackingStream.Position = value
Current position value.
Métodos
protected override void Dispose(bool disposing)
sizeTrackingStream.Dispose(disposing)
Disposes the command resources.
- disposing
- True if disposing managed resources.
public override void Flush()
sizeTrackingStream.Flush()
Flushes the current byte to the underlying stream and resets the buffer.
public override Task FlushAsync(CancellationToken cancellationToken)
result = sizeTrackingStream.FlushAsync(cancellationToken)
Flushes the stream asynchronously.
- cancellationToken
- CancellationToken
Devuelve: Task
public override int Read(byte[] buffer, int offset, int count)
result = sizeTrackingStream.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.
Devuelve: The total number of bytes read into the buffer.
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
result = sizeTrackingStream.ReadAsync(buffer, offset, count, cancellationToken)
public override long Seek(long offset, SeekOrigin origin)
result = sizeTrackingStream.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.
Devuelve: The new position within the current stream.
public override void SetLength(long value)
sizeTrackingStream.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)
sizeTrackingStream.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 Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
result = sizeTrackingStream.WriteAsync(buffer, offset, count, cancellationToken)