mirror of
https://github.com/aaru-dps/Aaru.Checksums.git
synced 2025-12-16 19:24:29 +00:00
Use Stream extension to ensure read operations return the requested number of bytes (unless EOF arrives first).
This commit is contained in:
@@ -334,12 +334,12 @@ public sealed class Adler32Context : IChecksum
|
||||
ushort localSum2 = 0;
|
||||
|
||||
var buffer = new byte[65536];
|
||||
int read = fileStream.Read(buffer, 0, 65536);
|
||||
int read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
|
||||
while(read > 0)
|
||||
{
|
||||
Step(ref localSum1, ref localSum2, buffer, (uint)read, useNative, nativeContext);
|
||||
read = fileStream.Read(buffer, 0, 65536);
|
||||
read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
}
|
||||
|
||||
var finalSum = (uint)((localSum2 << 16) | localSum1);
|
||||
|
||||
@@ -371,7 +371,7 @@ public class Crc16Context : IChecksum
|
||||
ushort[][] localTable = table ?? GenerateTable(polynomial, inverse);
|
||||
|
||||
var buffer = new byte[65536];
|
||||
int read = fileStream.Read(buffer, 0, 65536);
|
||||
int read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
|
||||
while(read > 0)
|
||||
{
|
||||
@@ -396,7 +396,7 @@ public class Crc16Context : IChecksum
|
||||
}
|
||||
}
|
||||
|
||||
read = fileStream.Read(buffer, 0, 65536);
|
||||
read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
}
|
||||
|
||||
localHashInt ^= seed;
|
||||
|
||||
@@ -554,13 +554,13 @@ public sealed class Crc32Context : IChecksum
|
||||
uint[][] localTable = GenerateTable(polynomial);
|
||||
|
||||
var buffer = new byte[65536];
|
||||
int read = fileStream.Read(buffer, 0, 65536);
|
||||
int read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
|
||||
while(read > 0)
|
||||
{
|
||||
Step(ref localHashInt, localTable, buffer, (uint)read, useIso, useNative, nativeContext);
|
||||
|
||||
read = fileStream.Read(buffer, 0, 65536);
|
||||
read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
}
|
||||
|
||||
localHashInt ^= seed;
|
||||
|
||||
@@ -498,13 +498,13 @@ public sealed class Crc64Context : IChecksum
|
||||
ulong[][] localTable = GenerateTable(polynomial);
|
||||
|
||||
var buffer = new byte[65536];
|
||||
int read = fileStream.Read(buffer, 0, 65536);
|
||||
int read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
|
||||
while(read > 0)
|
||||
{
|
||||
Step(ref localHashInt, localTable, buffer, (uint)read, useEcma, useNative, nativeContext);
|
||||
|
||||
read = fileStream.Read(buffer, 0, 65536);
|
||||
read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
}
|
||||
|
||||
localHashInt ^= seed;
|
||||
|
||||
@@ -313,13 +313,13 @@ public sealed class Fletcher32Context : IChecksum
|
||||
ushort localSum2 = 0xFFFF;
|
||||
|
||||
var buffer = new byte[65536];
|
||||
int read = fileStream.Read(buffer, 0, 65536);
|
||||
int read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
|
||||
while(read > 0)
|
||||
{
|
||||
Step(ref localSum1, ref localSum2, buffer, (uint)read, useNative, nativeContext);
|
||||
|
||||
read = fileStream.Read(buffer, 0, 65536);
|
||||
read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
}
|
||||
|
||||
var finalSum = (uint)((localSum2 << 16) | localSum1);
|
||||
@@ -641,13 +641,13 @@ public sealed class Fletcher16Context : IChecksum
|
||||
byte localSum2 = 0xFF;
|
||||
|
||||
var buffer = new byte[65536];
|
||||
int read = fileStream.Read(buffer, 0, 65536);
|
||||
int read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
|
||||
while(read > 0)
|
||||
{
|
||||
Step(ref localSum1, ref localSum2, buffer, (uint)read, useNative, nativeContext);
|
||||
|
||||
read = fileStream.Read(buffer, 0, 65536);
|
||||
read = fileStream.EnsureRead(buffer, 0, 65536);
|
||||
}
|
||||
|
||||
var finalSum = (ushort)((localSum2 << 8) | localSum1);
|
||||
|
||||
Reference in New Issue
Block a user