Example #1
0
        public static bool TryWriteFileIfDifferent(Stream stream, string path)
        {
            if (File.Exists(path))
            {
                try {
                    using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)) {
                        if (fs.Length == stream.Length)
                        {
                            if (fs.CopyToByteArray().SequenceEqual(stream.CopyToByteArray()))
                            {
                                return(true);                                // file is already the same, don't need to write
                            }
                        }
                    }
                } catch (Exception) { }
            }

            return(TryWriteFile(stream, path));
        }