private static bool CompareTimeZoneFile(string filePath, byte[] buffer, byte[] rawData) { try { // bufferSize == 1 used to avoid unnecessary buffer in FileStream using (SafeFileHandle sfh = File.OpenHandle(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { long fileLength = RandomAccess.GetLength(sfh); if (fileLength == rawData.Length) { int index = 0; int count = rawData.Length; while (count > 0) { int n = RandomAccess.Read(sfh, buffer.AsSpan(index, count), index); if (n == 0) { ThrowHelper.ThrowEndOfFileException(); } int end = index + n; for (; index < end; index++) { if (buffer[index] != rawData[index]) { return(false); } } count -= n; } return(true); } } } catch (IOException) { } catch (SecurityException) { } catch (UnauthorizedAccessException) { } return(false); }