< Summary

Information
Class: Elsa.Common.Codecs.Zstd
Assembly: Elsa.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Common/Codecs/Zstd.cs
Line coverage
7%
Covered lines: 1
Uncovered lines: 12
Coverable lines: 13
Total lines: 36
Line coverage: 7.6%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Iron()100%11100%
CompressAsync(...)100%210%
DecompressAsync(...)100%210%

File(s)

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

#LineLine coverage
 1using System.Text;
 2using IronCompress;
 3
 4namespace Elsa.Common.Codecs;
 5
 6/// <summary>
 7/// Represents a ZSTD compression strategy.
 8/// </summary>
 9public class Zstd : ICompressionCodec
 10{
 111    private Iron Iron { get; set; } = new();
 12
 13    /// <inheritdoc />
 14    public ValueTask<string> CompressAsync(string input, CancellationToken cancellationToken = default)
 15    {
 016        var inputBytes = Encoding.UTF8.GetBytes(input);
 017        var span = inputBytes.AsSpan();
 018        var result = Iron.Compress(Codec.Zstd, span);
 019        var compressedBytes = result.AsSpan();
 020        var compressedString = Convert.ToBase64String(compressedBytes);
 21
 022        return new (compressedString);
 23    }
 24
 25    /// <inheritdoc />
 26    public ValueTask<string> DecompressAsync(string input, CancellationToken cancellationToken = default)
 27    {
 028        var inputBytes = Convert.FromBase64String(input);
 029        var span = inputBytes.AsSpan();
 030        var result = Iron.Decompress(Codec.Zstd, span);
 031        var decompressedBytes = result.AsSpan();
 032        var decompressedString = Encoding.UTF8.GetString(decompressedBytes);
 33
 034        return new (decompressedString);
 35    }
 36}