4internal static class ImageDataSourceExtensions
11 public static void ReadExactly(
this IImageDataSource source,
long offset, Span<byte> destination)
14 while (totalRead < destination.Length)
16 int count = source.Read(offset + totalRead, destination[totalRead..]);
19 throw new EndOfStreamException(
"The image ended before the requested region was read.");
32 public static async ValueTask ReadExactlyAsync(
33 this IImageDataSource source,
35 Memory<byte> destination,
36 CancellationToken cancellationToken)
39 while (totalRead < destination.Length)
41 int count = await source.ReadAsync(
43 destination[totalRead..],
44 cancellationToken).ConfigureAwait(
false);
47 throw new EndOfStreamException(
"The image ended before the requested region was read.");