OutBuffer.cs 897 B

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