diff --git a/src/ImageSharp/Common/Extensions/StreamExtensions.cs b/src/ImageSharp/Common/Extensions/StreamExtensions.cs new file mode 100644 index 000000000..912a03823 --- /dev/null +++ b/src/ImageSharp/Common/Extensions/StreamExtensions.cs @@ -0,0 +1,25 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System.IO; + + internal static class StreamExtensions + { + public static void Skip(this Stream stream, int count) + { + if (stream.CanSeek) + { + stream.Position += count; + } + else + { + byte[] foo = new byte[count]; + stream.Read(foo, 0, count); + } + } + } +} diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 29b34aa9a..44bb5553b 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs @@ -59,7 +59,7 @@ namespace ImageSharp.Formats this.currentStream = stream; // Skip the identifier - this.currentStream.Seek(6, SeekOrigin.Current); + this.currentStream.Skip(6); this.ReadLogicalScreenDescriptor(); if (this.logicalScreenDescriptor.GlobalColorTableFlag) @@ -192,13 +192,13 @@ namespace ImageSharp.Formats /// The number of bytes to skip. private void Skip(int length) { - this.currentStream.Seek(length, SeekOrigin.Current); + this.currentStream.Skip(length); int flag; while ((flag = this.currentStream.ReadByte()) != 0) { - this.currentStream.Seek(flag, SeekOrigin.Current); + this.currentStream.Skip(flag); } } diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index f0f209a0c..cad32d9f2 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -116,7 +116,7 @@ namespace ImageSharp.Formats { Image currentImage = image; this.currentStream = stream; - this.currentStream.Seek(8, SeekOrigin.Current); + this.currentStream.Skip(8); bool isEndChunkReached = false;