Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# compare 2 binary files

static bool FileEquals(string fileName1, string fileName2)
{
    // Check the file size and CRC equality here.. if they are equal...    
    using (var file1 = new FileStream(fileName1, FileMode.Open))
        using (var file2 = new FileStream(fileName2, FileMode.Open))
            return FileStreamEquals(file1, file2);
}

static bool FileStreamEquals(Stream stream1, Stream stream2)
{
    const int bufferSize = 2048;
    byte[] buffer1 = new byte[bufferSize]; //buffer size
    byte[] buffer2 = new byte[bufferSize];
    while (true) {
        int count1 = stream1.Read(buffer1, 0, bufferSize);
        int count2 = stream2.Read(buffer2, 0, bufferSize);

        if (count1 != count2)
            return false;

        if (count1 == 0)
            return true;

        // You might replace the following with an efficient "memcmp"
        if (!buffer1.Take(count1).SequenceEqual(buffer2.Take(count2)))
            return false;
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to convert command line argument to int in C# 
Csharp :: c# aspx return image 
Csharp :: afaik 
Csharp :: vb.net ionic zip examples 
Csharp :: How to put a (new line) inside a list box 
Csharp :: c# control datagridview null value 
Csharp :: c# string size in bytes 
Csharp :: asp.net core reverse engineer database 
Csharp :: Package manager or PM cmd for dbcontext migration 
Csharp :: what is difference between int.Parse and toint32 in c# 
Csharp :: get fixedupdate interval unity 
Csharp :: how to modigy login page asp.net core 
Csharp :: An unhandled exception occurred during the execution of the current web request 
Csharp :: c# list add and return 
Csharp :: c# change chart legend font size 
Csharp :: compass direction mobile unity 
Csharp :: qcombobox delegate text filter 
Csharp :: return value of a mocked value will be as the input c# 
Csharp :: how to count specific controls in a container c# 
Csharp :: boucle C# 
Csharp :: linq cross join 
Csharp :: null objects 
Csharp :: c# url relative path remove 
Csharp :: c# array accessor 
Csharp :: unity using tmpro not working 
Csharp :: c# convert datatable to csv 
Csharp :: page refresh on button click in c# 
Csharp :: unity in app review 
Csharp :: c# second last element 
Csharp :: c# window instantly close 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =