public static void WriteAllBytes(string path, byte[] bytes) { string text = null; var currentText = ReadAllText(path); if (currentText != null) { text = Encoding.UTF8.GetString(bytes); if (currentText == text) { return; } } File.WriteAllBytes(path, bytes); var time = File.GetLastWriteTimeUtc(path); FileCaches[path] = new FileCache(time, bytes, text); }
public static FileCache GetFileCache(string path) { if (!File.Exists(path)) { return(null); } var time = File.GetLastWriteTimeUtc(path); if (FileCaches.TryGetValue(path, out var fileCache)) { if (time == fileCache.LastWriteTime) { return(fileCache); } } var bytes = File.ReadAllBytes(path); fileCache = new FileCache(time, bytes); FileCaches[path] = fileCache; return(fileCache); }