SizeTrackingStream

Ecng.IO

Stream wrapper that tracks write operations against a file system size limit. Checks limits during Write (fail-fast), not during Dispose.

继承自: Stream

构造函数

SizeTrackingStream
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).

属性

CanRead
public override bool CanRead { get; }
value = sizeTrackingStream.CanRead

Gets a value indicating whether the current stream supports reading.

CanSeek
public override bool CanSeek { get; }
value = sizeTrackingStream.CanSeek

Gets a value indicating whether the current stream supports seeking.

CanWrite
public override bool CanWrite { get; }
value = sizeTrackingStream.CanWrite

Gets a value indicating whether the current stream supports writing.

Length
public override long Length { get; }
value = sizeTrackingStream.Length

Gets the difference between the maximum and minimum values of the range.

Position
public override long Position { get; set; }
value = sizeTrackingStream.Position
sizeTrackingStream.Position = value

Current position value.

方法

Dispose
protected override void Dispose(bool disposing)
sizeTrackingStream.Dispose(disposing)

Disposes the command resources.

disposing
True if disposing managed resources.
Flush
public override void Flush()
sizeTrackingStream.Flush()

Flushes the current byte to the underlying stream and resets the buffer.

FlushAsync
public override Task FlushAsync(CancellationToken cancellationToken)
result = sizeTrackingStream.FlushAsync(cancellationToken)

Flushes the stream asynchronously.

cancellationToken
CancellationToken

返回值: Task

Read
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.

返回值: The total number of bytes read into the buffer.

ReadAsync
public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
result = sizeTrackingStream.ReadAsync(buffer, offset, count, cancellationToken)
Seek
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.

返回值: The new position within the current stream.

SetLength
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.
Write
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.
WriteAsync
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
result = sizeTrackingStream.WriteAsync(buffer, offset, count, cancellationToken)