Table of Contents

Class AvroFileReader<T>

Namespace
AvroSharp.Containers
Assembly
AvroSharp.dll

Reads an Avro object container file: the header when opened, then the objects block by block. Each block is read whole, checked against the sync marker and decompressed before its objects are decoded. Reading is synchronous (TryRead(out T), ReadAll()) or asynchronous (ReadAllAsync(CancellationToken)); the asynchronous path does no synchronous I/O, and decodes each block synchronously once it is in memory.

public sealed class AvroFileReader<T> : IDisposable, IAsyncDisposable

Type Parameters

T

The type of the objects.

Inheritance
AvroFileReader<T>
Implements
Inherited Members

Remarks

Instances are not thread-safe.

Properties

Codec

Gets the codec the blocks are compressed with; its Name is the header's avro.codec.

Metadata

Gets the header metadata, including the avro.schema and avro.codec entries.

PreviousSync

Gets the stream position where the block of the most recently read object starts (just after the previous sync marker); Seek(long) returns to it. Before the first object, the first block's position.

WriterSchema

Gets the schema the objects were written with, from the header.

Methods

Dispose()

Releases the buffers and, unless the options say otherwise, disposes the stream.

DisposeAsync()

Releases the buffers and, unless the options say otherwise, disposes the stream asynchronously.

PastSync(long)

Gets whether the block of the most recently read object starts past a split that ends at position, so the object belongs to the next split. Read a split as: reader.Sync(start); while (reader.TryRead(out var value) && !reader.PastSync(end)) { ... }.

ReadAll()

Reads the remaining objects.

ReadAllAsync(CancellationToken)

Reads the remaining objects, reading each block from the stream asynchronously.

ReadAllPipelinedAsync(int, CancellationToken)

Reads the remaining objects with I/O and decompression running ahead of decoding: a background task reads and decompresses up to blocksAhead blocks while the caller decodes the current one. This helps most with the slower codecs (xz, bzip2) and slow streams; with the null codec on a fast stream it adds only overhead.

Seek(long)

Moves to a block start, a position PreviousSync returned; the next object read is that block's first.

Sync(long)

Moves to the block after the first sync marker that starts at or after position, found by scanning. A position at or before the header's own marker moves to the first block, even when the header's metadata happens to contain the marker. With no marker after the position, the reader is at the end.

TryGetMetadataString(string, out string?)

Gets a metadata entry decoded as UTF-8.

TryRead(out T)

Reads the next object.

See Also