示例#1
0
        /// <summary>
        /// Reads the specified data at the offset to the file path.
        /// </summary>
        /// <param name="stream">The stream.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <param name="buffer">The buffer.</param>
        /// <param name="bufferOffset">The buffer offset.</param>
        /// <exception cref="System.Exception">Incorrect file length.</exception>
        private void Read(FileStream stream, long offset, int length, byte[] buffer, int bufferOffset)
        {
            stream.CannotBeNull();
            offset.MustBeGreaterThanOrEqualTo(0);
            length.MustBeGreaterThan(0);
            buffer.CannotBeNullOrEmpty();
            bufferOffset.MustBeGreaterThanOrEqualTo(0);
            bufferOffset.MustBeLessThanOrEqualTo(buffer.Length - length);

            if (stream.Length >= offset + length)
            {
                stream.Position = offset;
                stream.Read(buffer, bufferOffset, length);
            }
            else
            {
                throw new TorrentPersistanceException("Incorrect file length.");
            }
        }