// Decompiled with JetBrains decompiler // Type: Rei.Fs.PartialStream // Assembly: Rei.Fs, Version=1.13.2.8796, Culture=neutral, PublicKeyToken=null // MVID: D8B08A8B-697C-4439-9CFF-1BE4EE46F7B0 // Assembly location: F:\Eigene Dateien\Dropbox\portable Collection\Progs\CarotDAV\Rei.Fs.dll using Microsoft.VisualBasic.CompilerServices; using System; using System.IO; using System.Runtime.CompilerServices; namespace Rei.Fs { public class PartialStream : Stream { private Stream pBaseStream; private long pLength; private long pInnerPos; private long pStart; private int pLastCount; public object Tag; private object pSyncObject; private bool pHasError; private bool pDisposed; public PartialStream(Stream basestream, long length) { this.pHasError = false; this.pDisposed = false; this.pBaseStream = basestream; this.pLength = length; this.pInnerPos = 0L; if (!this.pBaseStream.CanSeek) return; this.pStart = this.pBaseStream.Position; } public Stream BaseStream { get { return this.pBaseStream; } } public override bool CanRead { get { return this.pBaseStream.CanRead; } } public override bool CanSeek { get { return this.pBaseStream.CanSeek; } } public override bool CanWrite { get { return this.pBaseStream.CanWrite; } } public override bool CanTimeout { get { return this.pBaseStream.CanTimeout; } } public override long Length { get { if (this.pLength < 0L) throw new NotSupportedException(); return this.pLength; } } public override int ReadTimeout { get { return this.pBaseStream.ReadTimeout; } set { this.pBaseStream.ReadTimeout = value; } } public override int WriteTimeout { get { return this.pBaseStream.WriteTimeout; } set { this.pBaseStream.WriteTimeout = value; } } public override long Position { get { return this.pInnerPos; } set { this.Seek(value, SeekOrigin.Begin); } } public override long Seek(long offset, SeekOrigin origin) { try { switch (origin) { case SeekOrigin.Current: checked { offset += this.Position; } break; case SeekOrigin.End: if (this.pLength < 0L) throw new NotSupportedException(); offset = checked (this.pLength - offset); break; } if (offset < 0L || this.pLength >= 0L && offset > this.pLength) throw new ArgumentOutOfRangeException(); this.pBaseStream.Seek(checked (this.pStart + offset), SeekOrigin.Begin); this.pInnerPos = offset; } catch (Exception ex) { ProjectData.SetProjectError(ex); this.pHasError = true; throw; } long num; return num; } public override void SetLength(long value) { throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { try { if (this.pInnerPos < 0L) this.Position = 0L; if (this.pLength >= 0L && checked (this.pInnerPos + (long) count) > this.pLength) count = checked ((int) (this.pLength - this.pInnerPos)); int num = this.pBaseStream.Read(buffer, offset, count); this.pInnerPos = checked (this.pInnerPos + (long) num); if (num == 0 && count > 0 && (this.pLength >= 0L && this.pInnerPos < this.pLength)) throw new IOException("Invalid Stream Length"); return num; } catch (Exception ex) { ProjectData.SetProjectError(ex); this.pHasError = true; throw; } } public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { try { if (this.pInnerPos < 0L) this.Position = 0L; if (this.pLength >= 0L && checked (this.pInnerPos + (long) count) > this.pLength) count = checked ((int) (this.pLength - this.pInnerPos)); this.pLastCount = count; return this.pBaseStream.BeginRead(buffer, offset, count, callback, RuntimeHelpers.GetObjectValue(state)); } catch (Exception ex) { ProjectData.SetProjectError(ex); this.pHasError = true; throw; } } public override int EndRead(IAsyncResult asyncResult) { try { int num = this.pBaseStream.EndRead(asyncResult); this.pInnerPos = checked (this.pInnerPos + (long) num); if (num == 0 && this.pLastCount > 0 && (this.pLength >= 0L && this.pInnerPos < this.pLength)) throw new IOException("Invalid Stream Length"); return num; } catch (Exception ex) { ProjectData.SetProjectError(ex); this.pHasError = true; throw; } } public override void Write(byte[] buffer, int offset, int count) { try { if (this.pInnerPos < 0L) this.Position = 0L; if (this.pLength >= 0L && checked (this.pInnerPos + (long) count) > this.pLength) throw new InvalidRangeException(); this.pBaseStream.Write(buffer, offset, count); this.pInnerPos = checked (this.pInnerPos + (long) count); } catch (Exception ex) { ProjectData.SetProjectError(ex); this.pHasError = true; throw; } } public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) { try { if (this.pInnerPos < 0L) this.Position = 0L; if (this.pLength >= 0L && checked (this.pInnerPos + (long) count) > this.pLength) throw new ArgumentException(); this.pLastCount = count; return this.pBaseStream.BeginWrite(buffer, offset, count, callback, RuntimeHelpers.GetObjectValue(state)); } catch (Exception ex) { ProjectData.SetProjectError(ex); this.pHasError = true; throw; } } public override void EndWrite(IAsyncResult asyncResult) { try { this.pBaseStream.EndWrite(asyncResult); this.pInnerPos = checked (this.pInnerPos + (long) this.pLastCount); } catch (Exception ex) { ProjectData.SetProjectError(ex); this.pHasError = true; throw; } } public override void Flush() { try { this.pBaseStream.Flush(); } catch (Exception ex) { ProjectData.SetProjectError(ex); this.pHasError = true; throw; } } protected override void Dispose(bool disposing) { try { if (!disposing || this.pDisposed) return; this.pDisposed = true; if (this.pHasError) { try { this.pBaseStream.Close(); } catch (Exception ex) { ProjectData.SetProjectError(ex); ProjectData.ClearProjectError(); } } else { if (this.pLength >= 0L && this.pInnerPos != this.pLength) { string message = "Length:" + this.pLength.ToString() + " Position:" + this.pInnerPos.ToString(); try { this.pBaseStream.Close(); } catch (Exception ex) { ProjectData.SetProjectError(ex); Exception innerexception = ex; throw new InvalidRangeException(message, innerexception); } throw new InvalidRangeException(message); } this.pBaseStream.Close(); } } finally { base.Dispose(disposing); } } } }