mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
Refactor IMediaImage.ReadSector(s) to return error status instead of buffer.
This commit is contained in:
@@ -832,7 +832,8 @@ namespace Aaru.DiscImages
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSector(ulong sectorAddress) => ReadSectors(sectorAddress, 1);
|
||||
public ErrorNumber ReadSector(ulong sectorAddress, out byte[] buffer) =>
|
||||
ReadSectors(sectorAddress, 1, out buffer);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectorTag(ulong sectorAddress, SectorTagType tag) => ReadSectorsTag(sectorAddress, 1, tag);
|
||||
@@ -845,15 +846,21 @@ namespace Aaru.DiscImages
|
||||
ReadSectorsTag(sectorAddress, 1, track, tag);
|
||||
|
||||
/// <inheritdoc />
|
||||
public byte[] ReadSectors(ulong sectorAddress, uint length)
|
||||
public ErrorNumber ReadSectors(ulong sectorAddress, uint length, out byte[] buffer)
|
||||
{
|
||||
buffer = null;
|
||||
|
||||
foreach(KeyValuePair<uint, ulong> kvp in from kvp in _offsetMap where sectorAddress >= kvp.Value
|
||||
from track in Tracks where track.Sequence == kvp.Key
|
||||
where sectorAddress - kvp.Value <
|
||||
track.EndSector - track.StartSector + 1 select kvp)
|
||||
return ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
{
|
||||
buffer = ReadSectors(sectorAddress - kvp.Value, length, kvp.Key);
|
||||
|
||||
throw new ArgumentOutOfRangeException(nameof(sectorAddress), "Sector address not found");
|
||||
return ErrorNumber.NoError;
|
||||
}
|
||||
|
||||
return ErrorNumber.SectorNotFound;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
Reference in New Issue
Block a user