Fix issue when creating SKData from a non-seekable stream (#1411)
This commit is contained in:
Родитель
ff3636a7bc
Коммит
a7bbd09c36
|
@ -97,7 +97,15 @@ namespace SkiaSharp
|
|||
{
|
||||
if (stream == null)
|
||||
throw new ArgumentNullException (nameof (stream));
|
||||
return Create (stream, stream.Length);
|
||||
if (stream.CanSeek) {
|
||||
return Create (stream, stream.Length);
|
||||
} else {
|
||||
using var memory = new SKDynamicMemoryWStream ();
|
||||
using (var managed = new SKManagedStream (stream)) {
|
||||
managed.CopyTo (memory);
|
||||
}
|
||||
return memory.DetachAsData ();
|
||||
}
|
||||
}
|
||||
|
||||
public static SKData Create (Stream stream, int length)
|
||||
|
|
|
@ -133,6 +133,16 @@ namespace SkiaSharp.Tests
|
|||
Assert.True(released, "The SKDataReleaseDelegate was not called.");
|
||||
}
|
||||
|
||||
[SkippableFact]
|
||||
public void CanCreateFromNonSeekable()
|
||||
{
|
||||
using var stream = File.OpenRead(Path.Combine(PathToImages, "baboon.png"));
|
||||
using var nonSeekable = new NonSeekableReadOnlyStream(stream);
|
||||
using var data = SKData.Create(nonSeekable);
|
||||
|
||||
Assert.NotNull(data);
|
||||
}
|
||||
|
||||
[SkippableFact(Skip = "Doesn't work as it relies on memory being overwritten by an external process.")]
|
||||
public void DataDisposedReturnsInvalidStream()
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче