Skip to content

Commit 63001fd

Browse files
committed
StreamHelper - Amazon.Runtime.Internal.Util.HashStream.Position set/get throws exception - avoid with stream.CanSeek check
1 parent 23acaca commit 63001fd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Ghostscript.NET/Helpers/StreamHelper.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ internal class StreamHelper
3636

3737
public static string GetStreamExtension(Stream stream)
3838
{
39+
// https://github.com/awslabs/aws-sdk-xamarin/blob/master/AWS.XamarinSDK/AWSSDK_Core/Amazon.Runtime/Internal/Util/HashStream.cs
40+
// Amazon.Runtime.Internal.Util.HashStream.Position {set; get;} throw NotSupportedException. First check CanSeek and default to PDF file extension
41+
if (!stream.CanSeek)
42+
{
43+
return ".pdf";
44+
}
45+
3946
if (stream.Length < 4)
4047
{
4148
throw new InvalidDataException("Less than 4 bytes found in stream.");
@@ -118,7 +125,12 @@ public static string WriteToTemporaryFile(Stream stream)
118125

119126
string path = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + extension);
120127

121-
stream.Position = 0;
128+
// https://github.com/awslabs/aws-sdk-xamarin/blob/master/AWS.XamarinSDK/AWSSDK_Core/Amazon.Runtime/Internal/Util/HashStream.cs
129+
// Amazon.Runtime.Internal.Util.HashStream.Position {set; get;} throw NotSupportedException.
130+
if (stream.CanSeek)
131+
{
132+
stream.Position = 0;
133+
}
122134

123135
using (FileStream fs = File.Create(path))
124136
{

0 commit comments

Comments
 (0)