< Summary

Information
Class: Elsa.Common.Codecs.GZip
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Codecs/GZip.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 15
Coverable lines: 15
Total lines: 35
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CompressAsync()0%620%
DecompressAsync()0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Codecs/GZip.cs

#LineLine coverage
 1using System.IO.Compression;
 2using System.Text;
 3
 4namespace Elsa.Common.Codecs;
 5
 6/// <summary>
 7/// Represents a GZip compression strategy.
 8/// </summary>
 9public class GZip : ICompressionCodec
 10{
 11    /// <inheritdoc />
 12    public async ValueTask<string> CompressAsync(string input, CancellationToken cancellationToken)
 13    {
 014        var inputBytes = Encoding.UTF8.GetBytes(input);
 015        using var output = new MemoryStream();
 016        await using var compressionStream = new GZipStream(output, CompressionMode.Compress);
 017        await compressionStream.WriteAsync(inputBytes, 0, inputBytes.Length, cancellationToken);
 018        await compressionStream.FlushAsync(cancellationToken);
 19
 020        return Convert.ToBase64String(output.ToArray());
 021    }
 22
 23    /// <inheritdoc />
 24    public async ValueTask<string> DecompressAsync(string input, CancellationToken cancellationToken)
 25    {
 026        var inputBytes = Convert.FromBase64String(input);
 027        using var inputMemoryStream = new MemoryStream(inputBytes);
 028        await using var decompressionStream = new GZipStream(inputMemoryStream, CompressionMode.Decompress);
 029        using var outputMemoryStream = new MemoryStream();
 030        await decompressionStream.CopyToAsync(outputMemoryStream, cancellationToken);
 031        var decompressedBytes = outputMemoryStream.ToArray();
 32
 033        return Encoding.UTF8.GetString(decompressedBytes);
 034    }
 35}

Methods/Properties

CompressAsync()
DecompressAsync()