This commit is contained in:
Matt Nadareski
2020-08-28 01:13:55 -07:00
parent d475d80fc4
commit 4bf5a835e7
15 changed files with 86 additions and 77 deletions

View File

@@ -209,28 +209,30 @@ namespace SabreTools.Library.IO
/// </summary>
/// <param name="input">Input stream to try seeking on</param>
/// <param name="offset">Optional offset to seek to</param>
private static long SeekIfPossible(this Stream input, long offset = 0)
public static long SeekIfPossible(this Stream input, long offset = 0)
{
if (input.CanSeek)
try
{
try
if (input.CanSeek)
{
if (offset < 0)
return input.Seek(offset, SeekOrigin.End);
else if (offset >= 0)
return input.Seek(offset, SeekOrigin.Begin);
}
catch (NotSupportedException)
{
Globals.Logger.Verbose("Stream does not support seeking to starting offset. Stream position not changed");
}
catch (NotImplementedException)
{
Globals.Logger.Warning("Stream does not support seeking to starting offset. Stream position not changed");
}
return input.Position;
}
catch (NotSupportedException)
{
Globals.Logger.Verbose("Stream does not support seeking to starting offset. Stream position not changed");
}
catch (NotImplementedException)
{
Globals.Logger.Warning("Stream does not support seeking to starting offset. Stream position not changed");
}
return input.Position;
return -1;
}
}
}