Class CompressionExtensions
Extension methods on byte[] and byte[][] that expose the full
ScyllaCompression API in a fluent, instance-method style.
Inherited Members
Namespace: Scylla.Core.Util.Compression
Assembly: ScyllaCore.dll
Syntax
public static class CompressionExtensions
Remarks
Every method in this class is a thin forwarding wrapper that calls the equivalent static method on ScyllaCompression. No additional logic is added here; the authoritative documentation for each operation is on ScyllaCompression.
Method categories exposed as extensions:
- Algorithm detection - DetectCompressionAlgorithm(byte[])
- Byte array compress/decompress - synchronous and async
- Combined compress+encrypt / decrypt+decompress - synchronous and async
- Batch compress/decompress on
byte[][]- synchronous and async
Stream, file, and archive operations do not have extension-method equivalents here; use ScyllaCompression directly for those.
Methods
Compress(byte[])
Compresses this byte array using DefaultAlgorithm and DefaultLevel.
Declaration
public static byte[] Compress(this byte[] data)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The data to compress. Must not be |
Returns
| Type | Description |
|---|---|
| byte[] | The compressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when compression fails or |
Compress(byte[], CompressionAlgorithm)
Compresses this byte array using the specified algorithm at the default compression level. Internally constructs a CompressionSettings with the given algorithm; all other settings use their default values.
Declaration
public static byte[] Compress(this byte[] data, CompressionAlgorithm algorithm)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The data to compress. Must not be |
| CompressionAlgorithm | algorithm | The compression algorithm to use. Algorithms other than GZip
and Deflate require the |
Returns
| Type | Description |
|---|---|
| byte[] | The compressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when compression fails, the algorithm is unsupported, or |
Compress(byte[], CompressionSettings)
Compresses this byte array using the algorithm and level from settings.
Declaration
public static byte[] Compress(this byte[] data, CompressionSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The data to compress. Must not be |
| CompressionSettings | settings | Compression settings. Pass |
Returns
| Type | Description |
|---|---|
| byte[] | The compressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when compression fails or |
CompressAndEncrypt(byte[], string)
Compresses this byte array using default settings and then encrypts the result. See CompressAndEncrypt(byte[], string) for full details.
Declaration
public static byte[] CompressAndEncrypt(this byte[] data, string password)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The plaintext data to compress and encrypt. Must not be |
| string | password | The encryption password. Must not be |
Returns
| Type | Description |
|---|---|
| byte[] | The compressed-then-encrypted byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when compression fails or the password is empty. |
| CryptoException | Thrown when encryption fails. |
CompressAndEncrypt(byte[], string, CompressionSettings, CryptoSettings)
Compresses this byte array with custom settings and then encrypts the result. See CompressAndEncrypt(byte[], string, CompressionSettings, CryptoSettings) for full details.
Declaration
public static byte[] CompressAndEncrypt(this byte[] data, string password, CompressionSettings compressionSettings, CryptoSettings cryptoSettings = null)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The plaintext data to compress and encrypt. Must not be |
| string | password | The encryption password. Must not be |
| CompressionSettings | compressionSettings | Compression settings. Pass |
| CryptoSettings | cryptoSettings | Encryption settings, or |
Returns
| Type | Description |
|---|---|
| byte[] | The compressed-then-encrypted byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when compression fails or the password is empty. |
| CryptoException | Thrown when encryption fails. |
CompressAndEncryptAsync(byte[], string, CompressionSettings, CryptoSettings, CancellationToken)
Asynchronously compresses this byte array with custom settings and then encrypts the result.
Declaration
public static Task<byte[]> CompressAndEncryptAsync(this byte[] data, string password, CompressionSettings compressionSettings, CryptoSettings cryptoSettings = null, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The plaintext data to compress and encrypt. Must not be |
| string | password | The encryption password. Must not be |
| CompressionSettings | compressionSettings | Compression settings. Pass |
| CryptoSettings | cryptoSettings | Encryption settings, or |
| CancellationToken | cancellationToken | Optional token to cancel the compression step. |
Returns
| Type | Description |
|---|---|
| Task<byte[]> | A task that resolves to the compressed-then-encrypted byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when compression fails or the password is empty. |
| CryptoException | Thrown when encryption fails. |
CompressAndEncryptAsync(byte[], string, CancellationToken)
Asynchronously compresses this byte array using default settings and then encrypts the result.
Declaration
public static Task<byte[]> CompressAndEncryptAsync(this byte[] data, string password, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The plaintext data to compress and encrypt. Must not be |
| string | password | The encryption password. Must not be |
| CancellationToken | cancellationToken | Optional token to cancel the compression step. |
Returns
| Type | Description |
|---|---|
| Task<byte[]> | A task that resolves to the compressed-then-encrypted byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when compression fails or the password is empty. |
| CryptoException | Thrown when encryption fails. |
CompressAsync(byte[], CompressionAlgorithm, CancellationToken)
Asynchronously compresses this byte array using the specified algorithm at the default compression level.
Declaration
public static Task<byte[]> CompressAsync(this byte[] data, CompressionAlgorithm algorithm, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The data to compress. Must not be |
| CompressionAlgorithm | algorithm | The compression algorithm to use. Algorithms other than GZip
and Deflate require the |
| CancellationToken | cancellationToken | Optional token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<byte[]> | A task that resolves to the compressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when compression fails, the algorithm is unsupported, or |
CompressAsync(byte[], CompressionSettings, CancellationToken)
Asynchronously compresses this byte array using the algorithm and level from
settings.
Declaration
public static Task<byte[]> CompressAsync(this byte[] data, CompressionSettings settings, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The data to compress. Must not be |
| CompressionSettings | settings | Compression settings. Pass |
| CancellationToken | cancellationToken | Optional token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<byte[]> | A task that resolves to the compressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when compression fails or |
CompressAsync(byte[], CancellationToken)
Asynchronously compresses this byte array using DefaultAlgorithm and DefaultLevel.
Declaration
public static Task<byte[]> CompressAsync(this byte[] data, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The data to compress. Must not be |
| CancellationToken | cancellationToken | Optional token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<byte[]> | A task that resolves to the compressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when compression fails or |
CompressBatch(byte[][])
Compresses each element of this jagged array in parallel using default settings, returning a new jagged array of compressed results in the same order. Useful for compressing many independent assets or data blobs simultaneously.
Declaration
public static byte[][] CompressBatch(this byte[][] dataArrays)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[][] | dataArrays | The jagged array of byte arrays to compress. Must not be |
Returns
| Type | Description |
|---|---|
| byte[][] | A jagged array of compressed byte arrays whose length equals
|
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when |
CompressBatch(byte[][], CompressionSettings)
Compresses each element of this jagged array in parallel using the provided settings, returning a new jagged array of compressed results in the same order.
Declaration
public static byte[][] CompressBatch(this byte[][] dataArrays, CompressionSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[][] | dataArrays | The jagged array of byte arrays to compress. Must not be |
| CompressionSettings | settings | Compression settings applied to every element. Pass |
Returns
| Type | Description |
|---|---|
| byte[][] | A jagged array of compressed byte arrays in the same order as the input. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when any element is |
CompressBatchAsync(byte[][], CompressionSettings, CancellationToken)
Asynchronously compresses each element of this jagged array using the provided settings, returning a new jagged array of compressed results in the same order.
Declaration
public static Task<byte[][]> CompressBatchAsync(this byte[][] dataArrays, CompressionSettings settings, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[][] | dataArrays | The jagged array of byte arrays to compress. Must not be |
| CompressionSettings | settings | Compression settings. Pass |
| CancellationToken | cancellationToken | Optional token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<byte[][]> | A task that resolves to a jagged array of compressed byte arrays. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when any element is |
CompressBatchAsync(byte[][], CancellationToken)
Asynchronously compresses each element of this jagged array using default settings, returning a new jagged array of compressed results in the same order.
Declaration
public static Task<byte[][]> CompressBatchAsync(this byte[][] dataArrays, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[][] | dataArrays | The jagged array of byte arrays to compress. Must not be |
| CancellationToken | cancellationToken | Optional token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<byte[][]> | A task that resolves to a jagged array of compressed byte arrays. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when any element is |
Decompress(byte[])
Decompresses this byte array using DefaultAlgorithm.
Declaration
public static byte[] Decompress(this byte[] compressedData)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | compressedData | The compressed data to decompress. Must not be |
Returns
| Type | Description |
|---|---|
| byte[] | The decompressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when decompression fails, the data is corrupted, or |
Decompress(byte[], CompressionAlgorithm)
Decompresses this byte array using the specified algorithm. Internally constructs a CompressionSettings with the given algorithm; all other settings use their default values.
Declaration
public static byte[] Decompress(this byte[] compressedData, CompressionAlgorithm algorithm)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | compressedData | The compressed data to decompress. Must not be |
| CompressionAlgorithm | algorithm | The compression algorithm that was used to produce this data. Must match the algorithm used during compression or the operation will fail. |
Returns
| Type | Description |
|---|---|
| byte[] | The decompressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when decompression fails, the data is corrupted, the algorithm is unsupported,
or |
Decompress(byte[], CompressionSettings)
Decompresses this byte array using the algorithm specified in settings.
Declaration
public static byte[] Decompress(this byte[] compressedData, CompressionSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | compressedData | The compressed data to decompress. Must not be |
| CompressionSettings | settings | Compression settings. Pass |
Returns
| Type | Description |
|---|---|
| byte[] | The decompressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when decompression fails, the data is corrupted, or |
DecompressAsync(byte[], CompressionAlgorithm, CancellationToken)
Asynchronously decompresses this byte array using the specified algorithm.
Declaration
public static Task<byte[]> DecompressAsync(this byte[] compressedData, CompressionAlgorithm algorithm, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | compressedData | The compressed data to decompress. Must not be |
| CompressionAlgorithm | algorithm | The compression algorithm that was used to produce this data. Must match the algorithm used during compression or the operation will fail. |
| CancellationToken | cancellationToken | Optional token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<byte[]> | A task that resolves to the decompressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when decompression fails, the data is corrupted, the algorithm is unsupported,
or |
DecompressAsync(byte[], CompressionSettings, CancellationToken)
Asynchronously decompresses this byte array using the algorithm specified in
settings.
Declaration
public static Task<byte[]> DecompressAsync(this byte[] compressedData, CompressionSettings settings, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | compressedData | The compressed data to decompress. Must not be |
| CompressionSettings | settings | Compression settings. Pass |
| CancellationToken | cancellationToken | Optional token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<byte[]> | A task that resolves to the decompressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when decompression fails, the data is corrupted, or |
DecompressAsync(byte[], CancellationToken)
Asynchronously decompresses this byte array using DefaultAlgorithm.
Declaration
public static Task<byte[]> DecompressAsync(this byte[] compressedData, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | compressedData | The compressed data to decompress. Must not be |
| CancellationToken | cancellationToken | Optional token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<byte[]> | A task that resolves to the decompressed byte array. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when decompression fails, the data is corrupted, or |
DecompressBatch(byte[][])
Decompresses each element of this jagged array in parallel using default settings, returning a new jagged array of decompressed results in the same order.
Declaration
public static byte[][] DecompressBatch(this byte[][] compressedArrays)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[][] | compressedArrays | The jagged array of compressed byte arrays to decompress. Must not be |
Returns
| Type | Description |
|---|---|
| byte[][] | A jagged array of decompressed byte arrays in the same order as the input. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when |
DecompressBatch(byte[][], CompressionSettings)
Decompresses each element of this jagged array in parallel using the provided settings, returning a new jagged array of decompressed results in the same order.
Declaration
public static byte[][] DecompressBatch(this byte[][] compressedArrays, CompressionSettings settings)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[][] | compressedArrays | The jagged array of compressed byte arrays to decompress. Must not be |
| CompressionSettings | settings | Compression settings that determine the algorithm for decompression. Must match the
algorithm used during compression. Pass |
Returns
| Type | Description |
|---|---|
| byte[][] | A jagged array of decompressed byte arrays in the same order as the input. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when any element is |
DecompressBatchAsync(byte[][], CompressionSettings, CancellationToken)
Asynchronously decompresses each element of this jagged array using the provided settings, returning a new jagged array of decompressed results in the same order.
Declaration
public static Task<byte[][]> DecompressBatchAsync(this byte[][] compressedArrays, CompressionSettings settings, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[][] | compressedArrays | The jagged array of compressed byte arrays to decompress. Must not be |
| CompressionSettings | settings | Compression settings that determine the algorithm for decompression. Must match the
algorithm used during compression. Pass |
| CancellationToken | cancellationToken | Optional token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<byte[][]> | A task that resolves to a jagged array of decompressed byte arrays. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when any element is |
DecompressBatchAsync(byte[][], CancellationToken)
Asynchronously decompresses each element of this jagged array using default settings, returning a new jagged array of decompressed results in the same order.
Declaration
public static Task<byte[][]> DecompressBatchAsync(this byte[][] compressedArrays, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[][] | compressedArrays | The jagged array of compressed byte arrays to decompress. Must not be |
| CancellationToken | cancellationToken | Optional token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<byte[][]> | A task that resolves to a jagged array of decompressed byte arrays. |
Exceptions
| Type | Condition |
|---|---|
| CompressionException | Thrown when any element is |
DecryptAndDecompress(byte[], string)
Decrypts this byte array and then decompresses the result using default settings. See DecryptAndDecompress(byte[], string) for full details.
Declaration
public static byte[] DecryptAndDecompress(this byte[] data, string password)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The encrypted and compressed data. Must not be |
| string | password | The decryption password. Must not be |
Returns
| Type | Description |
|---|---|
| byte[] | The decrypted and decompressed plaintext byte array. |
Exceptions
| Type | Condition |
|---|---|
| CryptoException | Thrown when decryption fails. |
| CompressionException | Thrown when decompression fails or the password is empty. |
DecryptAndDecompress(byte[], string, CompressionSettings, CryptoSettings)
Decrypts this byte array with custom settings and then decompresses the result. See DecryptAndDecompress(byte[], string, CompressionSettings, CryptoSettings) for full details.
Declaration
public static byte[] DecryptAndDecompress(this byte[] data, string password, CompressionSettings compressionSettings, CryptoSettings cryptoSettings = null)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The encrypted and compressed data. Must not be |
| string | password | The decryption password. Must not be |
| CompressionSettings | compressionSettings | Compression settings controlling the decompression algorithm. Must match the settings used when the data was originally compressed. |
| CryptoSettings | cryptoSettings | Decryption settings, or |
Returns
| Type | Description |
|---|---|
| byte[] | The decrypted and decompressed plaintext byte array. |
Exceptions
| Type | Condition |
|---|---|
| CryptoException | Thrown when decryption fails. |
| CompressionException | Thrown when decompression fails or the password is empty. |
DecryptAndDecompressAsync(byte[], string, CompressionSettings, CryptoSettings, CancellationToken)
Asynchronously decrypts this byte array with custom settings and then decompresses the result.
Declaration
public static Task<byte[]> DecryptAndDecompressAsync(this byte[] data, string password, CompressionSettings compressionSettings, CryptoSettings cryptoSettings = null, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The encrypted and compressed data. Must not be |
| string | password | The decryption password. Must not be |
| CompressionSettings | compressionSettings | Compression settings controlling the decompression algorithm. Must match the settings used when the data was originally compressed. |
| CryptoSettings | cryptoSettings | Decryption settings, or |
| CancellationToken | cancellationToken | Optional token to cancel the decompression step. |
Returns
| Type | Description |
|---|---|
| Task<byte[]> | A task that resolves to the decrypted and decompressed plaintext byte array. |
Exceptions
| Type | Condition |
|---|---|
| CryptoException | Thrown when decryption fails. |
| CompressionException | Thrown when decompression fails or the password is empty. |
DecryptAndDecompressAsync(byte[], string, CancellationToken)
Asynchronously decrypts this byte array and then decompresses the result using default settings.
Declaration
public static Task<byte[]> DecryptAndDecompressAsync(this byte[] data, string password, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | data | The encrypted and compressed data. Must not be |
| string | password | The decryption password. Must not be |
| CancellationToken | cancellationToken | Optional token to cancel the decompression step. |
Returns
| Type | Description |
|---|---|
| Task<byte[]> | A task that resolves to the decrypted and decompressed plaintext byte array. |
Exceptions
| Type | Condition |
|---|---|
| CryptoException | Thrown when decryption fails. |
| CompressionException | Thrown when decompression fails or the password is empty. |
DetectCompressionAlgorithm(byte[])
Attempts to identify the compression algorithm used to produce this byte array by inspecting its magic-number header. See DetectAlgorithm(byte[]) for the full list of recognisable magic numbers and their conditions.
Declaration
public static CompressionAlgorithm? DetectCompressionAlgorithm(this byte[] compressedData)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | compressedData | The compressed data to analyse. May be |
Returns
| Type | Description |
|---|---|
| CompressionAlgorithm? | The detected CompressionAlgorithm, or |