Table of Contents

Class ByteArrayAsyncExtensions

Namespace
Plugin.ByteArrays
Assembly
Plugin.ByteArrays.dll

Asynchronous operations for byte arrays.

public static class ByteArrayAsyncExtensions
Inheritance
ByteArrayAsyncExtensions
Inherited Members

Methods

ComputeHashAsync(byte[], string, CancellationToken)

Asynchronously computes a hash of the byte array using the specified algorithm.

public static Task<byte[]> ComputeHashAsync(this byte[] data, string algorithmName, CancellationToken cancellationToken = default)

Parameters

data byte[]

The data to hash.

algorithmName string

The hash algorithm name (e.g., "SHA256", "MD5").

cancellationToken CancellationToken

The cancellation token.

Returns

Task<byte[]>

A task representing the asynchronous operation with the computed hash.

CopyToStreamAsync(byte[], Stream, int, CancellationToken)

Asynchronously copies a byte array to a stream in chunks.

public static Task CopyToStreamAsync(this byte[] data, Stream stream, int chunkSize = 4096, CancellationToken cancellationToken = default)

Parameters

data byte[]

The data to copy to the stream.

stream Stream

The destination stream.

chunkSize int

The size of each chunk (default 4096).

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A task representing the asynchronous operation.

IndexOfAsync(byte[], byte[], CancellationToken)

Asynchronously searches for a pattern in the byte array.

public static Task<int> IndexOfAsync(this byte[] data, byte[] pattern, CancellationToken cancellationToken = default)

Parameters

data byte[]

The data to search in.

pattern byte[]

The pattern to search for.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<int>

A task representing the asynchronous operation with the index of the first occurrence, or -1 if not found.

ProcessInParallelAsync<TResult>(byte[], Func<byte[], Task<TResult>>, int, int, CancellationToken)

Asynchronously processes byte array data in parallel chunks.

public static Task<TResult[]> ProcessInParallelAsync<TResult>(this byte[] data, Func<byte[], Task<TResult>> processor, int chunkSize = 4096, int maxConcurrency = 0, CancellationToken cancellationToken = default)

Parameters

data byte[]

The data to process.

processor Func<byte[], Task<TResult>>

The function to process each chunk.

chunkSize int

The size of each chunk (default 4096).

maxConcurrency int

The maximum number of concurrent operations (default Environment.ProcessorCount).

cancellationToken CancellationToken

The cancellation token.

Returns

Task<TResult[]>

A task representing the asynchronous operation with the processed results.

Type Parameters

TResult

The type of the result.

ReadFromFileAsync(string, CancellationToken)

Asynchronously reads a byte array from a file.

public static Task<byte[]> ReadFromFileAsync(string filePath, CancellationToken cancellationToken = default)

Parameters

filePath string

The path to the file to read.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<byte[]>

A task representing the asynchronous operation with the file content as byte array.

ReadFromStreamAsync(Stream, int, CancellationToken)

Asynchronously reads a byte array from a stream.

public static Task<byte[]> ReadFromStreamAsync(Stream stream, int bufferSize = 4096, CancellationToken cancellationToken = default)

Parameters

stream Stream

The stream to read from.

bufferSize int

The buffer size for reading (default 4096).

cancellationToken CancellationToken

The cancellation token.

Returns

Task<byte[]>

A task representing the asynchronous operation with the stream content as byte array.

SequenceEqualAsync(byte[], byte[], CancellationToken)

Asynchronously compares two byte arrays for equality.

public static Task<bool> SequenceEqualAsync(this byte[] data1, byte[] data2, CancellationToken cancellationToken = default)

Parameters

data1 byte[]

The first byte array.

data2 byte[]

The second byte array.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<bool>

A task representing the asynchronous operation with the comparison result.

TransformAsync(byte[], Func<byte[], Task<byte[]>>, int, CancellationToken)

Asynchronously transforms byte array data using a transformation function.

public static Task<byte[]> TransformAsync(this byte[] data, Func<byte[], Task<byte[]>> transformer, int chunkSize = 4096, CancellationToken cancellationToken = default)

Parameters

data byte[]

The data to transform.

transformer Func<byte[], Task<byte[]>>

The transformation function.

chunkSize int

The size of each chunk for processing (default 4096).

cancellationToken CancellationToken

The cancellation token.

Returns

Task<byte[]>

A task representing the asynchronous operation with the transformed data.

VerifyIntegrityAsync(byte[], byte[], string, CancellationToken)

Asynchronously verifies the integrity of data against a provided hash.

public static Task<bool> VerifyIntegrityAsync(this byte[] data, byte[] expectedHash, string algorithmName, CancellationToken cancellationToken = default)

Parameters

data byte[]

The data to verify.

expectedHash byte[]

The expected hash value.

algorithmName string

The hash algorithm name.

cancellationToken CancellationToken

The cancellation token.

Returns

Task<bool>

A task representing the asynchronous operation with the verification result.

WriteToFileAsync(byte[], string, CancellationToken)

Asynchronously writes the byte array to a file.

public static Task WriteToFileAsync(this byte[] data, string filePath, CancellationToken cancellationToken = default)

Parameters

data byte[]

The data to write to the file.

filePath string

The path to the file to write.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A task representing the asynchronous operation.

WriteToStreamAsync(byte[], Stream, CancellationToken)

Asynchronously writes the byte array to a stream.

public static Task WriteToStreamAsync(this byte[] data, Stream stream, CancellationToken cancellationToken = default)

Parameters

data byte[]

The data to write to the stream.

stream Stream

The stream to write to.

cancellationToken CancellationToken

The cancellation token.

Returns

Task

A task representing the asynchronous operation.