Skip to content

Instantly share code, notes, and snippets.

@steveevers
Created May 22, 2018 17:43
Show Gist options
  • Save steveevers/beaf6fe57791c2f25d1f727bac79a501 to your computer and use it in GitHub Desktop.
Save steveevers/beaf6fe57791c2f25d1f727bac79a501 to your computer and use it in GitHub Desktop.
using System.IO;
using System.IO.MemoryMappedFiles;
public static class FileUtils
{
public static string MapAndRead(string processIdPath) {
using (var f = new FileStream(processIdPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (var m = MemoryMappedFile.CreateFromFile(f, null, 0, MemoryMappedFileAccess.Read, null, HandleInheritability.None, true))
using (var s = m.CreateViewStream(0, 0, MemoryMappedFileAccess.Read))
using (var r = new StreamReader(s)) {
return r.ReadToEnd();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment