mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 05:32:54 +08:00
Update stream read operations to use new helper methods
This commit is contained in:
parent
176bb4a4e2
commit
908c31c687
@ -4,6 +4,7 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
using osu.Game.IO.Archives;
|
using osu.Game.IO.Archives;
|
||||||
using osu.Game.Stores;
|
using osu.Game.Stores;
|
||||||
using osu.Game.Utils;
|
using osu.Game.Utils;
|
||||||
@ -63,9 +64,7 @@ namespace osu.Game.Database
|
|||||||
if (!(stream is MemoryStream memoryStream))
|
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).
|
// 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).
|
||||||
byte[] buffer = new byte[stream.Length];
|
memoryStream = new MemoryStream(stream.ReadAllBytesToArray());
|
||||||
stream.Read(buffer, 0, (int)stream.Length);
|
|
||||||
memoryStream = new MemoryStream(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZipUtils.IsZipArchive(memoryStream))
|
if (ZipUtils.IsZipArchive(memoryStream))
|
||||||
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.IO.Stores;
|
using osu.Framework.IO.Stores;
|
||||||
|
|
||||||
namespace osu.Game.IO.Archives
|
namespace osu.Game.IO.Archives
|
||||||
@ -35,14 +36,7 @@ namespace osu.Game.IO.Archives
|
|||||||
public virtual byte[] Get(string name)
|
public virtual byte[] Get(string name)
|
||||||
{
|
{
|
||||||
using (Stream input = GetStream(name))
|
using (Stream input = GetStream(name))
|
||||||
{
|
return input?.ReadAllBytesToArray();
|
||||||
if (input == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
byte[] buffer = new byte[input.Length];
|
|
||||||
input.Read(buffer);
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
|
public async Task<byte[]> GetAsync(string name, CancellationToken cancellationToken = default)
|
||||||
@ -52,9 +46,7 @@ namespace osu.Game.IO.Archives
|
|||||||
if (input == null)
|
if (input == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
byte[] buffer = new byte[input.Length];
|
return await input.ReadAllBytesToArrayAsync(cancellationToken).ConfigureAwait(false);
|
||||||
await input.ReadAsync(buffer, cancellationToken).ConfigureAwait(false);
|
|
||||||
return buffer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user