Don't keep mix files in memory.

Added SegmentStream class to assist in maintaining views into portions of the FileStream of the overall mix file to avoid having to copy sections into in-memory buffers.
This commit is contained in:
RoosterDragon
2015-09-18 00:35:15 +01:00
parent 410f121a1e
commit 210c7e312b
3 changed files with 108 additions and 3 deletions

View File

@@ -14,6 +14,7 @@ using System.Globalization;
using System.IO;
using System.Linq;
using OpenRA.FileFormats;
using OpenRA.Primitives;
namespace OpenRA.FileSystem
{
@@ -179,9 +180,10 @@ namespace OpenRA.FileSystem
if (!index.TryGetValue(hash, out e))
return null;
s.Seek(dataStart + e.Offset, SeekOrigin.Begin);
var data = s.ReadBytes((int)e.Length);
return new MemoryStream(data);
Stream parentStream;
var offset = dataStart + e.Offset + SegmentStream.GetOverallNestedOffset(s, out parentStream);
var path = ((FileStream)parentStream).Name;
return new SegmentStream(File.OpenRead(path), offset, e.Length);
}
public Stream GetContent(string filename)