Created
April 10, 2017 20:04
-
-
Save kevinhillinger/eb4bd1f83fd3790d4866bc2b4dde0106 to your computer and use it in GitHub Desktop.
Cache XML Files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FileCacher | |
{ | |
public Dictionary<string, byte[]> GetXmlFilesAsCache(IEnumerable<string> xmlFiles) | |
{ | |
var cache = new Dictionary<string, byte[]>(); | |
foreach (var file in xmlFiles) | |
{ | |
cache.Add(file, GetBytes(file)); | |
} | |
return cache; | |
} | |
private static byte[] GetBytes(string filePath) | |
{ | |
byte[] buffer = null; | |
using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) | |
{ | |
buffer = new byte[file.Length]; | |
file.Read(buffer, 0, (int)file.Length); | |
} | |
return buffer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment