Zarr.NET  0.6.1
Zarr reader and writer in .NET
Loading...
Searching...
No Matches
ZarrNET.CodecPipeline Class Referencesealed

Applies an ordered list of codecs as a pipeline. More...

Public Member Functions

 CodecPipeline (IReadOnlyList< IZarrCodec > codecs, int elementSize)
 
Task< byte[]> DecodeAsync (byte[] input, CancellationToken ct=default)
 
Task< byte[]> EncodeAsync (byte[] input, CancellationToken ct=default)
 

Detailed Description

Applies an ordered list of codecs as a pipeline.

Zarr v3 codec pipeline: Decode: last codec → ... → first codec (compressed bytes → array bytes) Encode: first codec → ... → last codec (array bytes → compressed bytes)

The pipeline also resolves byte-order swapping for the BytesCodec based on the data type element size from ZarrArrayMetadata.

When all codecs in the pipeline are synchronous (returning completed Tasks), the decode/encode path avoids async state machine overhead entirely. This is the common case for Blosc, Zstd, and BytesCodec pipelines.

Constructor & Destructor Documentation

◆ CodecPipeline()

ZarrNET.CodecPipeline.CodecPipeline ( IReadOnlyList< IZarrCodec > codecs,
int elementSize )
24 {
25 _codecs = codecs;
26 _elementSize = elementSize;
27
28 // Detect whether every codec in the pipeline is synchronous.
29 // Synchronous codecs return Task.FromResult — we identify them by
30 // interface marker or by known type. GzipCodec is the only async
31 // codec in the codebase (uses Stream.CopyToAsync).
32 _allCodecsSync = codecs.All(c => c is not GzipCodec);
33 }

Member Function Documentation

◆ DecodeAsync()

Task< byte[]> ZarrNET.CodecPipeline.DecodeAsync ( byte[] input,
CancellationToken ct = default )
40 {
41 // Fast path: when all codecs are synchronous, avoid async state machine
42 if (_allCodecsSync)
43 return Task.FromResult(DecodeSynchronous(input, ct));
44
45 return DecodeAsyncCore(input, ct);
46 }

◆ EncodeAsync()

Task< byte[]> ZarrNET.CodecPipeline.EncodeAsync ( byte[] input,
CancellationToken ct = default )
49 {
50 if (_allCodecsSync)
51 return Task.FromResult(EncodeSynchronous(input, ct));
52
53 return EncodeAsyncCore(input, ct);
54 }

The documentation for this class was generated from the following file: