Skip to content

Instantly share code, notes, and snippets.

@kevinhillinger
Created April 10, 2017 20:04
Show Gist options
  • Save kevinhillinger/eb4bd1f83fd3790d4866bc2b4dde0106 to your computer and use it in GitHub Desktop.
Save kevinhillinger/eb4bd1f83fd3790d4866bc2b4dde0106 to your computer and use it in GitHub Desktop.
Cache XML Files
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