OapCompressionCodec

Compression helpers for OAP asset blobs. Only Store and Deflate (raw RFC 1951) are implemented, which is the conformance baseline; Zstd is rejected.

Public Methods

Compress

public static byte[] Compress(OapCompression codec, ReadOnlySpan<byte> data)

Compresses data with codec.

Parameters:

  • codec (OapCompression): The codec to apply.
  • data (ReadOnlySpan): The plaintext bytes.

Returns: byte[]

  • The compressed (or, for Store, copied) bytes.

Decompress

public static byte[] Decompress(OapCompression codec, ReadOnlySpan<byte> data, long uncompressedSize)

Decompresses data with codec, producing exactly uncompressedSize bytes.

Parameters:

  • codec (OapCompression): The codec the blob was written with.
  • data (ReadOnlySpan): The stored (compressed) bytes.
  • uncompressedSize (long): The expected plaintext length.

Returns: byte[]

  • The plaintext bytes.

Best

public static (OapCompression Codec, byte[] Stored) Best(ReadOnlySpan<byte> data)

Picks the smaller of Store and Deflate for data, never inflating a blob. A quick probe on the first 4 KB avoids running full DEFLATE on incompressible data (random textures, already-compressed or encrypted payloads).

Parameters:

  • data (ReadOnlySpan): The plaintext bytes.

Returns: (OapCompression Codec, byte[] Stored)

  • The chosen codec and the bytes to store.