Show / Hide Table of Contents

Class FileComparer

Compare files and byte arrays for strict, byte-for-byte equality. This class supports both small-file comparison using System.IO.File.ReadAllBytes(System.String) and scalable streaming comparison for large files.

Inheritance
System.Object
FileComparer
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: WizardWrx.Core
Assembly: WizardWrx.Core.dll
Syntax
public static class FileComparer

Fields

| Improve this Doc View Source

DEFAULT_READ_ALL_BYTES_CEILING

Default ceiling (in bytes) below which file comparison uses System.IO.File.ReadAllBytes(System.String) instead of streaming.

Declaration
public const long DEFAULT_READ_ALL_BYTES_CEILING = 1048576L
Field Value
Type Description
System.Int64
| Improve this Doc View Source

DEFAULT_STREAMING_BUFFER_SIZE

Default streaming buffer size (in bytes). This value is a power of two, consistent with typical buffered I/O practice.

Declaration
public const int DEFAULT_STREAMING_BUFFER_SIZE = 81920
Field Value
Type Description
System.Int32

Properties

| Improve this Doc View Source

ReadAllBytesCeiling

This read/write property gets or sets the maximum file size (in bytes) for which System.IO.File.ReadAllBytes(System.String) is used instead of streaming comparison.

Declaration
public static long ReadAllBytesCeiling { get; set; }
Property Value
Type Description
System.Int64
Exceptions
Type Condition
System.ArgumentOutOfRangeException

An ArgumentOutOfRangeException Exception arises when the assigned value is less than or equal to zero.

| Improve this Doc View Source

StreamingBufferSize

This read/write property gets or sets the buffer size (in bytes) used for streaming file comparison.

Declaration
public static int StreamingBufferSize { get; set; }
Property Value
Type Description
System.Int32
Exceptions
Type Condition
System.ArgumentOutOfRangeException

An ArgumentOutOfRangeException Exception arises when the assigned value is less than or equal to zero.

Methods

| Improve this Doc View Source

CompareByteArrays(Byte[], Byte[])

Compare two byte arrays for strict equality.

Declaration
public static bool CompareByteArrays(byte[] pabytByteArray1, byte[] pabytByteArray2)
Parameters
Type Name Description
System.Byte[] pabytByteArray1

First byte array.

System.Byte[] pabytByteArray2

Second byte array.

Returns
Type Description
System.Boolean

true if the arrays are identical; otherwise, false.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if either array is null.

System.ArgumentException

Thrown if either array is empty.

| Improve this Doc View Source

CompareFiles(String, String)

Compare two files for strict, byte-for-byte equality. This method throws exceptions for invalid input or I/O errors.

Declaration
public static bool CompareFiles(string pstrAbsoluteOrRelativeFileName1, string pstrAbsoluteOrRelativeFileName2)
Parameters
Type Name Description
System.String pstrAbsoluteOrRelativeFileName1

This required string represents the path to the first file, which may be either a relative or absolute path.

System.String pstrAbsoluteOrRelativeFileName2

This required string represents the path to the second file, which may be either a relative or absolute path.

Returns
Type Description
System.Boolean

true if the files are identical byte-for-byte; otherwise, false.

Exceptions
Type Condition
System.ArgumentNullException

Thrown if either file path is null or empty.

System.IO.FileNotFoundException

Thrown if either file does not exist.

| Improve this Doc View Source

CompareFilesStreaming(String, String)

Streaming comparison of two files using a configurable buffer. Intended for large files where System.IO.File.ReadAllBytes(System.String) would be inefficient.

Declaration
public static bool CompareFilesStreaming(string pstrAbsoluteOrRelativeFileName1, string pstrAbsoluteOrRelativeFileName2)
Parameters
Type Name Description
System.String pstrAbsoluteOrRelativeFileName1

This required string represents the path to the first file, which may be either a relative or absolute path.

System.String pstrAbsoluteOrRelativeFileName2

This required string represents the path to the second file, which may be either a relative or absolute path.

Returns
Type Description
System.Boolean

true if the files are identical; otherwise, false.

| Improve this Doc View Source

TryCompareFiles(String, String, out Exception)

Safe version of CompareFiles(String, String). This method never throws; instead, it returns false and outputs the exception that would have been thrown.

Declaration
public static bool TryCompareFiles(string pstrAbsoluteOrRelativeFileName1, string pstrAbsoluteOrRelativeFileName2, out Exception opex)
Parameters
Type Name Description
System.String pstrAbsoluteOrRelativeFileName1

This required string represents the path to the first file, which may be either a relative or absolute path.

System.String pstrAbsoluteOrRelativeFileName2

This required string represents the path to the second file, which may be either a relative or absolute path.

System.Exception opex

Receives the exception if an error occurs; otherwise, null.

Returns
Type Description
System.Boolean

true if the files are identical; otherwise, false.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX