Skip to content

Commit

Permalink
Rename BinaryPatchUtility to BinaryPatch.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrainger committed Feb 11, 2023
1 parent ef0b1cd commit 1b799bc
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
public class BinaryPatchUtility
public class BinaryPatch
{
/// <summary>
/// Creates a binary patch (in <a href="http://www.daemonology.net/bsdiff/">bsdiff</a> format) that can be used
Expand Down
8 changes: 4 additions & 4 deletions src/BsDiffTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static void Main(string[] args)
try
{
using (var output = new FileStream(patchFile, FileMode.Create))
BinaryPatchUtility.Create(File.ReadAllBytes(oldFile), File.ReadAllBytes(newFile), output);
BinaryPatch.Create(File.ReadAllBytes(oldFile), File.ReadAllBytes(newFile), output);
}
catch (FileNotFoundException ex)
{
Expand Down Expand Up @@ -58,7 +58,7 @@ private static void CheckImplementation(string oldFile, string newFile)
// run C# implementation
var portTime = Stopwatch.StartNew();
using (var output = new FileStream(portPatchFileName, FileMode.Create))
BinaryPatchUtility.Create(File.ReadAllBytes(oldFile), File.ReadAllBytes(newFile), output);
BinaryPatch.Create(File.ReadAllBytes(oldFile), File.ReadAllBytes(newFile), output);
portTime.Stop();

Console.WriteLine("Patches created in {0} (reference) and {1} (C# port).", referenceTime.Elapsed, portTime.Elapsed);
Expand All @@ -81,13 +81,13 @@ private static void CheckImplementation(string oldFile, string newFile)
Console.Write("Applying reference patch with port binary...");
using (var input = new FileStream(oldFile, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var output = new FileStream(outputFilePaths[2], FileMode.Create))
BinaryPatchUtility.Apply(input, () => new FileStream(referencePatchFileName, FileMode.Open, FileAccess.Read, FileShare.Read), output);
BinaryPatch.Apply(input, () => new FileStream(referencePatchFileName, FileMode.Open, FileAccess.Read, FileShare.Read), output);
Console.WriteLine("done.");

Console.Write("Applying port patch with port binary...");
using (var input = new FileStream(oldFile, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var output = new FileStream(outputFilePaths[3], FileMode.Create))
BinaryPatchUtility.Apply(input, () => new FileStream(portPatchFileName, FileMode.Open, FileAccess.Read, FileShare.Read), output);
BinaryPatch.Apply(input, () => new FileStream(portPatchFileName, FileMode.Open, FileAccess.Read, FileShare.Read), output);
Console.WriteLine("done.");

var errors = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/BsPatchTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void Main(string[] args)
{
using (var input = new FileStream(oldFile, FileMode.Open, FileAccess.Read, FileShare.Read))
using (var output = new FileStream(newFile, FileMode.Create))
BinaryPatchUtility.Apply(input, () => new FileStream(patchFile, FileMode.Open, FileAccess.Read, FileShare.Read), output);
BinaryPatch.Apply(input, () => new FileStream(patchFile, FileMode.Open, FileAccess.Read, FileShare.Read), output);
}
catch (FileNotFoundException ex)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/BsDiff.Tests/BinaryPatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void ApplyFirstSentencePatch()
private static void AssertCreatePatch(byte[] oldData, byte[] newData, int expectedLengthLow, int expectedLengthHigh)
{
using var outputStream = new MemoryStream();
BinaryPatchUtility.Create(oldData, newData, outputStream);
BinaryPatch.Create(oldData, newData, outputStream);
var patch = outputStream.ToArray();
Assert.InRange(patch.Length, expectedLengthLow, expectedLengthHigh);
AssertHeader(patch.AsSpan(0, 32), newData.Length);
Expand All @@ -139,7 +139,7 @@ private static void AssertApplyPatch(byte[] oldData, byte[] newData, byte[] patc
{
using var inputStream = new MemoryStream(oldData);
using var outputStream = new MemoryStream();
BinaryPatchUtility.Apply(inputStream, () => new MemoryStream(patch), outputStream);
BinaryPatch.Apply(inputStream, () => new MemoryStream(patch), outputStream);
Assert.Equal(newData, outputStream.ToArray());
}
}

0 comments on commit 1b799bc

Please sign in to comment.