private void ReadInternal() { var sw = Stopwatch.StartNew(); // a partial read is required at the end of the file long position = m_streamPosition; if (position + m_buffer.Length > m_stream.Length) { m_streamEnd.Seek(position, SeekOrigin.Begin); m_bufferValidSize = m_streamEnd.Read(m_buffer.Data, 0, (int)(m_streamEnd.Length - position)); } else { m_stream.Read(m_buffer.Data, 0, m_buffer.Length); m_streamPosition += m_buffer.Length; m_bufferValidSize = m_buffer.Length; } // if the buffer was not valid, we just did a seek // and need to maintain the buffer index if (m_bufferIsValid) { m_bufferIndex = 0; } else { m_bufferIsValid = true; } sw.Stop(); PerformanceManager.UpdateReadBytes(m_bufferValidSize, sw); }
private void FlushInternal() { if (m_bufferIndex > 0) { var sw = Stopwatch.StartNew(); // a partial flush is only allowed at the end of the file if (m_bufferIndex != m_buffer.Length && m_stream.Position + m_bufferIndex != m_length) { // once this is done, no more writes can be accepted m_actualLength = Position; } m_stream.Write(m_buffer.Data, 0, m_buffer.Length); m_bufferIndex = 0; sw.Stop(); PerformanceManager.UpdateWriteBytes(m_actualLength > 0 ? m_actualLength : m_buffer.Length, sw); } }