mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 14:17:26 +08:00
Avoid MemoryStream
overhead for incoming non-MemoryStream
in ImportTask
This commit is contained in:
parent
f90f2491c3
commit
b5902a8736
@ -46,9 +46,19 @@ namespace osu.Game.Database
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ArchiveReader GetReader()
|
public ArchiveReader GetReader()
|
||||||
{
|
{
|
||||||
return Stream != null
|
if (Stream == null)
|
||||||
? getReaderFrom(Stream)
|
return getReaderFromPath(Path);
|
||||||
: getReaderFrom(Path);
|
|
||||||
|
if (Stream is MemoryStream memoryStream)
|
||||||
|
{
|
||||||
|
if (ZipUtils.IsZipArchive(memoryStream))
|
||||||
|
return new ZipArchiveReader(memoryStream, Path);
|
||||||
|
|
||||||
|
return new LegacyByteArrayReader(memoryStream.ToArray(), 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).
|
||||||
|
return new LegacyByteArrayReader(Stream.ReadAllBytesToArray(), Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -60,32 +70,12 @@ namespace osu.Game.Database
|
|||||||
File.Delete(Path);
|
File.Delete(Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Creates an <see cref="ArchiveReader"/> from a stream.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="stream">A seekable stream containing the archive content.</param>
|
|
||||||
/// <returns>A reader giving access to the archive's content.</returns>
|
|
||||||
private ArchiveReader getReaderFrom(Stream stream)
|
|
||||||
{
|
|
||||||
if (!(stream is MemoryStream memoryStream))
|
|
||||||
{
|
|
||||||
// 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).
|
|
||||||
memoryStream = new MemoryStream(stream.ReadAllBytesToArray());
|
|
||||||
stream.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ZipUtils.IsZipArchive(memoryStream))
|
|
||||||
return new ZipArchiveReader(memoryStream, Path);
|
|
||||||
|
|
||||||
return new LegacyByteArrayReader(memoryStream.ToArray(), Path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates an <see cref="ArchiveReader"/> from a valid storage path.
|
/// Creates an <see cref="ArchiveReader"/> from a valid storage path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">A file or folder path resolving the archive content.</param>
|
/// <param name="path">A file or folder path resolving the archive content.</param>
|
||||||
/// <returns>A reader giving access to the archive's content.</returns>
|
/// <returns>A reader giving access to the archive's content.</returns>
|
||||||
private ArchiveReader getReaderFrom(string path)
|
private ArchiveReader getReaderFromPath(string path)
|
||||||
{
|
{
|
||||||
if (ZipUtils.IsZipArchive(path))
|
if (ZipUtils.IsZipArchive(path))
|
||||||
return new ZipArchiveReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read), System.IO.Path.GetFileName(path));
|
return new ZipArchiveReader(File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read), System.IO.Path.GetFileName(path));
|
||||||
|
Loading…
Reference in New Issue
Block a user