using System.IO; using System.Linq; namespace SabreTools.IO { /// /// Extensions to Stream functionality /// public static class StreamExtensions { /// /// Seek to a specific point in the stream, if possible /// /// Input stream to try seeking on /// Optional offset to seek to public static long SeekIfPossible(this Stream input, long offset = 0) { try { if (input.CanSeek) { if (offset < 0) return input.Seek(offset, SeekOrigin.End); else if (offset >= 0) return input.Seek(offset, SeekOrigin.Begin); } return input.Position; } catch { return -1; } } } }