diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index 7b02f21c4..34bbb61e0 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -84,9 +84,9 @@ namespace SixLabors.ImageSharp public IEnumerable ImageFormats => this.imageFormats; /// - /// Gets or sets the position in a stream to use for reading. + /// Gets or sets the position in a stream to use for reading when using a seekable stream as an image data source. /// - public ReadOrigin ReadOrigin { get; set; } = ReadOrigin.Begin; + public ReadOrigin ReadOrigin { get; set; } = ReadOrigin.Current; /// /// Gets or sets the that is currently in use. diff --git a/src/ImageSharp/Image/Image.FromStream.cs b/src/ImageSharp/Image/Image.FromStream.cs index a0c71133c..c3f4a714f 100644 --- a/src/ImageSharp/Image/Image.FromStream.cs +++ b/src/ImageSharp/Image/Image.FromStream.cs @@ -19,6 +19,7 @@ namespace SixLabors.ImageSharp /// By reading the header on the provided stream this calculates the images mime type. /// /// The image stream to read the header from. + /// Thrown if the stream is not readable. /// The mime type or null if none found. public static IImageFormat DetectFormat(Stream stream) => DetectFormat(Configuration.Default, stream); @@ -27,6 +28,7 @@ namespace SixLabors.ImageSharp /// /// The configuration. /// The image stream to read the header from. + /// Thrown if the stream is not readable. /// The mime type or null if none found. public static IImageFormat DetectFormat(Configuration config, Stream stream) => WithSeekableStream(config, stream, s => InternalDetectFormat(s, config)); @@ -35,9 +37,7 @@ namespace SixLabors.ImageSharp /// By reading the header on the provided stream this reads the raw image information. /// /// The image stream to read the header from. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// /// The or null if suitable info detector not found. /// @@ -60,9 +60,7 @@ namespace SixLabors.ImageSharp /// /// The stream containing image information. /// the mime type of the decoded image. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// A new .> public static Image Load(Stream stream, out IImageFormat format) => Load(stream, out format); @@ -70,9 +68,7 @@ namespace SixLabors.ImageSharp /// Create a new instance of the class from the given stream. /// /// The stream containing image information. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// A new .> public static Image Load(Stream stream) => Load(stream); @@ -81,9 +77,7 @@ namespace SixLabors.ImageSharp /// /// The stream containing image information. /// The decoder. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// A new .> public static Image Load(Stream stream, IImageDecoder decoder) => Load(stream, decoder); @@ -92,9 +86,7 @@ namespace SixLabors.ImageSharp /// /// The config for the decoder. /// The stream containing image information. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// A new .> public static Image Load(Configuration config, Stream stream) => Load(config, stream); @@ -104,9 +96,7 @@ namespace SixLabors.ImageSharp /// The config for the decoder. /// The stream containing image information. /// the mime type of the decoded image. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// A new .> public static Image Load(Configuration config, Stream stream, out IImageFormat format) => Load(config, stream, out format); @@ -115,9 +105,7 @@ namespace SixLabors.ImageSharp /// Create a new instance of the class from the given stream. /// /// The stream containing image information. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// The pixel format. /// A new .> public static Image Load(Stream stream) @@ -129,9 +117,7 @@ namespace SixLabors.ImageSharp /// /// The stream containing image information. /// the mime type of the decoded image. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// The pixel format. /// A new .> public static Image Load(Stream stream, out IImageFormat format) @@ -143,9 +129,7 @@ namespace SixLabors.ImageSharp /// /// The stream containing image information. /// The decoder. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// The pixel format. /// A new .> public static Image Load(Stream stream, IImageDecoder decoder) @@ -158,9 +142,7 @@ namespace SixLabors.ImageSharp /// The Configuration. /// The stream containing image information. /// The decoder. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// The pixel format. /// A new .> public static Image Load(Configuration config, Stream stream, IImageDecoder decoder) @@ -172,9 +154,7 @@ namespace SixLabors.ImageSharp /// /// The configuration options. /// The stream containing image information. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// The pixel format. /// A new .> public static Image Load(Configuration config, Stream stream) @@ -187,9 +167,7 @@ namespace SixLabors.ImageSharp /// The configuration options. /// The stream containing image information. /// the mime type of the decoded image. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// The pixel format. /// A new .> public static Image Load(Configuration config, Stream stream, out IImageFormat format) @@ -203,9 +181,7 @@ namespace SixLabors.ImageSharp /// The stream containing image information. /// The position in the stream to use for reading. /// the mime type of the decoded image. - /// - /// Thrown if the stream is not readable nor seekable. - /// + /// Thrown if the stream is not readable. /// The pixel format. /// A new .> public static Image Load(Configuration config, Stream stream, ReadOrigin origin, out IImageFormat format) @@ -249,11 +225,6 @@ namespace SixLabors.ImageSharp return action(stream); } - if (config.ReadOrigin == ReadOrigin.Current) - { - throw new NotSupportedException("Cannot seek within the stream."); - } - // We want to be able to load images from things like HttpContext.Request.Body using (var memoryStream = new MemoryStream()) { diff --git a/tests/ImageSharp.Tests/ConfigurationTests.cs b/tests/ImageSharp.Tests/ConfigurationTests.cs index fc97b2209..06f02fcf1 100644 --- a/tests/ImageSharp.Tests/ConfigurationTests.cs +++ b/tests/ImageSharp.Tests/ConfigurationTests.cs @@ -63,9 +63,9 @@ namespace SixLabors.ImageSharp.Tests /// Test that the default configuration read origin options is set to begin. /// [Fact] - public void TestDefultConfigurationReadOriginIsBegin() + public void TestDefultConfigurationReadOriginIsCurrent() { - Assert.True(Configuration.Default.ReadOrigin == ReadOrigin.Begin); + Assert.True(Configuration.Default.ReadOrigin == ReadOrigin.Current); } ///