Represents buffered file reader.
Namespace: DotNext.IO Assembly: DotNext.IO.dll Syntaxpublic class FileReader : Disposable, IAsyncBinaryReader, IBufferedReader, IBufferedChannel, IResettable, IDisposable, IAsyncEnumerable<ReadOnlyMemory<byte>>, IDynamicInterfaceCastable
Constructors | Edit this page View Source FileReader(SafeFileHandle)
Initializes a new buffered file reader.
Declarationpublic FileReader(SafeFileHandle handle)
Parameters Exceptions | Edit this page View Source FileReader(FileStream)
Initializes a new buffered file reader.
Declarationpublic FileReader(FileStream source)
Parameters Type Name Description FileStream source
Readable file stream.
Exceptions Fields | Edit this page View Source handleRepresents the file handle.
Declarationprotected readonly SafeFileHandle handle
Field Value Properties | Edit this page View Source Allocator
Gets buffer allocator.
Declarationpublic MemoryAllocator<byte>? Allocator { get; init; }
Property Value | Edit this page View Source Buffer
Gets unconsumed part of the buffer.
Declarationpublic ReadOnlyMemory<byte> Buffer { get; }
Property Value | Edit this page View Source FilePosition
Gets or sets the cursor position within the file.
Declarationpublic long FilePosition { get; set; }
Property Value Exceptions | Edit this page View Source HasBufferedData
Gets a value indicating that the read buffer is not empty.
Declarationpublic bool HasBufferedData { get; }
Property Value | Edit this page View Source MaxBufferSize
Gets the maximum size of the internal buffer.
Declarationpublic int MaxBufferSize { get; init; }
Property Value | Edit this page View Source ReadPosition
Gets the read position within the file.
Declarationpublic long ReadPosition { get; }
Property Value | Edit this page View Source ReaderSegmentLength
Limits the number of available bytes to read.
Declarationpublic long? ReaderSegmentLength { set; }
Property Value Type Description long?
The number of available bytes to read; or null to allow read to the end of the file.
Exceptions Methods | Edit this page View Source Consume(int)Advances read position.
Declarationpublic void Consume(int count)
Parameters Type Name Description int count
The number of consumed bytes.
Exceptions | Edit this page View Source CopyToAsync<TConsumer>(TConsumer, long, CancellationToken)Reads the entire content using the specified delegate.
Declarationpublic ValueTask CopyToAsync<TConsumer>(TConsumer consumer, long count, CancellationToken token = default) where TConsumer : ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>
Parameters Type Name Description TConsumer consumer
The content reader.
long countThe number of bytes to copy.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing asynchronous result.
Type Parameters Name Description TConsumerThe type of the consumer.
Exceptions | Edit this page View Source CopyToAsync<TConsumer>(TConsumer, CancellationToken)Reads the entire content using the specified delegate.
Declarationpublic ValueTask CopyToAsync<TConsumer>(TConsumer consumer, CancellationToken token = default) where TConsumer : ISupplier<ReadOnlyMemory<byte>, CancellationToken, ValueTask>
Parameters Type Name Description TConsumer consumer
The content reader.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTaskThe task representing asynchronous result.
Type Parameters Name Description TConsumerThe type of the consumer.
Exceptions | Edit this page View Source DecodeAsync(DecodingContext, LengthFormat, MemoryAllocator<char>?, CancellationToken)Decodes the sequence of characters.
Declarationpublic ValueTask<MemoryOwner<char>> DecodeAsync(DecodingContext context, LengthFormat lengthFormat, MemoryAllocator<char>? allocator = null, CancellationToken token = default)
Parameters Type Name Description DecodingContext context
The decoding context containing string characters encoding.
LengthFormat lengthFormatThe format of the string length encoded in the stream.
MemoryAllocator<char> allocatorThe allocator of the buffer of characters.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Exceptions | Edit this page View Source DecodeAsync(DecodingContext, LengthFormat, Memory<char>, CancellationToken)Decodes the sequence of characters.
Declarationpublic IAsyncEnumerable<ReadOnlyMemory<char>> DecodeAsync(DecodingContext context, LengthFormat lengthFormat, Memory<char> buffer, CancellationToken token = default)
Parameters Type Name Description DecodingContext context
The decoding context containing string characters encoding.
LengthFormat lengthFormatThe format of the string length encoded in the stream.
Memory<char> bufferThe buffer of characters.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Exceptions | Edit this page View Source Dispose(bool)Releases managed and unmanaged resources associated with this object.
Declarationprotected override void Dispose(bool disposing)
Parameters Overrides | Edit this page View Source ParseAsync<T>(LengthFormat, NumberStyles, IFormatProvider?, CancellationToken)
Parses the numeric value from UTF-8 encoded characters.
Declarationpublic ValueTask<T> ParseAsync<T>(LengthFormat lengthFormat, NumberStyles style, IFormatProvider? provider = null, CancellationToken token = default) where T : INumberBase<T>
Parameters Type Name Description LengthFormat lengthFormat
The format of the string length (in bytes) encoded in the stream.
NumberStyles styleA combination of number styles.
IFormatProvider providerCulture-specific formatting information.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<T>The result of parsing.
Type Parameters Name Description TThe numeric type.
Exceptions | Edit this page View Source ParseAsync<T>(LengthFormat, IFormatProvider?, CancellationToken)Parses the sequence of characters encoded as UTF-8.
Declarationpublic ValueTask<T> ParseAsync<T>(LengthFormat lengthFormat, IFormatProvider? provider = null, CancellationToken token = default) where T : IUtf8SpanParsable<T>
Parameters Type Name Description LengthFormat lengthFormat
The format of the string length (in bytes) encoded in the stream.
IFormatProvider providerCulture-specific formatting information.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<T>The result of parsing.
Type Parameters Name Description TThe type that supports parsing from UTF-8.
Exceptions | Edit this page View Source Read()Reads the data from the file to the underlying buffer.
Declaration Returns Type Description booltrue if the data has been copied from the file to the internal buffer; false if no more data to read.
Exceptions | Edit this page View Source Read(Span<byte>)Reads the block of the memory.
Declarationpublic int Read(Span<byte> destination)
Parameters Type Name Description Span<byte> destination
The output buffer.
Returns Type Description intThe number of bytes copied to destination
.
Reads the memory block.
Declarationpublic ValueTask<MemoryOwner<byte>> ReadAsync(LengthFormat lengthFormat, MemoryAllocator<byte>? allocator = null, CancellationToken token = default)
Parameters Type Name Description LengthFormat lengthFormat
The format of the string length encoded in the stream.
MemoryAllocator<byte> allocatorAn allocator of the resulting buffer.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Exceptions | Edit this page View Source ReadAsync(Memory<byte>, CancellationToken)Reads the block of the memory.
Declarationpublic ValueTask<int> ReadAsync(Memory<byte> destination, CancellationToken token = default)
Parameters Type Name Description Memory<byte> destination
The output buffer.
CancellationToken tokenThe token that can be used to cancel the operation.
Returns Type Description ValueTask<int>The number of bytes copied to destination
.
Fetches the data from the underlying storage to the internal buffer.
Declarationpublic ValueTask<bool> ReadAsync(CancellationToken token = default)
Parameters Type Name Description CancellationToken token
The token that can be used to cancel the operation.
Returns Type Description ValueTask<bool>true if the data has been copied from the underlying storage to the internal buffer; false if no more data to read.
Exceptions | Edit this page View Source ReadAsync<T>(CancellationToken)Decodes the value of binary formattable type.
Declarationpublic ValueTask<T> ReadAsync<T>(CancellationToken token = default) where T : IBinaryFormattable<T>
Parameters Type Name Description CancellationToken token
The token that can be used to cancel the operation.
Returns Type Description ValueTask<T>The decoded value.
Type Parameters Name Description TThe type of the result.
Exceptions | Edit this page View Source ReadBigEndianAsync<T>(CancellationToken)Reads integer encoded in big-endian format.
Declarationpublic ValueTask<T> ReadBigEndianAsync<T>(CancellationToken token = default) where T : IBinaryInteger<T>
Parameters Type Name Description CancellationToken token
The token that can be used to cancel the operation.
Returns Type Description ValueTask<T>The integer value.
Type Parameters Name Description TThe integer type.
Exceptions | Edit this page View Source ReadLittleEndianAsync<T>(CancellationToken)Reads integer encoded in little-endian format.
Declarationpublic ValueTask<T> ReadLittleEndianAsync<T>(CancellationToken token = default) where T : IBinaryInteger<T>
Parameters Type Name Description CancellationToken token
The token that can be used to cancel the operation.
Returns Type Description ValueTask<T>The integer value.
Type Parameters Name Description TThe integer type.
Exceptions | Edit this page View Source Reset()Clears the read buffer.
Declaration | Edit this page View Source Skip(long)Skips the specified number of bytes and advances file read cursor.
Declarationpublic void Skip(long count)
Parameters Type Name Description long count
The number of bytes to skip.
Exceptions Implements Extension MethodsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4