CSharpUtils.Streams.SliceStream.Read C# (CSharp) Method

Read() public method

Read a chunk from this SliceStream and move its cursor after that chunk. Only will be able to read inside the bounds of this Slice. It won't change the ParentStream cursor.
public Read ( byte buffer, int offset, int count ) : int
buffer byte ByteArray to write to
offset int Offset of the ByteArray to write to
count int Number of bytes to read
return int
		public override int Read(byte[] buffer, int offset, int count)
		{
			lock (ParentStream)
			{
				var ParentStreamPositionToRestore = ParentStream.Position;
				ParentStream.Position = ThisStart + Position;
				if (Position + count > Length)
				{
					count = (int)(Length - Position);
				}
				try
				{
					//Console.WriteLine("Read(position: {0}, count: {1})", Position, count);
					return base.Read(buffer, offset, count);
				}
				finally
				{
					Seek(count, SeekOrigin.Current);
					ParentStream.Position = ParentStreamPositionToRestore;
				}
			}
		}