Annotation of elwix/tools/oldlzma/SRC/7zip/Compress/LZ/LZOutWindow.cpp, revision 1.1
1.1 ! misho 1: // LZOutWindow.cpp
! 2:
! 3: #include "StdAfx.h"
! 4:
! 5: #include "../../../Common/Alloc.h"
! 6: #include "LZOutWindow.h"
! 7:
! 8: bool CLZOutWindow::Create(UInt32 windowSize)
! 9: {
! 10: const UInt32 kMinBlockSize = 1;
! 11: if (windowSize < kMinBlockSize)
! 12: windowSize = kMinBlockSize;
! 13: if (_buffer != 0 && _windowSize == windowSize)
! 14: return true;
! 15:
! 16: // It's here to allow Solid decoding / and calling Create for RAR
! 17: _pos = 0;
! 18: _streamPos = 0;
! 19:
! 20: Free();
! 21: _windowSize = windowSize;
! 22: _buffer = (Byte *)::BigAlloc(windowSize);
! 23: return (_buffer != 0);
! 24: }
! 25:
! 26: void CLZOutWindow::Free()
! 27: {
! 28: ::BigFree(_buffer);
! 29: _buffer = 0;
! 30: }
! 31:
! 32: void CLZOutWindow::SetStream(ISequentialOutStream *stream)
! 33: {
! 34: ReleaseStream();
! 35: _stream = stream;
! 36: _stream->AddRef();
! 37: }
! 38:
! 39: void CLZOutWindow::Init(bool solid)
! 40: {
! 41: if(!solid)
! 42: {
! 43: _streamPos = 0;
! 44: _pos = 0;
! 45: }
! 46: #ifdef _NO_EXCEPTIONS
! 47: ErrorCode = S_OK;
! 48: #endif
! 49: }
! 50:
! 51: void CLZOutWindow::ReleaseStream()
! 52: {
! 53: if(_stream != 0)
! 54: {
! 55: // Flush(); // Test it
! 56: _stream->Release();
! 57: _stream = 0;
! 58: }
! 59: }
! 60:
! 61: void CLZOutWindow::FlushWithCheck()
! 62: {
! 63: HRESULT result = Flush();
! 64: #ifdef _NO_EXCEPTIONS
! 65: ErrorCode = result;
! 66: #else
! 67: if (result != S_OK)
! 68: throw CLZOutWindowException(result);
! 69: #endif
! 70: }
! 71:
! 72: HRESULT CLZOutWindow::Flush()
! 73: {
! 74: UInt32 size = _pos - _streamPos;
! 75: if(size == 0)
! 76: return S_OK;
! 77: #ifdef _NO_EXCEPTIONS
! 78: if (ErrorCode != S_OK)
! 79: return ErrorCode;
! 80: #endif
! 81:
! 82: if(_stream != 0)
! 83: {
! 84: UInt32 processedSize;
! 85: HRESULT result = _stream->Write(_buffer + _streamPos, size, &processedSize);
! 86: if (result != S_OK)
! 87: return result;
! 88: if (size != processedSize)
! 89: return E_FAIL;
! 90: }
! 91: if (_pos >= _windowSize)
! 92: _pos = 0;
! 93: _streamPos = _pos;
! 94: return S_OK;
! 95: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>