CompressionHelper
Provides helper methods for compressing and decompressing data using various algorithms.
メソッド
public static Task<byte[]> CompressAsync<TCompressStream>(byte[] input, int? index, int? count, CompressionLevel level, int bufferSize, CancellationToken cancellationToken)
result = CompressionHelper.CompressAsync(input, index, count, level, bufferSize, cancellationToken)
Asynchronously compresses a portion of a byte array using the specified compression stream.
- input
- The byte array to compress.
- index
- The starting index for compression.
- count
- The number of bytes to compress.
- level
- The compression level to use.
- bufferSize
- The buffer size to use during compression.
- cancellationToken
- A token to monitor for cancellation requests.
戻り値: A task representing the asynchronous operation, with a compressed byte array as the result.
public static Task CompressAsync<TCompressStream>(Stream input, Stream output, CompressionLevel level, bool leaveOpen, int bufferSize, CancellationToken cancellationToken)
result = CompressionHelper.CompressAsync(input, output, level, leaveOpen, bufferSize, cancellationToken)
Asynchronously compresses data from the input stream and writes the compressed data to the output stream using the specified compression stream.
- input
- The input stream containing data to compress.
- output
- The output stream to write compressed data to.
- level
- The compression level to use.
- leaveOpen
- Whether to leave the output stream open after compression.
- bufferSize
- The buffer size to use during compression.
- cancellationToken
- A token to monitor for cancellation requests.
戻り値: A task representing the asynchronous compression operation.
public static Task<byte[]> CompressAsync<TCompressStream>(ReadOnlyMemory<byte> input, CompressionLevel level, int bufferSize, CancellationToken cancellationToken)
result = CompressionHelper.CompressAsync(input, level, bufferSize, cancellationToken)
Asynchronously compresses a read-only memory of bytes using the specified compression stream.
- input
- The read-only memory containing data to compress.
- level
- The compression level to use.
- bufferSize
- The buffer size to use during compression.
- cancellationToken
- A token to monitor for cancellation requests.
戻り値: A task representing the asynchronous operation, with a compressed byte array as the result.
public static byte[] Compress<TCompressStream>(byte[] input, int? index, int? count, CompressionLevel level, int bufferSize)
result = CompressionHelper.Compress(input, index, count, level, bufferSize)
Compresses a portion of a byte array using the specified compression stream.
- input
- The byte array to compress.
- index
- The starting index for compression.
- count
- The number of bytes to compress.
- level
- The compression level to use.
- bufferSize
- The buffer size to use during compression.
戻り値: A compressed byte array.
public static byte[] DeflateFrom(byte[] input, int? index, int? count, int bufferSize)
result = CompressionHelper.DeflateFrom(input, index, count, bufferSize)
Decompresses a portion of a byte array using the Deflate algorithm.
- input
- The byte array to decompress.
- index
- The starting index from which to begin decompression.
- count
- The number of bytes to decompress.
- bufferSize
- The buffer size to use during decompression.
戻り値: A decompressed byte array.
public static byte[] DeflateFrom(ReadOnlySpan<byte> input, int bufferSize)
result = CompressionHelper.DeflateFrom(input, bufferSize)
Decompresses a span of bytes using the Deflate algorithm.
- input
- The span to decompress.
- bufferSize
- The buffer size to use during decompression.
戻り値: A decompressed byte array.
public static byte[] DeflateTo(byte[] input)
result = CompressionHelper.DeflateTo(input)
Compresses the specified byte array using the Deflate algorithm.
- input
- The byte array to compress.
戻り値: A compressed byte array.
public static byte[] Do7Zip(byte[] input)
result = CompressionHelper.Do7Zip(input)
Compresses the specified byte array using the 7Zip (LZMA) algorithm.
- input
- The byte array to compress.
戻り値: A compressed byte array with LZMA header (5 bytes properties + 8 bytes size + compressed data).
public static Task<byte[]> GZipAsync(byte[] data, CancellationToken cancellationToken)
result = CompressionHelper.GZipAsync(data, cancellationToken)
Compresses the data with GZip.
- data
- The data to compress.
- cancellationToken
- A token to monitor for cancellation requests.
戻り値: The GZip-compressed bytes.
public static byte[] Un7Zip(byte[] input)
result = CompressionHelper.Un7Zip(input)
Decompresses a 7Zip (LZMA) compressed byte array.
- input
- The byte array containing 7Zip-compressed data with LZMA header.
戻り値: A decompressed byte array.
public static Task UncompressAsync<TCompressStream>(Stream input, Stream output, bool leaveOpen, int bufferSize, CancellationToken cancellationToken)
result = CompressionHelper.UncompressAsync(input, output, leaveOpen, bufferSize, cancellationToken)
Asynchronously decompresses data from the input stream and writes the decompressed data to the output stream using the specified compression stream.
- input
- The input stream containing compressed data.
- output
- The output stream to write decompressed data to.
- leaveOpen
- Whether to leave the input stream open after decompression.
- bufferSize
- The buffer size to use during decompression.
- cancellationToken
- A token to monitor for cancellation requests.
戻り値: A task representing the asynchronous decompression operation.
public static Task<byte[]> UncompressAsync<TCompressStream>(byte[] input, int? index, int? count, int bufferSize, CancellationToken cancellationToken)
result = CompressionHelper.UncompressAsync(input, index, count, bufferSize, cancellationToken)
Asynchronously decompresses a portion of a byte array using the specified compression stream.
- input
- The byte array containing compressed data.
- index
- The starting index for decompression.
- count
- The number of bytes to decompress.
- bufferSize
- The buffer size to use during decompression.
- cancellationToken
- A token to monitor for cancellation requests.
戻り値: A task representing the asynchronous decompression operation, with a decompressed byte array as the result.
public static byte[] Uncompress<TCompressStream>(byte[] input, int? index, int? count, int bufferSize)
result = CompressionHelper.Uncompress(input, index, count, bufferSize)
Decompresses a portion of a byte array using the specified compression stream.
- input
- The byte array containing compressed data.
- index
- The starting index for decompression.
- count
- The number of bytes to decompress.
- bufferSize
- The buffer size to use during decompression.
戻り値: A decompressed byte array.
public static string UnDeflate(ReadOnlySpan<byte> input)
result = CompressionHelper.UnDeflate(input)
Decompresses a Deflate-compressed span of bytes into a UTF-8 encoded string.
- input
- The span containing Deflate-compressed data.
戻り値: A string resulting from decompression.
public static string UnDeflate(byte[] input, int index, int count)
result = CompressionHelper.UnDeflate(input, index, count)
Decompresses a portion of a Deflate-compressed byte array into a UTF-8 encoded string.
- input
- The byte array containing Deflate-compressed data.
- index
- The starting index for decompression.
- count
- The number of bytes to decompress.
戻り値: A string resulting from decompression.
public static string UnDeflate(byte[] input)
result = CompressionHelper.UnDeflate(input)
Decompresses a Deflate-compressed byte array into a UTF-8 encoded string.
- input
- The byte array containing Deflate-compressed data.
戻り値: A string resulting from decompression.
public static int UnDeflate(ReadOnlySpan<byte> input, Span<byte> destination)
result = CompressionHelper.UnDeflate(input, destination)
Decompresses a Deflate-compressed span of bytes into the provided destination span.
- input
- The span containing Deflate-compressed data.
- destination
- The span to store decompressed data.
戻り値: The number of bytes written into the destination span.
public static int UnDeflate(byte[] input, int index, int count, byte[] destination)
result = CompressionHelper.UnDeflate(input, index, count, destination)
Decompresses a portion of a Deflate-compressed byte array into the provided destination buffer.
- input
- The byte array containing Deflate-compressed data.
- index
- The starting index for decompression.
- count
- The number of bytes to decompress.
- destination
- The buffer to store decompressed data.
戻り値: The number of bytes written into the destination buffer.
public static int UnGZip(byte[] input, int index, int count, byte[] destination)
result = CompressionHelper.UnGZip(input, index, count, destination)
Decompresses a portion of a GZip-compressed byte array into the provided destination buffer.
- input
- The byte array containing GZip-compressed data.
- index
- The starting index for decompression.
- count
- The number of bytes to decompress.
- destination
- The buffer to store decompressed data.
戻り値: The number of bytes written into the destination buffer.
public static int UnGZip(ReadOnlySpan<byte> input, Span<byte> destination)
result = CompressionHelper.UnGZip(input, destination)
Decompresses a GZip-compressed span of bytes into the provided destination span.
- input
- The span containing GZip-compressed data.
- destination
- The span to store decompressed data.
戻り値: The number of bytes written into the destination span.
public static string UnGZip(byte[] input, int index, int count)
result = CompressionHelper.UnGZip(input, index, count)
Decompresses a GZip-compressed portion of a byte array into a UTF-8 encoded string.
- input
- The byte array containing GZip-compressed data.
- index
- The starting index from which to begin decompression.
- count
- The number of bytes to decompress.
戻り値: A string resulting from decompression.
public static string UnGZip(ReadOnlySpan<byte> input)
result = CompressionHelper.UnGZip(input)
Decompresses a GZip-compressed span of bytes into a UTF-8 encoded string.
- input
- The span containing GZip-compressed data.
戻り値: A string resulting from decompression.
public static string UnGZip(byte[] input)
result = CompressionHelper.UnGZip(input)
Decompresses a GZip-compressed byte array into a UTF-8 encoded string.
- input
- The byte array containing GZip-compressed data.
戻り値: A string resulting from decompression.
public static Task<byte[]> UnGZipAsync(byte[] data, CancellationToken cancellationToken)
result = CompressionHelper.UnGZipAsync(data, cancellationToken)
Decompresses GZip-compressed data to bytes.
- data
- The GZip-compressed data.
- cancellationToken
- A token to monitor for cancellation requests.
戻り値: The decompressed bytes.
public static IEnumerable<ValueTuple<string, Stream>> Unzip(byte[] input, Func<string, bool> filter)
result = CompressionHelper.Unzip(input, filter)
Extracts entries from a ZIP archive contained in the specified byte array.
- input
- The byte array containing the ZIP archive.
- filter
- A function to filter entries by name. Only entries returning true will be processed.
戻り値: An enumerable of entries. The enumerator must be disposed after use (foreach does this automatically).
public static IEnumerable<ValueTuple<string, Stream>> Unzip(Stream input, bool leaveOpen, Func<string, bool> filter)
result = CompressionHelper.Unzip(input, leaveOpen, filter)
Extracts entries from a ZIP archive contained in the specified stream.
- input
- The stream containing the ZIP archive.
- leaveOpen
- Whether to leave the underlying stream open after processing.
- filter
- A function to filter entries by name. Only entries returning true will be processed.
戻り値: An enumerable of entries. The enumerator must be disposed after use (foreach does this automatically).
public static void Zip(IEnumerable<ValueTuple<string, Stream>> entries, Stream output, CompressionLevel level, bool leaveOpen)
CompressionHelper.Zip(entries, output, level, leaveOpen)
Creates a ZIP archive from a collection of entries and writes it to the specified stream.
- entries
- The entries to include in the archive. Each entry is a tuple of (name, stream).
- output
- The output stream to write the ZIP archive to.
- level
- The compression level to use.
- leaveOpen
- Whether to leave the output stream open after creating the archive.
public static Task ZipAsync(IEnumerable<ValueTuple<string, Stream>> entries, Stream output, CompressionLevel level, bool leaveOpen, CancellationToken cancellationToken)
result = CompressionHelper.ZipAsync(entries, output, level, leaveOpen, cancellationToken)
Creates a ZIP archive from a collection of entries and writes it to the specified stream asynchronously.
- entries
- The entries to include in the archive. Each entry is a tuple of (name, stream).
- output
- The output stream to write the ZIP archive to.
- level
- The compression level to use.
- leaveOpen
- Whether to leave the output stream open after creating the archive.
- cancellationToken
- A token to monitor for cancellation requests.
フィールド
public const int DefaultBufferSize
value = CompressionHelper.DefaultBufferSize
Represents the default buffer size used in compression and decompression operations.