From f2c262dc225a05493faf56c44e72cf396430cd5b Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 5 Dec 2020 20:58:34 +0100 Subject: [PATCH] Remove TiffUtils, use Stream extensions instead --- .../Compression/DeflateTiffCompression.cs | 2 +- .../Tiff/Compression/NoneTiffCompression.cs | 2 +- .../Compression/PackBitsTiffCompression.cs | 2 +- .../Formats/Tiff/Compression/T4BitReader.cs | 2 +- .../Formats/Tiff/Utils/TiffUtils.cs | 54 ------------------- 5 files changed, 4 insertions(+), 58 deletions(-) delete mode 100644 src/ImageSharp/Formats/Tiff/Utils/TiffUtils.cs diff --git a/src/ImageSharp/Formats/Tiff/Compression/DeflateTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/DeflateTiffCompression.cs index 4cc7008eb..4ea98d95a 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/DeflateTiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/DeflateTiffCompression.cs @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Compression var subStream = new SubStream(stream, byteCount - headerLength); using (var deflateStream = new DeflateStream(subStream, CompressionMode.Decompress, true)) { - deflateStream.ReadFull(buffer); + deflateStream.Read(buffer, 0, buffer.Length); } if (this.Predictor == TiffPredictor.Horizontal) diff --git a/src/ImageSharp/Formats/Tiff/Compression/NoneTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/NoneTiffCompression.cs index 5ca112f3b..a07b42112 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/NoneTiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/NoneTiffCompression.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Compression /// public override void Decompress(Stream stream, int byteCount, Span buffer) { - stream.ReadFull(buffer, byteCount); + stream.Read(buffer, 0, byteCount); } } } diff --git a/src/ImageSharp/Formats/Tiff/Compression/PackBitsTiffCompression.cs b/src/ImageSharp/Formats/Tiff/Compression/PackBitsTiffCompression.cs index 2fbb7e6f1..d77ee78e4 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/PackBitsTiffCompression.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/PackBitsTiffCompression.cs @@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Compression Span compressedData = compressedDataMemory.GetSpan(); - stream.ReadFull(compressedData, byteCount); + stream.Read(compressedData, 0, byteCount); int compressedOffset = 0; int decompressedOffset = 0; diff --git a/src/ImageSharp/Formats/Tiff/Compression/T4BitReader.cs b/src/ImageSharp/Formats/Tiff/Compression/T4BitReader.cs index f2609e05c..d5435f546 100644 --- a/src/ImageSharp/Formats/Tiff/Compression/T4BitReader.cs +++ b/src/ImageSharp/Formats/Tiff/Compression/T4BitReader.cs @@ -821,7 +821,7 @@ namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Compression private void ReadImageDataFromStream(Stream input, int bytesToRead) { Span dataSpan = this.Data.GetSpan(); - input.ReadFull(dataSpan, bytesToRead); + input.Read(dataSpan, 0, bytesToRead); } } } diff --git a/src/ImageSharp/Formats/Tiff/Utils/TiffUtils.cs b/src/ImageSharp/Formats/Tiff/Utils/TiffUtils.cs deleted file mode 100644 index e81a7f4c4..000000000 --- a/src/ImageSharp/Formats/Tiff/Utils/TiffUtils.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Six Labors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.IO; - -namespace SixLabors.ImageSharp.Formats.Experimental.Tiff.Utils -{ - /// - /// TIFF specific utilities and extension methods. - /// - internal static class TiffUtils - { - /// - /// Reads a sequence of bytes from the input stream into a buffer. - /// - /// The stream to read from. - /// A buffer to store the retrieved data. - /// The number of bytes to read. - public static void ReadFull(this Stream stream, Span buffer, int count) - { - int offset = 0; - - while (count > 0) - { - int bytesLeftInBuffer = buffer.Length - offset; - if (bytesLeftInBuffer < count) - { - TiffThrowHelper.ThrowImageFormatException("Error reading data from the stream. The provided buffer was too small."); - } - - int bytesRead = stream.Read(buffer, offset, count); - - if (bytesRead == 0) - { - break; - } - - offset += bytesRead; - count -= bytesRead; - } - } - - /// - /// Reads all bytes from the input stream into a buffer until the end of stream or the buffer is full. - /// - /// The stream to read from. - /// A buffer to store the retrieved data. - public static void ReadFull(this Stream stream, Span buffer) - { - ReadFull(stream, buffer, buffer.Length); - } - } -}