< Summary

Information
Class: DeltaSharp.DeltaApplyExtensions
Assembly: DeltaSharp
File(s): /home/runner/work/DeltaSharp/DeltaSharp/src/DeltaSharp/DeltaApplyExtensions.cs
Line coverage
90%
Covered lines: 9
Uncovered lines: 1
Coverable lines: 10
Total lines: 44
Line coverage: 90%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Apply(...)83.33%6688.88%

File(s)

/home/runner/work/DeltaSharp/DeltaSharp/src/DeltaSharp/DeltaApplyExtensions.cs

#LineLine coverage
 1namespace DeltaSharp;
 2
 3/// <summary>Provides output-size-limited patch application for <see cref="IDeltaApply"/> implementations.</summary>
 4public static class DeltaApplyExtensions
 5{
 6    /// <summary>Applies a patch after enforcing an output-size limit in bytes.</summary>
 7    /// <param name="apply">The applier for the patch's format and checksum algorithm.</param>
 8    /// <param name="source">The original source bytes against which the patch was created.</param>
 9    /// <param name="delta">The encoded patch, including its output-length header and final checksum.</param>
 10    /// <param name="maxOutputLength">The maximum permitted target length in bytes; zero permits only empty output.</par
 11    /// <returns>The reconstructed target in newly allocated memory and its verified checksum.</returns>
 12    /// <remarks>
 13    /// The declared length is checked before allocating the output buffer. The limit bounds the target
 14    /// allocation, not total memory usage or processing time. Validation is delegated to
 15    /// <see cref="IDeltaApply.Apply(ReadOnlySpan{byte}, ReadOnlySpan{byte}, Memory{byte})"/>.
 16    /// </remarks>
 17    /// <exception cref="ArgumentNullException"><paramref name="apply"/> is null.</exception>
 18    /// <exception cref="ArgumentOutOfRangeException"><paramref name="maxOutputLength"/> is negative.</exception>
 19    /// <exception cref="DeltaApplyException">
 20    /// The declared length exceeds the limit, with <see cref="DeltaApplyException.Error"/> set to
 21    /// <see cref="DeltaApplyException.DeltaApplyExceptionError.OutputLengthLimitExceeded"/>,
 22    /// or the applier rejects the patch during validation.
 23    /// </exception>
 24    /// <exception cref="Format.DeltaReaderException">The format reader rejects malformed command syntax.</exception>
 25    public static DeltaResult Apply(this IDeltaApply apply, ReadOnlySpan<byte> source,
 26        ReadOnlySpan<byte> delta, int maxOutputLength)
 27    {
 65028        if (apply is null)
 029            throw new ArgumentNullException(nameof(apply));
 65030        if (maxOutputLength < 0)
 3031            throw new ArgumentOutOfRangeException(nameof(maxOutputLength));
 32
 62033        var outputLength = apply.GetOutputLength(delta);
 59034        if (outputLength > (ulong)maxOutputLength)
 25035            throw new DeltaApplyException(DeltaApplyException.DeltaApplyExceptionError.OutputLengthLimitExceeded);
 36
 37#if NETSTANDARD2_0
 6838        var buffer = new byte[(int)outputLength];
 39#else
 27240        var buffer = GC.AllocateUninitializedArray<byte>((int)outputLength);
 41#endif
 34042        return apply.Apply(source, delta, buffer.AsMemory());
 43    }
 44}