// Decompiled with JetBrains decompiler // Type: Rei.Fs.ChunkedStream // 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 System; using System.IO; namespace Rei.Fs { public class ChunkedStream : Stream { private Stream pBaseStream; public object Tag; private long pChunkSize; private long pCurrentPosition; private long pChunkPosition; private long pTotalLength; private bool pDisposed; public event EventHandler ChunkFinishedEvent; public ChunkedStream(Stream basestream, long chunksize, long totallength) { this.pDisposed = false; this.pBaseStream = basestream; this.pChunkSize = chunksize; this.pCurrentPosition = 0L; this.pChunkPosition = 0L; this.pTotalLength = totallength; } public void SetStream(Stream basestream) { this.pBaseStream = basestream; this.pChunkPosition = 0L; } public Stream BaseStream { get { return this.pBaseStream; } } public long ChunkSize { get { return this.pChunkSize; } } public override bool CanRead { get { return false; } } public override bool CanSeek { get { return false; } } public override bool CanWrite { get { return this.BaseStream.CanWrite; } } public override long Length { get { return this.pTotalLength; } } public override long Position { get { return this.pCurrentPosition; } set { throw new NotSupportedException(); } } public override void SetLength(long value) { throw new NotSupportedException(); } public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException(); } public override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException(); } public override void Flush() { if (this.pBaseStream == null) return; this.pBaseStream.Flush(); } public override void Write(byte[] buffer, int offset, int count) { if (this.pBaseStream == null) throw new ObjectDisposedException(this.GetType().FullName); if (count < 0) throw new ArgumentOutOfRangeException(nameof (count)); if (offset < 0) throw new ArgumentOutOfRangeException(nameof (offset)); int count1 = count; if (checked ((long) count1 + this.pChunkPosition) > this.pChunkSize) count1 = checked ((int) (this.pChunkSize - this.pChunkPosition)); if (count1 > 0) { this.pBaseStream.Write(buffer, offset, count1); checked { count -= count1; } checked { offset += count1; } this.pChunkPosition = checked (this.pChunkPosition + (long) count1); this.pCurrentPosition = checked (this.pCurrentPosition + (long) count1); } if (count <= 0) return; this.pBaseStream.Close(); EventHandler finishedEventEvent = this.ChunkFinishedEvent; if (finishedEventEvent != null) finishedEventEvent((object) this, EventArgs.Empty); this.Write(buffer, offset, count); } protected override void Dispose(bool disposing) { try { if (!disposing || this.pDisposed) return; this.pDisposed = true; this.pBaseStream.Close(); } finally { base.Dispose(disposing); } } } }