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

Blosc bytes-to-bytes codec. More...

Inheritance diagram for ZarrNET.BloscCodec:
ZarrNET.IZarrCodec

Public Member Functions

 BloscCodec (string cname="lz4", int clevel=5, BloscShuffle shuffle=BloscShuffle.ByteShuffle, int typesize=1, int blocksize=0)
 
Task< byte[]> DecodeAsync (byte[] input, CancellationToken ct=default)
 Decodes bytes produced by the previous codec step.
 
Task< byte[]> EncodeAsync (byte[] input, CancellationToken ct=default)
 Encodes bytes for the next codec step.
 
- Public Member Functions inherited from ZarrNET.IZarrCodec

Properties

string Name [get]
 Codec name as it appears in zarr.json (e.g. "gzip", "zstd", "bytes").
 
- Properties inherited from ZarrNET.IZarrCodec

Detailed Description

Blosc bytes-to-bytes codec.

Blosc is a meta-compressor: it applies an optional shuffle filter to improve compressibility, then compresses each block with an inner codec (lz4, zstd, zlib, blosclz, snappy). The 16-byte Blosc1 frame header stores the parameters needed to decode, so decoding is self-describing from the frame alone.

Blosc1 frame layout: [16-byte header] [bstarts table: nblocks x int32] – byte offsets of each block from the start of block data [block data – nblocks contiguous compressed/raw blocks]

Shuffle is applied per-block before compression, so unshuffle must also be per-block.

Supported inner codecs: lz4, lz4hc, zstd, zlib Unsupported (throws NotSupportedException): blosclz, snappy, bit-shuffle, split blocks

NuGet dependencies: K4os.Compression.LZ4 (lz4 / lz4hc inner codec) ZstdSharp.Port (zstd inner codec – already a project dependency)

Constructor & Destructor Documentation

◆ BloscCodec()

ZarrNET.BloscCodec.BloscCodec ( string cname = "lz4",
int clevel = 5,
BloscShuffle shuffle = BloscShuffle::ByteShuffle,
int typesize = 1,
int blocksize = 0 )
Parameters
cnameInner compressor name: "lz4", "lz4hc", "zstd", "zlib".
clevelCompression level. Meaning is inner-codec-specific.
shuffleShuffle filter applied before compression.
typesizeElement size in bytes, used by the shuffle filter.
blocksizeUncompressed block size in bytes. 0 = auto (256 KiB).
52 {
53 _cname = ParseInternalCodecName(cname);
54 _clevel = clevel;
55 _shuffle = shuffle;
56 _typesize = Math.Max(1, typesize);
57 _blocksize = blocksize;
58 }

Member Function Documentation

◆ DecodeAsync()

Task< byte[]> ZarrNET.BloscCodec.DecodeAsync ( byte[] input,
CancellationToken ct = default )

Decodes bytes produced by the previous codec step.

Implements ZarrNET.IZarrCodec.

65 {
66 ct.ThrowIfCancellationRequested();
67
68 var header = ParseFrameHeader(input);
69 var output = new byte[header.UncompressedBytes];
70
71 DecompressBlocks(input, header, output);
72
73 return Task.FromResult(output);
74 }

◆ EncodeAsync()

Task< byte[]> ZarrNET.BloscCodec.EncodeAsync ( byte[] input,
CancellationToken ct = default )

Encodes bytes for the next codec step.

Implements ZarrNET.IZarrCodec.

77 {
78 ct.ThrowIfCancellationRequested();
79
80 var blockSize = ResolveBlockSize(_blocksize, input.Length);
81 var blockCount = (input.Length + blockSize - 1) / blockSize;
82 var frame = CompressAndWriteFrame(input, blockSize, blockCount);
83
84 return Task.FromResult(frame);
85 }

Property Documentation

◆ Name

string ZarrNET.BloscCodec.Name
get

Codec name as it appears in zarr.json (e.g. "gzip", "zstd", "bytes").

Implements ZarrNET.IZarrCodec.


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