Class AvroFileWriter<T>
- Namespace
- AvroSharp.Containers
- Assembly
- AvroSharp.dll
Writes an Avro object container file: a header holding the schema, then blocks of objects, each compressed with the file's codec and followed by the sync marker. Objects are buffered until a block reaches SyncInterval or 65,536 objects; Flush() and Dispose() write the rest. The header is written with the first block, or when the writer is flushed or disposed. The asynchronous members (WriteAsync(T, CancellationToken), FlushAsync(CancellationToken), DisposeAsync()) do no synchronous I/O.
public sealed class AvroFileWriter<T> : IDisposable, IAsyncDisposable
Type Parameters
TThe type of the objects.
- Inheritance
-
AvroFileWriter<T>
- Implements
- Inherited Members
Remarks
Instances are not thread-safe.
Properties
- Codec
Gets the codec that compresses each block.
- Schema
Gets the schema of the objects.
- SyncMarker
Gets the file's sync marker, the 16 bytes that follow every block: random for a new file, the file's own when appending.
Methods
- Dispose()
Writes the buffered objects, flushes the stream and, unless the options say otherwise, disposes it.
- DisposeAsync()
Writes the buffered objects, flushes the stream and, unless the options say otherwise, disposes it, all asynchronously.
- Flush()
Writes the buffered objects as a block, if there are any, and flushes the stream.
- FlushAsync(CancellationToken)
Writes the buffered objects as a block, if there are any, and flushes the stream, asynchronously.
- Sync()
Writes the buffered objects as a block, if there are any, and returns the position after it: where the next block starts, which Seek(long) accepts, as Apache Avro Java's
DataFileWriter.sync()returns. The position counts from where the stream was when the writer was created (from 0 when the stream can't seek). The stream itself is not flushed.
- SyncAsync(CancellationToken)
Writes the buffered objects as a block, as Sync() does, asynchronously, and returns the position after it.
- Write(T)
Appends one object, writing a block when the buffered objects reach the sync interval.
- WriteAsync(T, CancellationToken)
Appends one object; when the buffered objects reach the sync interval, the block is written to the stream asynchronously. The object itself is encoded synchronously, into memory.
- WriteBlock(AvroFileBlock, bool)
Writes a block read from another file (TryReadBlock(out AvroFileBlock?)) after the objects written so far, without decoding its objects. A block compressed with this file's codec is copied byte for byte, unless
recompressis set; any other block is decompressed with its codec and compressed with this file's.
- WriteBlockAsync(AvroFileBlock, bool, CancellationToken)
Writes a block read from another file, as WriteBlock(AvroFileBlock, bool) does, asynchronously.