public static IndexData ReadFromFile(string filePath) { if (!File.Exists(filePath)) { throw new FileNotFoundException($"Index file under {filePath} not found."); } var size = new FileInfo(filePath).Length; int treeType; NodeMetaData[] data; using (var mmf = MemoryMappedFile.CreateFromFile(filePath, FileMode.Open)) { using (var accessor = mmf.CreateViewAccessor(0, size)) { accessor.Read(0, out treeType); accessor.Read(sizeof(int), out int itemCount); data = new NodeMetaData[itemCount]; long pos = sizeof(int) * 2; for (var i = 0; i < itemCount; ++i) { data[i] = NodeMetaData.Read(accessor, ref pos); } } } return(new IndexData((TreeType)treeType, data)); }
public static IndexData ReadFromFile(string filePath, long offset, long size) { if (!File.Exists(filePath)) { throw new FileNotFoundException($"Index file under {filePath} not found."); } int treeType; NodeMetaData[] data; using (var mmf = MemoryMappedFile.CreateFromFile(File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read), null, 0L, MemoryMappedFileAccess.Read, HandleInheritability.None, false)) { using (var accessor = mmf.CreateViewAccessor(offset, size, MemoryMappedFileAccess.Read)) { accessor.Read(0, out treeType); accessor.Read(sizeof(int), out int itemCount); data = new NodeMetaData[itemCount]; long pos = sizeof(int) * 2; for (var i = 0; i < itemCount; ++i) { data[i] = NodeMetaData.Read(accessor, ref pos); } } } return(new IndexData((TreeType)treeType, data)); }