James Jackson-South 9 years ago
parent
commit
84e664a47f
  1. 2
      src/ImageSharp.Drawing/ImageSharp.Drawing.csproj
  2. 4
      src/ImageSharp/Image.FromStream.cs
  3. 14
      tests/ImageSharp.Tests/Image/ImageLoadTests.cs
  4. 50
      tests/ImageSharp.Tests/Image/NoneSeekableStream.cs

2
src/ImageSharp.Drawing/ImageSharp.Drawing.csproj

@ -40,7 +40,7 @@
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="SixLabors.Fonts" Version="0.1.0-alpha0002" />
<PackageReference Include="SixLabors.Shapes" Version="0.1.0-alpha0009" />
<PackageReference Include="SixLabors.Shapes" Version="0.1.0-alpha0010" />
</ItemGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>..\..\ImageSharp.ruleset</CodeAnalysisRuleSet>

4
src/ImageSharp/Image.FromStream.cs

@ -201,7 +201,7 @@ namespace ImageSharp
{
config = config ?? Configuration.Default;
Image<TColor> img = WithSeekableStream(stream, s => Decode<TColor>(stream, options, config));
Image<TColor> img = WithSeekableStream(stream, s => Decode<TColor>(s, options, config));
if (img != null)
{
@ -238,7 +238,7 @@ namespace ImageSharp
stream.CopyTo(ms);
ms.Position = 0;
return action(stream);
return action(ms);
}
}
}

14
tests/ImageSharp.Tests/Image/ImageLoadTests.cs

@ -86,6 +86,20 @@ namespace ImageSharp.Tests
}
[Fact]
public void LoadFromNoneSeekableStream()
{
NoneSeekableStream stream = new NoneSeekableStream(this.DataStream);
Image img = Image.Load(stream);
Assert.NotNull(img);
Assert.Equal(TestFormat.GlobalTestFormat, img.CurrentImageFormat);
TestFormat.GlobalTestFormat.VerifyDecodeCall(this.Marker, null, Configuration.Default);
}
[Fact]
public void LoadFromStreamWithType()
{

50
tests/ImageSharp.Tests/Image/NoneSeekableStream.cs

@ -0,0 +1,50 @@
using System;
using System.IO;
namespace ImageSharp.Tests
{
internal class NoneSeekableStream : Stream
{
private Stream dataStream;
public NoneSeekableStream(Stream dataStream)
{
this.dataStream = dataStream;
}
public override bool CanRead => this.dataStream.CanRead;
public override bool CanSeek => false;
public override bool CanWrite => false;
public override long Length => this.dataStream.Length;
public override long Position { get => this.dataStream.Position; set => throw new NotImplementedException(); }
public override void Flush()
{
this.dataStream.Flush();
}
public override int Read(byte[] buffer, int offset, int count)
{
return this.dataStream.Read(buffer, offset, count);
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotImplementedException();
}
public override void SetLength(long value)
{
throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotImplementedException();
}
}
}
Loading…
Cancel
Save