• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // OutBuffer.cs
2 
3 namespace 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 
OutBuffer(uint bufferSize)13 		public OutBuffer(uint bufferSize)
14 		{
15 			m_Buffer = new byte[bufferSize];
16 			m_BufferSize = bufferSize;
17 		}
18 
SetStream(System.IO.Stream stream)19 		public void SetStream(System.IO.Stream stream) { m_Stream = stream; }
FlushStream()20 		public void FlushStream() { m_Stream.Flush(); }
CloseStream()21 		public void CloseStream() { m_Stream.Close(); }
ReleaseStream()22 		public void ReleaseStream() { m_Stream = null; }
23 
Init()24 		public void Init()
25 		{
26 			m_ProcessedSize = 0;
27 			m_Pos = 0;
28 		}
29 
WriteByte(byte b)30 		public void WriteByte(byte b)
31 		{
32 			m_Buffer[m_Pos++] = b;
33 			if (m_Pos >= m_BufferSize)
34 				FlushData();
35 		}
36 
FlushData()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 
GetProcessedSize()45 		public ulong GetProcessedSize() { return m_ProcessedSize + m_Pos; }
46 	}
47 }
48