1// OutBuffer.cs 2 3namespace SevenZip.Buffer 4{ 5 public class OutBuffer 6 { 7 byte[] m_Buffer; 8 uint m_Pos; 9 uint m_BufferSize; 10 System.IO.Stream m_Stream; 11 ulong m_ProcessedSize; 12 13 public OutBuffer(uint bufferSize) 14 { 15 m_Buffer = new byte[bufferSize]; 16 m_BufferSize = bufferSize; 17 } 18 19 public void SetStream(System.IO.Stream stream) { m_Stream = stream; } 20 public void FlushStream() { m_Stream.Flush(); } 21 public void CloseStream() { m_Stream.Close(); } 22 public void ReleaseStream() { m_Stream = null; } 23 24 public void Init() 25 { 26 m_ProcessedSize = 0; 27 m_Pos = 0; 28 } 29 30 public void WriteByte(byte b) 31 { 32 m_Buffer[m_Pos++] = b; 33 if (m_Pos >= m_BufferSize) 34 FlushData(); 35 } 36 37 public void FlushData() 38 { 39 if (m_Pos == 0) 40 return; 41 m_Stream.Write(m_Buffer, 0, (int)m_Pos); 42 m_Pos = 0; 43 } 44 45 public ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; } 46 } 47} 48