1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:07:52 +08:00

Avoid MemoryStream.ToArray overhead in LegacyByteArrayReader

This commit is contained in:
Dean Herbert 2023-09-14 13:33:25 +09:00
parent b5902a8736
commit 0657b55196
2 changed files with 31 additions and 1 deletions

View File

@ -54,7 +54,7 @@ namespace osu.Game.Database
if (ZipUtils.IsZipArchive(memoryStream))
return new ZipArchiveReader(memoryStream, Path);
return new LegacyByteArrayReader(memoryStream.ToArray(), Path);
return new MemoryStreamArchiveReader(memoryStream, Path);
}
// This isn't used in any current path. May need to reconsider for performance reasons (ie. if we don't expect the incoming stream to be copied out).

View File

@ -0,0 +1,30 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.IO;
namespace osu.Game.IO.Archives
{
/// <summary>
/// Allows reading a single file from the provided memory stream.
/// </summary>
public class MemoryStreamArchiveReader : ArchiveReader
{
private readonly MemoryStream stream;
public MemoryStreamArchiveReader(MemoryStream stream, string filename)
: base(filename)
{
this.stream = stream;
}
public override Stream GetStream(string name) => new MemoryStream(stream.GetBuffer(), 0, (int)stream.Length);
public override void Dispose()
{
}
public override IEnumerable<string> Filenames => new[] { Name };
}
}