File:  [ELWIX - Embedded LightWeight unIX -] / elwix / tools / oldlzma / SRC / 7zip / Compress / LZ / LZOutWindow.cpp
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 14 09:04:51 2013 UTC (11 years, 2 months ago) by misho
Branches: misho, elwix1_9_mips, MAIN
CVS tags: start, elwix2_8, elwix2_7, elwix2_6, elwix2_3, elwix2_2, HEAD, ELWIX2_7, ELWIX2_6, ELWIX2_5, ELWIX2_2p0
oldlzma needs for uboot

// LZOutWindow.cpp

#include "StdAfx.h"

#include "../../../Common/Alloc.h"
#include "LZOutWindow.h"

bool CLZOutWindow::Create(UInt32 windowSize)
{
  const UInt32 kMinBlockSize = 1;
  if (windowSize < kMinBlockSize)
    windowSize = kMinBlockSize;
  if (_buffer != 0 && _windowSize == windowSize)
    return true;

  // It's here to allow Solid decoding / and calling Create for RAR
  _pos = 0;
  _streamPos = 0;
  
  Free();
  _windowSize = windowSize;
  _buffer = (Byte *)::BigAlloc(windowSize);
  return (_buffer != 0);
}

void CLZOutWindow::Free()
{
  ::BigFree(_buffer);
  _buffer = 0;
}

void CLZOutWindow::SetStream(ISequentialOutStream *stream)
{
  ReleaseStream();
  _stream = stream;
  _stream->AddRef();
}

void CLZOutWindow::Init(bool solid)
{
  if(!solid)
  {
    _streamPos = 0;
    _pos = 0;
  }
  #ifdef _NO_EXCEPTIONS
  ErrorCode = S_OK;
  #endif
}

void CLZOutWindow::ReleaseStream()
{
  if(_stream != 0)
  {
    // Flush(); // Test it
    _stream->Release();
    _stream = 0;
  }
}

void CLZOutWindow::FlushWithCheck()
{
  HRESULT result = Flush();
  #ifdef _NO_EXCEPTIONS
  ErrorCode = result;
  #else
  if (result != S_OK)
    throw CLZOutWindowException(result);
  #endif
}

HRESULT CLZOutWindow::Flush()
{
  UInt32 size = _pos - _streamPos;
  if(size == 0)
    return S_OK;
  #ifdef _NO_EXCEPTIONS
  if (ErrorCode != S_OK)
    return ErrorCode;
  #endif

  if(_stream != 0)
  {
    UInt32 processedSize;
    HRESULT result = _stream->Write(_buffer + _streamPos, size, &processedSize);
    if (result != S_OK)
      return result;
    if (size != processedSize)
      return E_FAIL;
  }
  if (_pos >= _windowSize)
    _pos = 0;
  _streamPos = _pos;
  return S_OK;
}

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>