mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 09:42:55 +08:00
Avoid MemoryStream.ToArray
overhead in LegacyByteArrayReader
This commit is contained in:
parent
b5902a8736
commit
0657b55196
@ -54,7 +54,7 @@ namespace osu.Game.Database
|
|||||||
if (ZipUtils.IsZipArchive(memoryStream))
|
if (ZipUtils.IsZipArchive(memoryStream))
|
||||||
return new ZipArchiveReader(memoryStream, Path);
|
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).
|
// 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).
|
||||||
|
30
osu.Game/IO/Archives/MemoryStreamArchiveReader.cs
Normal file
30
osu.Game/IO/Archives/MemoryStreamArchiveReader.cs
Normal 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 };
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user