mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Make IStorage array read/write extension methods
This commit is contained in:
parent
42044d02ba
commit
6e2fa012c2
1 changed files with 20 additions and 1 deletions
|
@ -6,6 +6,25 @@ namespace LibHac.IO
|
|||
{
|
||||
public static class StorageExtensions
|
||||
{
|
||||
public static void Read(this IStorage storage, byte[] buffer, long offset, int count, int bufferOffset)
|
||||
{
|
||||
ValidateStorageParameters(buffer, offset, count, bufferOffset);
|
||||
storage.Read(buffer.AsSpan(bufferOffset, count), offset);
|
||||
}
|
||||
public static void Write(this IStorage storage, byte[] buffer, long offset, int count, int bufferOffset)
|
||||
{
|
||||
ValidateStorageParameters(buffer, offset, count, bufferOffset);
|
||||
storage.Write(buffer.AsSpan(bufferOffset, count), offset);
|
||||
}
|
||||
|
||||
private static void ValidateStorageParameters(byte[] buffer, long offset, int count, int bufferOffset)
|
||||
{
|
||||
if (buffer == null) throw new ArgumentNullException(nameof(buffer));
|
||||
if (offset < 0) throw new ArgumentOutOfRangeException(nameof(offset), "Argument must be non-negative.");
|
||||
if (count < 0) throw new ArgumentOutOfRangeException(nameof(count), "Argument must be non-negative.");
|
||||
if (bufferOffset < 0) throw new ArgumentOutOfRangeException(nameof(bufferOffset), "Argument must be non-negative.");
|
||||
}
|
||||
|
||||
public static IStorage Slice(this IStorage storage, long start)
|
||||
{
|
||||
if (storage.Length == -1)
|
||||
|
|
Loading…
Reference in a new issue