public void UintReader_ValuesMatch_InterleavedReads() { using var fs = new FileStream(testFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); using var reader = new BinaryReader(fs); using var rofs = new ReadOnlyFileStream(testFilePath); using var roreader = new BinaryReader(rofs); var b = new byte[500]; var b2 = new byte[500]; for (var i = 0; i < values; i++) { if (i % 20 == 0) { if (i * 4 == 1279520) { Debugger.Break(); } var fread = fs.Read(b, 0, b.Length); var roread = rofs.Read(b2, 0, b2.Length); Assert.IsTrue(b.SequenceEqual(b2), $"Read at {i*4} did not equal"); fs.Position -= fread; rofs.Position -= roread; } Assert.AreEqual(reader.ReadUInt32(), roreader.ReadUInt32()); } }
public void UintOverload_ValuesMatch() { using var fs = new FileStream(testFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); using var reader = new BinaryReader(fs); using var rofs = new ReadOnlyFileStream(testFilePath); for (var i = 0; i < values; i++) { Assert.AreEqual(reader.ReadUInt32(), rofs.ReadUInt32At(i * sizeof(uint))); } }
private MapStream GetAggregateStream(Stream mapStream, MapStreamTransform streamTransform) { var stream = new MapStream(streamTransform(mapStream)); foreach (var(key, map) in this.config.AncillaryMaps) { var fs = new ReadOnlyFileStream(Path.Combine(this.config.MapRoot, map)); stream.UseAncillaryMap(key, streamTransform(fs)); } return(stream); }
public void UintReader_ValuesMatchReverse() { using var fs = new FileStream(testFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); using var reader = new BinaryReader(fs); using var rofs = new ReadOnlyFileStream(testFilePath); using var roreader = new BinaryReader(rofs); for (var i = 0; i < values; i++) { fs.Position = fs.Length - (i * sizeof(uint)) - sizeof(uint); rofs.Position = fs.Length - (i * sizeof(uint)) - sizeof(uint); Assert.AreEqual(reader.ReadUInt32(), roreader.ReadUInt32()); } }
public void UintReader_ValuesMatchRandom() { using var fs = new FileStream(testFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); using var reader = new BinaryReader(fs); using var rofs = new ReadOnlyFileStream(testFilePath); using var roreader = new BinaryReader(rofs); var rand = new Random(42); for (var i = 0; i < values; i++) { var pos = rand.Next(0, values) * sizeof(uint); fs.Position = pos; rofs.Position = pos; Assert.AreEqual(reader.ReadUInt32(), roreader.ReadUInt32(), $"Failed on {i}"); } }
/// <summary> /// Loads the specified file as a map. /// </summary> /// <param name="mapName">The filename to load map data from. Will be combined with the current config's MapRoot</param> /// <param name="streamTransform">A delegate to tranform the map streams into a format that can be read. Typical use case is if the maps on disk are compressed.</param> /// <param name="loadCallback">An optional callback that will be invoked after each map is created</param> public TMap Load <TMap>(string mapName, MapStreamTransform streamTransform, MapLoadCallback loadCallback = null) where TMap : IMap, new() { var fs = new ReadOnlyFileStream(Path.Combine(this.config.MapRoot, mapName)); return(this.Load <TMap>(fs, streamTransform, loadCallback)); }