< Summary

Information
Class: DeltaSharp.DeltaSharp
Assembly: DeltaSharp
File(s): /home/runner/work/DeltaSharp/DeltaSharp/src/DeltaSharp/Delta.cs
Line coverage
100%
Covered lines: 34
Uncovered lines: 0
Coverable lines: 34
Total lines: 267
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Binary()100%11100%
get_Fossil()100%11100%
get_ASCII()100%11100%
.cctor()100%11100%
CreateBinary(...)100%11100%
CreateBinary(...)100%11100%
CreateFossil(...)100%11100%
CreateFossil(...)100%11100%
CreateASCII(...)100%11100%
CreateASCII(...)100%11100%
SelectCreator(...)100%44100%
ApplyBinary(...)100%11100%
ApplyBinaryInto(...)100%11100%
ApplyBinary(...)100%11100%
ApplyFossil(...)100%11100%
ApplyFossilInto(...)100%11100%
ApplyFossil(...)100%11100%
ApplyASCII(...)100%11100%
ApplyASCIIInto(...)100%11100%
ApplyASCII(...)100%11100%

File(s)

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

#LineLine coverage
 1using DeltaSharp.Format;
 2using System;
 3using System.Collections.Generic;
 4using System.Linq;
 5using System.Text;
 6using System.Threading.Tasks;
 7using System.Xml;
 8using static DeltaSharp.DeltaApplyException;
 9
 10namespace DeltaSharp;
 11
 12
 13/// <summary>Provides matching patch creation and application services for a delta format.</summary>
 14public interface IDelta
 15{
 16    /// <summary>Gets the service that applies patches in this format.</summary>
 17    IDeltaApply Apply { get; }
 18    /// <summary>Gets the service that creates patches in this format.</summary>
 19    IDeltaCreate Create { get; }
 20}
 21
 22/// <summary>Creates and applies Fossil-format patches using the Fossil additive checksum.</summary>
 23public class DeltaFossil: IDelta
 24{
 25    /// <inheritdoc cref="IDelta.Apply"/>
 26    public IDeltaApply Apply { get; }
 27    /// <inheritdoc cref="IDelta.Create"/>
 28    public IDeltaCreate Create { get; }
 29
 30    /// <summary>Initializes Fossil services with exhaustive source-match search for patch creation.</summary>
 31    public DeltaFossil() : this(DeltaSearchMode.Exhaustive)
 32    {
 33    }
 34
 35    /// <summary>Initializes Fossil services with the specified source-match search mode for patch creation.</summary>
 36    /// <param name="searchMode">The search-effort policy for the creation service; does not affect patch application.</
 37    /// <exception cref="ArgumentOutOfRangeException"><paramref name="searchMode"/> is not a defined search mode.</excep
 38    public DeltaFossil(DeltaSearchMode searchMode)
 39    {
 40        Apply = new DeltaApply<FossilDeltaReader, DeltaChecksum>();
 41        Create = new DeltaCreate<FossilDeltaWriter, DeltaChecksum>(new DeltaChecksum(), searchMode);
 42    }
 43
 44}
 45
 46/// <summary>Creates and applies DeltaSharp binary patches using the Fossil additive checksum.</summary>
 47public class DeltaBinary : IDelta
 48{
 49    /// <inheritdoc cref="IDelta.Apply"/>
 50    public IDeltaApply Apply { get; }
 51    /// <inheritdoc cref="IDelta.Create"/>
 52    public IDeltaCreate Create { get; }
 53
 54    /// <summary>Initializes binary services with exhaustive source-match search for patch creation.</summary>
 55    public DeltaBinary() : this(DeltaSearchMode.Exhaustive)
 56    {
 57    }
 58
 59    /// <summary>Initializes binary services with the specified source-match search mode for patch creation.</summary>
 60    /// <param name="searchMode">The search-effort policy for the creation service; does not affect patch application.</
 61    /// <exception cref="ArgumentOutOfRangeException"><paramref name="searchMode"/> is not a defined search mode.</excep
 62    public DeltaBinary(DeltaSearchMode searchMode)
 63    {
 64        Apply = new DeltaApply<BinaryDeltaReader, DeltaChecksum>();
 65        Create = new DeltaCreate<BinaryDeltaWriter, DeltaChecksum>(new DeltaChecksum(), searchMode);
 66    }
 67}
 68
 69/// <summary>Creates and applies DeltaSharp ASCII patches using the Fossil additive checksum.</summary>
 70/// <remarks>Command headers are ASCII text, but inserted payloads may contain arbitrary binary bytes.</remarks>
 71public class DeltaASCII : IDelta
 72{
 73    /// <inheritdoc cref="IDelta.Apply"/>
 74    public IDeltaApply Apply { get; }
 75    /// <inheritdoc cref="IDelta.Create"/>
 76    public IDeltaCreate Create { get; }
 77
 78    /// <summary>Initializes ASCII services with exhaustive source-match search for patch creation.</summary>
 79    public DeltaASCII() : this(DeltaSearchMode.Exhaustive)
 80    {
 81    }
 82
 83    /// <summary>Initializes ASCII services with the specified source-match search mode for patch creation.</summary>
 84    /// <param name="searchMode">The search-effort policy for the creation service; does not affect patch application.</
 85    /// <exception cref="ArgumentOutOfRangeException"><paramref name="searchMode"/> is not a defined search mode.</excep
 86    public DeltaASCII(DeltaSearchMode searchMode)
 87    {
 88        Apply = new DeltaApply<ASCIIDeltaReader, DeltaChecksum>();
 89        Create = new DeltaCreate<ASCIIDeltaWriter, DeltaChecksum>(new DeltaChecksum(), searchMode);
 90    }
 91}
 92
 93/// <summary>Provides shared services and convenience methods for binary, ASCII, and Fossil patches.</summary>
 94/// <remarks>
 95/// All built-in formats use the Fossil additive target checksum. Match the creation and application
 96/// formats, and supply the original source when applying a patch. Creation defaults to
 97/// <see cref="DeltaSearchMode.Exhaustive"/>; use an explicit mode to bound source-match candidates.
 98/// </remarks>
 99public static class DeltaSharp
 100{
 101    /// <summary>Gets shared binary-format services with exhaustive source-match search for creation.</summary>
 9870102    public static IDelta Binary { get; }
 103    /// <summary>Gets shared Fossil-format services with exhaustive source-match search for creation.</summary>
 9830104    public static IDelta Fossil { get; }
 105    /// <summary>Gets shared ASCII-format services with exhaustive source-match search for creation.</summary>
 9660106    public static IDelta ASCII { get; }
 107
 10108    private static readonly IDeltaCreate BoundedBinaryCreator =
 10109        new DeltaCreate<BinaryDeltaWriter, DeltaChecksum>(new DeltaChecksum(), DeltaSearchMode.Bounded);
 10110    private static readonly IDeltaCreate BoundedFossilCreator =
 10111        new DeltaCreate<FossilDeltaWriter, DeltaChecksum>(new DeltaChecksum(), DeltaSearchMode.Bounded);
 10112    private static readonly IDeltaCreate BoundedAsciiCreator =
 10113        new DeltaCreate<ASCIIDeltaWriter, DeltaChecksum>(new DeltaChecksum(), DeltaSearchMode.Bounded);
 114
 115    static DeltaSharp()
 116    {
 10117        Binary = new DeltaBinary();
 10118        Fossil = new DeltaFossil();
 10119        ASCII = new DeltaASCII();
 10120    }
 121
 122    /// <summary>Creates a binary patch using exhaustive source-match search.</summary>
 123    /// <param name="source">The original bytes that will be available when applying the patch; may be empty.</param>
 124    /// <param name="target">The desired reconstructed bytes; may be empty.</param>
 125    /// <returns>The binary patch bytes and the Fossil additive checksum of the target.</returns>
 126    public static DeltaResult CreateBinary(ReadOnlySpan<byte> source,ReadOnlySpan<byte> target)
 127    {
 2380128        return  Binary.Create.Create(source, target);
 129    }
 130
 131    /// <summary>Creates a binary patch using the selected source-match search mode.</summary>
 132    /// <param name="source">The original bytes that will be available when applying the patch; may be empty.</param>
 133    /// <param name="target">The desired reconstructed bytes; may be empty.</param>
 134    /// <param name="searchMode">The search-effort policy for this call.</param>
 135    /// <returns>The binary patch bytes and the Fossil additive checksum of the target.</returns>
 136    /// <exception cref="ArgumentOutOfRangeException"><paramref name="searchMode"/> is not a defined search mode.</excep
 137    public static DeltaResult CreateBinary(ReadOnlySpan<byte> source, ReadOnlySpan<byte> target, DeltaSearchMode searchM
 270138        => SelectCreator(searchMode, Binary.Create, BoundedBinaryCreator).Create(source, target);
 139
 140    /// <summary>Creates a Fossil patch using exhaustive source-match search.</summary>
 141    /// <param name="source">The original bytes that will be available when applying the patch; may be empty.</param>
 142    /// <param name="target">The desired reconstructed bytes; may be empty.</param>
 143    /// <returns>The Fossil patch bytes and the Fossil additive checksum of the target.</returns>
 144    public static DeltaResult CreateFossil(ReadOnlySpan<byte> source, ReadOnlySpan<byte> target)
 145    {
 2270146        return Fossil.Create.Create(source, target);
 147    }
 148
 149    /// <summary>Creates a Fossil patch using the selected source-match search mode.</summary>
 150    /// <param name="source">The original bytes that will be available when applying the patch; may be empty.</param>
 151    /// <param name="target">The desired reconstructed bytes; may be empty.</param>
 152    /// <param name="searchMode">The search-effort policy for this call.</param>
 153    /// <returns>The Fossil patch bytes and the Fossil additive checksum of the target.</returns>
 154    /// <exception cref="ArgumentOutOfRangeException"><paramref name="searchMode"/> is not a defined search mode.</excep
 155    public static DeltaResult CreateFossil(ReadOnlySpan<byte> source, ReadOnlySpan<byte> target, DeltaSearchMode searchM
 270156        => SelectCreator(searchMode, Fossil.Create, BoundedFossilCreator).Create(source, target);
 157
 158    /// <summary>Creates an ASCII patch using exhaustive source-match search.</summary>
 159    /// <param name="source">The original bytes that will be available when applying the patch; may be empty.</param>
 160    /// <param name="target">The desired reconstructed bytes; may be empty.</param>
 161    /// <returns>The ASCII patch bytes, including raw insert payloads, and the Fossil additive checksum of the target.</
 162    public static DeltaResult CreateASCII(ReadOnlySpan<byte> source, ReadOnlySpan<byte> target)
 163    {
 2270164        return ASCII.Create.Create(source, target);
 165    }
 166
 167    /// <summary>Creates an ASCII patch using the selected source-match search mode.</summary>
 168    /// <param name="source">The original bytes that will be available when applying the patch; may be empty.</param>
 169    /// <param name="target">The desired reconstructed bytes; may be empty.</param>
 170    /// <param name="searchMode">The search-effort policy for this call.</param>
 171    /// <returns>The ASCII patch bytes, including raw insert payloads, and the Fossil additive checksum of the target.</
 172    /// <exception cref="ArgumentOutOfRangeException"><paramref name="searchMode"/> is not a defined search mode.</excep
 173    public static DeltaResult CreateASCII(ReadOnlySpan<byte> source, ReadOnlySpan<byte> target, DeltaSearchMode searchMo
 290174        => SelectCreator(searchMode, ASCII.Create, BoundedAsciiCreator).Create(source, target);
 175
 176    private static IDeltaCreate SelectCreator(DeltaSearchMode searchMode, IDeltaCreate exhaustive, IDeltaCreate bounded)
 830177        => searchMode switch
 830178        {
 220179            DeltaSearchMode.Exhaustive => exhaustive,
 580180            DeltaSearchMode.Bounded => bounded,
 30181            _ => throw new ArgumentOutOfRangeException(nameof(searchMode), searchMode, "Unknown search mode.")
 830182        };
 183
 184    /// <summary>Applies a binary patch and verifies the target checksum.</summary>
 185    /// <param name="source">The original source bytes against which the patch was created.</param>
 186    /// <param name="delta">The binary patch to apply.</param>
 187    /// <returns>The reconstructed target in newly allocated memory and its Fossil additive checksum.</returns>
 188    /// <remarks>Allocates the declared target length before full validation. Use the overload with a size limit to cap 
 189    /// <exception cref="DeltaApplyException">The patch is incomplete or fails structural, length, source-range, or chec
 190    /// <exception cref="DeltaReaderException">The binary reader rejects malformed command syntax.</exception>
 191    public static DeltaResult ApplyBinary(ReadOnlySpan<byte> source, ReadOnlySpan<byte> delta)
 192    {
 2370193        return Binary.Apply.Apply(source, delta);
 194    }
 195
 196    /// <inheritdoc cref="IDeltaApply.Apply(ReadOnlySpan{byte}, ReadOnlySpan{byte}, Memory{byte})"/>
 197    public static DeltaResult ApplyBinaryInto(ReadOnlySpan<byte> source, ReadOnlySpan<byte> delta, Memory<byte> output)
 2250198        => Binary.Apply.Apply(source, delta, output);
 199
 200    /// <summary>Applies a binary patch with an output-size limit checked before allocation.</summary>
 201    /// <param name="source">The original source bytes against which the patch was created.</param>
 202    /// <param name="delta">The binary patch to apply.</param>
 203    /// <param name="maxOutputLength">The maximum target length in bytes; zero permits only empty output.</param>
 204    /// <returns>The reconstructed target in newly allocated memory and its Fossil additive checksum.</returns>
 205    /// <remarks>The limit bounds the target allocation, not total memory or processing time. Bytes after the first vali
 206    /// <exception cref="ArgumentOutOfRangeException"><paramref name="maxOutputLength"/> is negative.</exception>
 207    /// <exception cref="DeltaApplyException">The declared length exceeds the limit, or the patch is incomplete or fails
 208    /// <exception cref="DeltaReaderException">The binary reader rejects malformed command syntax.</exception>
 209    public static DeltaResult ApplyBinary(ReadOnlySpan<byte> source, ReadOnlySpan<byte> delta, int maxOutputLength)
 150210        => Binary.Apply.Apply(source, delta, maxOutputLength);
 211
 212    /// <summary>Applies a Fossil patch and verifies the target checksum.</summary>
 213    /// <param name="source">The original source bytes against which the patch was created.</param>
 214    /// <param name="delta">The Fossil patch to apply.</param>
 215    /// <returns>The reconstructed target in newly allocated memory and its Fossil additive checksum.</returns>
 216    /// <remarks>Allocates the declared target length before full validation. Use the overload with a size limit to cap 
 217    /// <exception cref="DeltaApplyException">The patch is incomplete or fails structural, length, source-range, or chec
 218    /// <exception cref="DeltaReaderException">The Fossil reader rejects malformed syntax or a numeric operand exceeding
 219    public static DeltaResult ApplyFossil(ReadOnlySpan<byte> source, ReadOnlySpan<byte> delta)
 220    {
 2350221        return Fossil.Apply.Apply(source, delta);
 222    }
 223
 224    /// <inheritdoc cref="IDeltaApply.Apply(ReadOnlySpan{byte}, ReadOnlySpan{byte}, Memory{byte})"/>
 225    public static DeltaResult ApplyFossilInto(ReadOnlySpan<byte> source, ReadOnlySpan<byte> delta, Memory<byte> output)
 2250226        => Fossil.Apply.Apply(source, delta, output);
 227
 228    /// <summary>Applies a Fossil patch with an output-size limit checked before allocation.</summary>
 229    /// <param name="source">The original source bytes against which the patch was created.</param>
 230    /// <param name="delta">The Fossil patch to apply.</param>
 231    /// <param name="maxOutputLength">The maximum target length in bytes; zero permits only empty output.</param>
 232    /// <returns>The reconstructed target in newly allocated memory and its Fossil additive checksum.</returns>
 233    /// <remarks>The limit bounds the target allocation, not total memory or processing time. Bytes after the first vali
 234    /// <exception cref="ArgumentOutOfRangeException"><paramref name="maxOutputLength"/> is negative.</exception>
 235    /// <exception cref="DeltaApplyException">The declared length exceeds the limit, or the patch is incomplete or fails
 236    /// <exception cref="DeltaReaderException">The Fossil reader rejects malformed syntax or a numeric operand exceeding
 237    public static DeltaResult ApplyFossil(ReadOnlySpan<byte> source, ReadOnlySpan<byte> delta, int maxOutputLength)
 150238        => Fossil.Apply.Apply(source, delta, maxOutputLength);
 239
 240    /// <summary>Applies an ASCII patch and verifies the target checksum.</summary>
 241    /// <param name="source">The original source bytes against which the patch was created.</param>
 242    /// <param name="delta">The ASCII patch to apply, including any raw insert payloads.</param>
 243    /// <returns>The reconstructed target in newly allocated memory and its Fossil additive checksum.</returns>
 244    /// <remarks>Allocates the declared target length before full validation. Use the overload with a size limit to cap 
 245    /// <exception cref="DeltaApplyException">The patch is incomplete or fails structural, length, source-range, or chec
 246    /// <exception cref="DeltaReaderException">The ASCII reader rejects malformed command syntax.</exception>
 247    public static DeltaResult ApplyASCII(ReadOnlySpan<byte> source, ReadOnlySpan<byte> delta)
 248    {
 2250249        return ASCII.Apply.Apply(source, delta);
 250    }
 251
 252    /// <inheritdoc cref="IDeltaApply.Apply(ReadOnlySpan{byte}, ReadOnlySpan{byte}, Memory{byte})"/>
 253    public static DeltaResult ApplyASCIIInto(ReadOnlySpan<byte> source, ReadOnlySpan<byte> delta, Memory<byte> output)
 2250254        => ASCII.Apply.Apply(source, delta, output);
 255
 256    /// <summary>Applies an ASCII patch with an output-size limit checked before allocation.</summary>
 257    /// <param name="source">The original source bytes against which the patch was created.</param>
 258    /// <param name="delta">The ASCII patch to apply, including any raw insert payloads.</param>
 259    /// <param name="maxOutputLength">The maximum target length in bytes; zero permits only empty output.</param>
 260    /// <returns>The reconstructed target in newly allocated memory and its Fossil additive checksum.</returns>
 261    /// <remarks>The limit bounds the target allocation, not total memory or processing time. Bytes after the first vali
 262    /// <exception cref="ArgumentOutOfRangeException"><paramref name="maxOutputLength"/> is negative.</exception>
 263    /// <exception cref="DeltaApplyException">The declared length exceeds the limit, or the patch is incomplete or fails
 264    /// <exception cref="DeltaReaderException">The ASCII reader rejects malformed command syntax.</exception>
 265    public static DeltaResult ApplyASCII(ReadOnlySpan<byte> source, ReadOnlySpan<byte> delta, int maxOutputLength)
 150266        => ASCII.Apply.Apply(source, delta, maxOutputLength);
 267}

Methods/Properties

get_Binary()
get_Fossil()
get_ASCII()
.cctor()
CreateBinary(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>)
CreateBinary(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>,DeltaSharp.DeltaSearchMode)
CreateFossil(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>)
CreateFossil(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>,DeltaSharp.DeltaSearchMode)
CreateASCII(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>)
CreateASCII(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>,DeltaSharp.DeltaSearchMode)
SelectCreator(DeltaSharp.DeltaSearchMode,DeltaSharp.IDeltaCreate,DeltaSharp.IDeltaCreate)
ApplyBinary(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>)
ApplyBinaryInto(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>,System.Memory`1<System.Byte>)
ApplyBinary(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>,System.Int32)
ApplyFossil(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>)
ApplyFossilInto(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>,System.Memory`1<System.Byte>)
ApplyFossil(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>,System.Int32)
ApplyASCII(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>)
ApplyASCIIInto(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>,System.Memory`1<System.Byte>)
ApplyASCII(System.ReadOnlySpan`1<System.Byte>,System.ReadOnlySpan`1<System.Byte>,System.Int32)