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

Write() public method

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