Use Stream extension to ensure read operations return the requested number of bytes (unless EOF arrives first).

This commit is contained in:
2022-11-14 09:43:16 +00:00
parent f90cc6593f
commit 0eb589d785
178 changed files with 862 additions and 780 deletions

View File

@@ -47,6 +47,7 @@ using Aaru.Console;
using Aaru.Decoders.PCMCIA;
using Aaru.DiscImages;
using Aaru.Filters;
using Aaru.Helpers;
using Schemas;
using MediaType = Aaru.CommonTypes.Metadata.MediaType;
using Tuple = Aaru.Decoders.PCMCIA.Tuple;
@@ -1041,7 +1042,7 @@ public sealed partial class Sidecar
scpImage.Header.offsets[t] + 1];
scpStream.Position = scpImage.Header.offsets[t];
scpStream.Read(trackContents, 0, trackContents.Length);
scpStream.EnsureRead(trackContents, 0, trackContents.Length);
scpBlockTrackType.Size = (ulong)trackContents.Length;
scpBlockTrackType.Checksums = Checksum.GetChecksums(trackContents).ToArray();
}
@@ -1146,7 +1147,7 @@ public sealed partial class Sidecar
Stream kfStream = kvp.Value.GetDataForkStream();
var trackContents = new byte[kfStream.Length];
kfStream.Position = 0;
kfStream.Read(trackContents, 0, trackContents.Length);
kfStream.EnsureRead(trackContents, 0, trackContents.Length);
kfBlockTrackType.Size = (ulong)trackContents.Length;
kfBlockTrackType.Checksums = Checksum.GetChecksums(trackContents).ToArray();
@@ -1232,7 +1233,7 @@ public sealed partial class Sidecar
dfiBlockTrackType.Image.offset = (ulong)offset;
var trackContents = new byte[length];
dfiStream.Position = offset;
dfiStream.Read(trackContents, 0, trackContents.Length);
dfiStream.EnsureRead(trackContents, 0, trackContents.Length);
dfiBlockTrackType.Size = (ulong)trackContents.Length;
dfiBlockTrackType.Checksums = Checksum.GetChecksums(trackContents).ToArray();
}

View File

@@ -34,6 +34,7 @@ namespace Aaru.Core;
using System.Collections.Generic;
using System.IO;
using Aaru.Helpers;
using Schemas;
/// <summary>Sidecar operations</summary>
@@ -133,7 +134,7 @@ public sealed partial class Sidecar
if(sectors - doneSectors >= sectorsToRead)
{
sector = new byte[sectorsToRead * blockSize];
_fs.Read(sector, 0, sector.Length);
_fs.EnsureRead(sector, 0, sector.Length);
UpdateProgress2($"Hashing block {doneSectors} of {sectors} on file {i + 1} of {files.Count}",
(long)doneSectors, (long)sectors);
@@ -143,7 +144,7 @@ public sealed partial class Sidecar
else
{
sector = new byte[(uint)(sectors - doneSectors) * blockSize];
_fs.Read(sector, 0, sector.Length);
_fs.EnsureRead(sector, 0, sector.Length);
UpdateProgress2($"Hashing block {doneSectors} of {sectors} on file {i + 1} of {files.Count}",
(long)doneSectors, (long)sectors);

View File

@@ -40,6 +40,7 @@ using Aaru.CommonTypes;
using Aaru.CommonTypes.Enums;
using Aaru.CommonTypes.Interfaces;
using Aaru.Console;
using Aaru.Helpers;
using Schemas;
public sealed partial class Sidecar
@@ -104,7 +105,7 @@ public sealed partial class Sidecar
return _sidecar;
data = new byte[1048576];
_fs.Read(data, 0, 1048576);
_fs.EnsureRead(data, 0, 1048576);
UpdateProgress("Hashing image file byte {0} of {1}", position, _fi.Length);
@@ -114,7 +115,7 @@ public sealed partial class Sidecar
}
data = new byte[_fi.Length - position];
_fs.Read(data, 0, (int)(_fi.Length - position));
_fs.EnsureRead(data, 0, (int)(_fi.Length - position));
UpdateProgress("Hashing image file byte {0} of {1}", position, _fi.Length);